-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antoine Lelaisant
committed
Mar 14, 2021
1 parent
f730084
commit c696164
Showing
21 changed files
with
462 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react' | ||
import { Game } from './Game' | ||
import { Provider } from 'react-redux' | ||
import { MemoryRouter as Router } from 'react-router-dom' | ||
import { render, screen, waitFor } from '@testing-library/react' | ||
import configureStore from '../../configureStore' | ||
|
||
describe('Game', () => { | ||
it('it renders correctly', async () => { | ||
const initialState = { | ||
game: { | ||
lines: 6, | ||
linesPerMillisecond: 2, | ||
skills: {} | ||
} | ||
} | ||
|
||
render( | ||
<Provider store={configureStore(initialState)}> | ||
<Router> | ||
<Game /> | ||
</Router> | ||
</Provider> | ||
) | ||
|
||
expect(screen.getByText(/6 lines/)).toBeInTheDocument() | ||
expect(screen.getByText(/per second: 20/)).toBeInTheDocument() | ||
expect(screen.getByText(/Skills/)).toBeInTheDocument() | ||
expect(screen.getByText(/Store/)).toBeInTheDocument() | ||
|
||
await waitFor( | ||
() => expect(screen.getByText(/8 lines/)).toBeInTheDocument(), | ||
{ timeout: 150 } | ||
) | ||
await waitFor( | ||
() => expect(screen.getByText(/10 lines/)).toBeInTheDocument(), | ||
{ timeout: 150 } | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react' | ||
import { Gitcoin } from './Gitcoin' | ||
import { render, screen, fireEvent } from '@testing-library/react' | ||
import { click } from 'modules/game' | ||
import configureStore from '../../configureStore' | ||
|
||
jest.mock('react-redux', () => { | ||
const dispatch = jest.fn() | ||
|
||
return { | ||
...jest.requireActual('react-redux'), | ||
useDispatch: () => dispatch | ||
} | ||
}) | ||
import { Provider, useDispatch } from 'react-redux' | ||
|
||
describe('Gitcoin', () => { | ||
it('Allows to click', () => { | ||
const initialState = { | ||
game: { lines: 6, linesPerMillisecond: 2 } | ||
} | ||
|
||
render( | ||
<Provider store={configureStore(initialState)}> | ||
<Gitcoin /> | ||
</Provider> | ||
) | ||
|
||
expect(screen.getByAltText(/Gitcoin/i)).toBeInTheDocument() | ||
|
||
const dispatch = useDispatch() | ||
|
||
fireEvent.click(screen.getByLabelText(/Gitcoin/)) | ||
expect(dispatch).toHaveBeenCalledWith(click()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import { Home } from './Home' | ||
import { MemoryRouter as Router } from 'react-router-dom' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
describe('Home', () => { | ||
it('renders correctly', () => { | ||
render( | ||
<Router> | ||
<Home /> | ||
</Router> | ||
) | ||
|
||
expect(screen.getByText(/Dogs have boundless enthusiasm/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Play/i)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import { Score } from './Score' | ||
import { Provider } from 'react-redux' | ||
import { render, screen } from '@testing-library/react' | ||
import configureStore from '../configureStore' | ||
|
||
describe('Score', () => { | ||
it('should displays the number of lines', () => { | ||
const initialState = { | ||
game: { lines: 6, linesPerMillisecond: 2 } | ||
} | ||
|
||
render( | ||
<Provider store={configureStore(initialState)}> | ||
<Score /> | ||
</Provider> | ||
) | ||
|
||
expect(screen.getByText(/6 lines/i)).toBeInTheDocument() | ||
expect(screen.getByText(/per second: 20/i)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import { Section } from './Section' | ||
|
||
describe('Section', () => { | ||
it('Displays the owned skills', () => { | ||
render(<Section itemName="Bash" number={3} />) | ||
|
||
expect(screen.getByText('Bash')).toBeInTheDocument() | ||
expect(screen.getAllByAltText('Bash')).toHaveLength(3) | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { render, screen } from '@testing-library/react' | ||
import { Skills } from './Skills' | ||
import configureStore from '../../configureStore' | ||
|
||
|
||
describe('Store', () => { | ||
it('Renders correctly', () => { | ||
const initialState = { | ||
game: { | ||
skills: { 'Bash': 2, 'Git': 3, 'Javascript': 4 } | ||
} | ||
} | ||
|
||
render( | ||
<Provider store={configureStore(initialState)}> | ||
<Skills /> | ||
</Provider> | ||
) | ||
|
||
expect(screen.getByText(/Bash/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Git/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Javascript/i)).toBeInTheDocument() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
import BashIcon from 'devicon/icons/bash/bash-original.svg' | ||
import { render, screen, fireEvent } from '@testing-library/react' | ||
import { Item } from './Item' | ||
|
||
describe('Item', () => { | ||
it('Renders a buyable item', () => { | ||
const item = { | ||
name: 'Bash', | ||
price: 10, | ||
multiplier: 0.1, | ||
icon: BashIcon | ||
} | ||
|
||
const onBuy = jest.fn() | ||
|
||
render( | ||
<Item | ||
item={item} | ||
lines={150} | ||
onBuy={onBuy} | ||
/> | ||
) | ||
|
||
expect(screen.getByText(/Bash/i)).toBeInTheDocument() | ||
expect(screen.getByText(/1 lines per second/i)).toBeInTheDocument() | ||
expect(screen.getByRole('button')).not.toBeDisabled() | ||
|
||
fireEvent.click(screen.getByRole('button')) | ||
|
||
expect(onBuy).toHaveBeenCalledWith(item) | ||
}) | ||
|
||
it('Renders a non buyable item', () => { | ||
const item = { | ||
name: 'Bash', | ||
price: 10, | ||
multiplier: 0.1, | ||
icon: BashIcon | ||
} | ||
|
||
const onBuy = jest.fn() | ||
|
||
render( | ||
<Item | ||
item={item} | ||
lines={0} | ||
onBuy={onBuy} | ||
/> | ||
) | ||
|
||
expect(screen.getByText(/Bash/i)).toBeInTheDocument() | ||
expect(screen.getByText(/1 lines per second/i)).toBeInTheDocument() | ||
expect(screen.getByRole(/button/i)).toBeDisabled() | ||
|
||
fireEvent.click(screen.getByRole('button')) | ||
|
||
expect(onBuy).not.toHaveBeenCalledWith(item) | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { render, screen } from '@testing-library/react' | ||
import { Store } from './Store' | ||
import configureStore from '../../configureStore' | ||
|
||
|
||
describe('Store', () => { | ||
it('Renders correctly', () => { | ||
const initialState = { | ||
game: { lines: 6 } | ||
} | ||
|
||
render( | ||
<Provider store={configureStore(initialState)}> | ||
<Store /> | ||
</Provider> | ||
) | ||
|
||
expect(screen.getByText(/Bash/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Git/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Javascript/i)).toBeInTheDocument() | ||
expect(screen.getByText(/React/i)).toBeInTheDocument() | ||
expect(screen.getByText(/Vim/i)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { createStore } from 'redux' | ||
import { rootReducer } from './modules' | ||
|
||
export default () => { | ||
const store = createStore(rootReducer) | ||
export default (initialState = {}) => { | ||
const store = createStore(rootReducer, initialState) | ||
|
||
return store | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.