-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(addSourcesScanModal): ds-767 lint, test updates (#450)
- Loading branch information
Showing
4 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/views/sources/__tests__/__snapshots__/addSourcesScanModal.test.tsx.snap
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,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AddSourceModal should call onSubmit with the correct filtered data when "Save" is clicked: onSubmit, filtered data 1`] = ` | ||
[ | ||
[ | ||
{ | ||
"name": "Test Scan", | ||
"options": { | ||
"enabled_extended_product_search": { | ||
"jboss_brms": false, | ||
"jboss_eap": false, | ||
"jboss_fuse": false, | ||
"jboss_ws": false, | ||
"search_directories": undefined, | ||
}, | ||
"max_concurrency": "25", | ||
}, | ||
"sources": undefined, | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`AddSourceModal should have the correct title: title 1`] = ` | ||
<span | ||
class="pf-v5-c-modal-box__title-text" | ||
> | ||
Scan | ||
</span> | ||
`; | ||
|
||
exports[`AddSourceModal should render a basic component: basic 1`] = ` | ||
<Modal | ||
actions={[]} | ||
appendTo={[Function]} | ||
aria-describedby="" | ||
aria-label="" | ||
aria-labelledby="" | ||
className="" | ||
hasNoBodyWrapper={false} | ||
isOpen={true} | ||
onClose={[Function]} | ||
ouiaSafe={true} | ||
position="default" | ||
showClose={true} | ||
title="Scan" | ||
titleIconVariant={null} | ||
titleLabel="" | ||
variant="small" | ||
> | ||
<FormContextProvider | ||
initialValues={ | ||
{ | ||
"scan-max-concurrent": "25", | ||
"scan-sources": "", | ||
} | ||
} | ||
> | ||
[Function] | ||
</FormContextProvider> | ||
</Modal> | ||
`; |
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,47 @@ | ||
import React, { act } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { shallowComponent } from '../../../../config/jest.setupTests'; | ||
import { AddSourcesScanModal } from '../addSourcesScanModal'; | ||
|
||
describe('AddSourceModal', () => { | ||
let mockOnClose; | ||
let mockOnSubmit; | ||
|
||
beforeEach(async () => { | ||
await act(async () => { | ||
mockOnClose = jest.fn(); | ||
mockOnSubmit = jest.fn(); | ||
await render(<AddSourcesScanModal isOpen={true} onClose={mockOnClose} onSubmit={mockOnSubmit} />); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render a basic component', async () => { | ||
const component = await shallowComponent(<AddSourcesScanModal isOpen={true} />); | ||
expect(component).toMatchSnapshot('basic'); | ||
}); | ||
|
||
it('should have the correct title', () => { | ||
const title = screen.getByText(/Scan/); | ||
expect(title).toMatchSnapshot('title'); | ||
}); | ||
|
||
it('should call onSubmit with the correct filtered data when "Save" is clicked', async () => { | ||
const user = userEvent.setup(); | ||
await user.type(screen.getByPlaceholderText(new RegExp('Enter a name for the scan', 'i')), 'Test Scan'); | ||
await user.click(screen.getByText('Save')); | ||
|
||
expect(mockOnSubmit.mock.calls).toMatchSnapshot('onSubmit, filtered data'); | ||
}); | ||
|
||
it('should call onClose', async () => { | ||
const user = userEvent.setup(); | ||
await user.click(screen.getByText('Cancel')); | ||
|
||
expect(mockOnClose).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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