-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for OpenApiModels component
- Loading branch information
Showing
10 changed files
with
737 additions
and
27 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
42 changes: 22 additions & 20 deletions
42
docusaurus/video/docusaurus/docs/api/_common_/OpenApiModels.jsx
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
57 changes: 57 additions & 0 deletions
57
docusaurus/video/openapi-to-docs/__tests__/OpenApiModels.test.jsx
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,57 @@ | ||
import { render, screen } from './utils' | ||
import OpenApiModels from '../../docusaurus/docs/api/_common_/OpenApiModels' | ||
import mockApiJson from './mock-open-api.json'; | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
describe('OpenApiModels', async () => { | ||
let container; | ||
|
||
beforeEach(() => { | ||
container = render( | ||
<OpenApiModels modelName={'GetOrCreateCallRequest'} apiJson={mockApiJson}/>, | ||
).container; | ||
}); | ||
|
||
it('should render each model in an HTML table', () => { | ||
expect(screen.getByTestId('GetOrCreateCallRequest-table')).toBeInTheDocument(); | ||
expect(screen.getByTestId('CallRequest-table')).toBeInTheDocument(); | ||
expect(screen.getByTestId('MemberRequest-table')).toBeInTheDocument(); | ||
|
||
expect(container.querySelectorAll('table').length).toBe(3); | ||
}); | ||
|
||
it('should render model name', () => { | ||
expect(screen.getByText('GetOrCreateCallRequest')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render properties of model - name', () => { | ||
expect(screen.getByTestId('GetOrCreateCallRequest-data-name').innerHTML).toContain('data'); | ||
}); | ||
|
||
it('should render properties of model - type and type definition links', () => { | ||
// ref | ||
expect(screen.getByTestId('GetOrCreateCallRequest-data-type').innerHTML).toContain('CallRequest'); | ||
|
||
expect(screen.getByTestId('GetOrCreateCallRequest-data-typelink').href).toContain('#CallRequest'); | ||
|
||
expect(container.querySelector('#CallRequest')).toBeInTheDocument(); | ||
|
||
// primitive | ||
expect(screen.getByTestId('GetOrCreateCallRequest-ring-type').innerHTML).toContain('boolean'); | ||
|
||
expect(container.querySelector('[data-testid=GetOrCreateCallRequest-ring-typelink]')).toBe(null); | ||
|
||
// formatted name | ||
expect(screen.getByTestId('CallRequest-members-type').innerHTML).toContain('MemberRequest[]'); | ||
}); | ||
|
||
it('should render properties of model - description', () => { | ||
expect(screen.getByTestId('GetOrCreateCallRequest-data-description').innerHTML).toContain('Configuration options for the call'); | ||
}) | ||
|
||
it('should render properties of model - constraints', () => { | ||
expect(screen.getByTestId('GetOrCreateCallRequest-data-constraints').innerHTML).toContain('Required'); | ||
expect(screen.getByTestId('GetOrCreateCallRequest-notify-constraints').innerHTML).toContain('-'); | ||
expect(screen.getByTestId('CallRequest-members-constraints').innerHTML).toContain('Required, Maximum: 100'); | ||
}); | ||
}) |
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 @@ | ||
import '@testing-library/jest-dom'; |
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,18 @@ | ||
import { cleanup, render } from '@testing-library/react' | ||
import { afterEach } from 'vitest' | ||
|
||
afterEach(() => { | ||
cleanup() | ||
}) | ||
|
||
function customRender(ui, options = {}) { | ||
return render(ui, { | ||
// wrap provider(s) here if needed | ||
wrapper: ({ children }) => children, | ||
...options, | ||
}) | ||
} | ||
|
||
export * from '@testing-library/react' | ||
// override render export | ||
export { customRender as render } |
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
Oops, something went wrong.