forked from dekkerglen/CubeCobra
-
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
Showing
5 changed files
with
107 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,46 @@ | ||
import React from 'react' | ||
import { render, fireEvent, waitForElement } from '@testing-library/react' | ||
import { FetchMock } from '@react-mock/fetch'; | ||
import { render, fireEvent, waitForElement, wait } from '@testing-library/react' | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
import exampleCardsFull from '../../../fixtures/examplecardsdetails'; | ||
import CubeListPage from 'components/CubeListPage'; | ||
import { treeCache } from 'components/AutocompleteInput'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
const element = () =><CubeListPage cards={exampleCardsFull} cubeID="1" canEdit={true} maybe={exampleCardsFull} defaultTagColors={[]} defaultShowTagColors={true} defaultSorts={['Color Category', 'Types-Multicolor']} />; | ||
const element = () => ( | ||
<FetchMock | ||
mocks={[ | ||
{ matcher: '/cube/api/cardnames', response: { success: 'true' } }, | ||
{ matcher: '/cube/api/cubecardnames/1', response: { success: 'true' } }, | ||
]} | ||
> | ||
<CubeListPage cards={exampleCardsFull} cubeID="1" canEdit={true} maybe={exampleCardsFull} defaultTagColors={[]} defaultShowTagColors={true} defaultSorts={['Color Category', 'Types-Multicolor']} />; | ||
</FetchMock> | ||
); | ||
|
||
describe('CubeListPage', () => { | ||
test('displays cards', () => { | ||
const { getByText } = render(element()); | ||
test('CubeListPage has major functionality', async () => { | ||
const { findByPlaceholderText, findByText, getAllByText, getByDisplayValue, getByPlaceholderText, getByText } = render(element()); | ||
|
||
expect(getByText('Ayara, First of Locthwain')); | ||
}); | ||
expect(getByText(exampleCardsFull[0].details.name)); | ||
|
||
test('opens edit collapse', () => { | ||
const { getByPlaceholderText, getByText } = render(element()); | ||
// TODO: These tests should be in their own files. | ||
// Test Edit Collapse | ||
fireEvent.click(getByText('Add/Remove')); | ||
await findByPlaceholderText('Card to Remove'); | ||
|
||
fireEvent.click(getByText('Add/Remove')); | ||
// Avoid act warnings. | ||
await act(() => Promise.all(Object.values(treeCache))); | ||
|
||
expect(getByPlaceholderText('Card to Add')); | ||
}); | ||
expect(getByPlaceholderText('Card to Remove')).toBeInTheDocument(); | ||
|
||
// Test Sort Collapse | ||
fireEvent.click(getByText('Sort')); | ||
await findByText('Primary Sort'); | ||
fireEvent.change(getByDisplayValue('Color Category'), { target: { value: 'Color Identity' } }); | ||
fireEvent.change(getByDisplayValue('Types-Multicolor'), { target: { value: 'Unsorted' } }); | ||
|
||
for (const card of exampleCardsFull) { | ||
expect(getAllByText(card.details.name).length).toBeGreaterThan(0); | ||
} | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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