-
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.
feat: add testing to the docs component and it's helpers
- Loading branch information
Showing
10 changed files
with
226 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
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
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,135 @@ | ||
import { act, fireEvent, render, screen, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import App from '@/app/App'; | ||
|
||
describe('Testing for docs component', () => { | ||
it('Should render docs components after clicking on show docs btn', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
expect(screen.queryByTestId('overlay')).toBeNull(); | ||
expect(screen.queryByText('Docs')).toBeNull(); | ||
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull(); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
expect(await screen.findByTestId('overlay')).toBeInTheDocument(); | ||
expect(await screen.findByText('Docs')).toBeInTheDocument(); | ||
expect( | ||
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'), | ||
).toBeInTheDocument(); | ||
}); | ||
it('Should close docs section after clicking on overlay', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
expect(screen.queryByTestId('overlay')).toBeNull(); | ||
expect(screen.queryByText('Docs')).toBeNull(); | ||
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull(); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
const overlay = await screen.findByTestId('overlay'); | ||
expect(overlay).toBeInTheDocument(); | ||
expect(await screen.findByText('Docs')).toBeInTheDocument(); | ||
expect( | ||
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'), | ||
).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(overlay); | ||
}); | ||
waitForElementToBeRemoved(() => { | ||
expect(overlay).toBeNull(); | ||
expect(screen.queryByText('Docs')).toBeNull(); | ||
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation.')).toBeNull(); | ||
}).catch(() => console.log('Error during testing closing of docs section was caught.')); | ||
}); | ||
it('Should close docs section after clicking on close docs button', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
expect(screen.queryByTestId('overlay')).toBeNull(); | ||
expect(screen.queryByText('Docs')).toBeNull(); | ||
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation')).toBeNull(); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
const closeDocsBtn = await screen.findByText('closeDocs'); | ||
expect(await screen.findByTestId('overlay')).toBeInTheDocument(); | ||
expect(await screen.findByText('Docs')).toBeInTheDocument(); | ||
expect( | ||
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'), | ||
).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(closeDocsBtn); | ||
}); | ||
waitForElementToBeRemoved(() => { | ||
expect(screen.queryByTestId('overlay')).toBeNull(); | ||
expect(screen.queryByText('Docs')).toBeNull(); | ||
expect(screen.queryByText('A GraphQL schema provides a root type for each kind of operation.')).toBeNull(); | ||
}).catch(() => console.log('Error during testing closing of docs section was caught.')); | ||
}); | ||
it('Should navigate and display info about proper type after cliking on that type', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
const booleanTypeLink = await screen.findByText('Boolean'); | ||
expect(booleanTypeLink).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(booleanTypeLink); | ||
}); | ||
expect(await screen.findByText('The `Boolean` scalar type represents `true` or `false`.')).toBeInTheDocument(); | ||
}); | ||
it('Should navigate and display info about proper info about root type after cliking on that type', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
const RootTypeLink = await screen.findByText('Root'); | ||
await act(async () => { | ||
fireEvent.click(RootTypeLink); | ||
}); | ||
expect(await screen.findByText('Fields:')).toBeInTheDocument(); | ||
}); | ||
it('Should navigate and display info about proper info about root type after cliking on that type and all following clicked types as well as navigating back', async () => { | ||
render(<App />); | ||
const showDocsBtn = screen.getByText('show docs'); | ||
await act(async () => { | ||
fireEvent.click(showDocsBtn); | ||
}); | ||
const RootTypeLink = await screen.findByText('Root'); | ||
await act(async () => { | ||
fireEvent.click(RootTypeLink); | ||
}); | ||
expect(await screen.findByText('Fields:')).toBeInTheDocument(); | ||
const filmsLink = await screen.findByText('Film'); | ||
expect(filmsLink).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(filmsLink); | ||
}); | ||
expect(await screen.findByText('Implements:')).toBeInTheDocument(); | ||
const nodeTypeLink = await screen.findByText('Node'); | ||
expect(nodeTypeLink).toBeInTheDocument(); | ||
await act(async () => { | ||
fireEvent.click(nodeTypeLink); | ||
}); | ||
expect(await screen.findByText('Implementations')).toBeInTheDocument(); | ||
const backToFilmBtn = await screen.findByRole('button', { name: 'Film' }); | ||
await act(async () => { | ||
fireEvent.click(backToFilmBtn); | ||
}); | ||
const backToRootBtn = await screen.findByRole('button', { name: 'Root' }); | ||
await act(async () => { | ||
fireEvent.click(backToRootBtn); | ||
}); | ||
const backToDocsBtn = await screen.findByRole('button', { name: 'Docs' }); | ||
await act(async () => { | ||
fireEvent.click(backToDocsBtn); | ||
}); | ||
expect(await screen.findByText('Docs')).toBeInTheDocument(); | ||
expect( | ||
await screen.findByText('A GraphQL schema provides a root type for each kind of operation.'), | ||
).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,45 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import getTypeName from '@/components/DocsComp/lib/helpers/getTypeName'; | ||
|
||
const mockObjOne = { | ||
kind: 'NON_NULL', | ||
name: null, | ||
ofType: { | ||
kind: 'LIST', | ||
name: null, | ||
ofType: { | ||
kind: 'NON_NULL', | ||
name: null, | ||
ofType: { | ||
kind: 'SCALAR', | ||
name: 'ID', | ||
ofType: null, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockObjTwo = { | ||
kind: 'INPUT_OBJECT', | ||
name: 'FilterCharacter', | ||
ofType: null, | ||
}; | ||
|
||
const mockObjThree = { | ||
kind: 'NON_NULL', | ||
name: null, | ||
ofType: { | ||
kind: 'SCALAR', | ||
name: 'ID', | ||
ofType: null, | ||
}, | ||
}; | ||
|
||
describe('Testing the getTypeName helper function', () => { | ||
it('It should return proper string after recursively checking obj tree', () => { | ||
expect(getTypeName(mockObjOne)).toMatch('[ID!]!'); | ||
expect(getTypeName(mockObjTwo)).toMatch('FilterCharacter'); | ||
expect(getTypeName(mockObjThree)).toMatch('ID!'); | ||
}); | ||
}); |
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 { describe, expect, it } from 'vitest'; | ||
|
||
import separateString from '@/components/DocsComp/lib/helpers/separateString'; | ||
|
||
describe('Testing the getTypeName helper function', () => { | ||
it('It should return proper string after recursively checking obj tree', () => { | ||
const outputOne = separateString('[ID!]!'); | ||
expect(outputOne[0]).toMatch('['); | ||
expect(outputOne[1]).toMatch('ID'); | ||
expect(outputOne[2]).toMatch('!]!'); | ||
const outputTwo = separateString('ID'); | ||
expect(outputTwo[0]).toMatch(''); | ||
expect(outputTwo[1]).toMatch('ID'); | ||
expect(outputTwo[2]).toMatch(''); | ||
const outputThree = separateString('ID!'); | ||
expect(outputThree[0]).toMatch(''); | ||
expect(outputThree[1]).toMatch('ID'); | ||
expect(outputThree[2]).toMatch('!'); | ||
// expect(separateString(mockObjTwo)).toMatch('FilterCharacter'); | ||
// expect(separateString(mockObjThree)).toMatch('ID!'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -90,6 +90,22 @@ vi.mock('@components/loginReg/PassVisibilityIcon', () => ({ | |
default: () => <button type="button">click</button>, | ||
})); | ||
|
||
vi.mock('@components/Header/ui/ShowDocsBtn', () => ({ | ||
default: (props: { onClick: () => void }) => ( | ||
<button type="button" onClick={props.onClick}> | ||
show docs | ||
</button> | ||
), | ||
})); | ||
|
||
vi.mock('@components/DocsComp/ui/CloseDocsBtn', () => ({ | ||
default: (props: { onClick: () => void }) => ( | ||
<button type="button" onClick={props.onClick}> | ||
closeDocs | ||
</button> | ||
), | ||
})); | ||
|
||
vi.mock('firebase/auth', () => ({ | ||
getAuth: () => {}, | ||
signInWithEmailAndPassword: () => ({ user: { email: '[email protected]' } }), | ||
|
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