-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
2b08ec8
commit 441dc05
Showing
7 changed files
with
161 additions
and
9 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
lib/VersionHistory/components/VersionCheckbox/VersionCheckbox.test.js
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,39 @@ | ||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
|
||
import { VersionViewContext } from '../../VersionViewContext'; | ||
import { VersionCheckbox } from './VersionCheckbox'; | ||
|
||
const defaultProps = { | ||
label: 'Test Label', | ||
name: 'testName', | ||
}; | ||
|
||
const renderVersionCheckbox = (props = {}, contextValue = {}) => { | ||
return render( | ||
<VersionViewContext.Provider value={contextValue}> | ||
<VersionCheckbox | ||
{...defaultProps} | ||
{...props} | ||
/> | ||
</VersionViewContext.Provider>, | ||
); | ||
}; | ||
|
||
describe('VersionCheckbox', () => { | ||
it('renders with marked label when name is in context paths', () => { | ||
renderVersionCheckbox({}, { paths: ['testName'] }); | ||
|
||
screen.debug(); | ||
|
||
expect(screen.getByText('Test Label').closest('mark')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders with normal label when name is not in context paths', () => { | ||
renderVersionCheckbox({}, { paths: ['otherName'] }); | ||
|
||
expect(screen.getByText('Test Label').closest('mark')).not.toBeInTheDocument(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
lib/VersionHistory/components/VersionKeyValue/VersionKeyValue.test.js
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,64 @@ | ||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
|
||
import { VersionViewContext } from '../../VersionViewContext'; | ||
import { VersionKeyValue } from './VersionKeyValue'; | ||
|
||
const defaultProps = { | ||
label: 'Test Label', | ||
value: 'Test Value', | ||
name: 'testName', | ||
}; | ||
|
||
const renderComponent = (props = {}, contextValue = {}) => { | ||
return render( | ||
<VersionViewContext.Provider value={contextValue}> | ||
<VersionKeyValue | ||
{...defaultProps} | ||
{...props} | ||
/> | ||
</VersionViewContext.Provider>, | ||
); | ||
}; | ||
|
||
describe('VersionKeyValue', () => { | ||
it('should render label and value', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('Test Label')).toBeInTheDocument(); | ||
expect(screen.getByText('Test Value')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render NoValue when value is not provided', () => { | ||
renderComponent({ value: undefined }); | ||
|
||
expect(screen.getByText('Test Label')).toBeInTheDocument(); | ||
expect(screen.getByText('stripes-components.noValue.noValueSet')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should highlight updated value', () => { | ||
renderComponent({ name: 'testName' }, { paths: ['testName'] }); | ||
|
||
expect(screen.getByText('Test Value').closest('mark')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not highlight non-updated value', () => { | ||
renderComponent({}, { paths: ['anotherName'] }); | ||
|
||
expect(screen.getByText('Test Value').closest('mark')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should highlight updated value for multiple fields', () => { | ||
renderComponent({ multiple: true }, { paths: ['testName[0]'] }); | ||
|
||
expect(screen.getByText('Test Value').closest('mark')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not highlight non-updated value for multiple fields', () => { | ||
renderComponent({ multiple: true }, { paths: ['anotherName[0]'] }); | ||
|
||
expect(screen.getByText('Test Value').closest('mark')).not.toBeInTheDocument(); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
lib/VersionHistory/components/VersionView/VersionView.test.js
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,52 @@ | ||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import VersionView from './VersionView'; | ||
|
||
const defaultProps = { | ||
children: <div>Version Content</div>, | ||
id: 'test-id', | ||
isLoading: false, | ||
onClose: jest.fn(), | ||
tags: [{ id: 'tag1' }, { id: 'tag2' }], | ||
versionId: 'version1', | ||
dismissible: true, | ||
}; | ||
|
||
const renderComponent = (props = {}) => render( | ||
<VersionView | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
); | ||
|
||
describe('VersionView', () => { | ||
it('should render loading pane when isLoading is true', () => { | ||
renderComponent({ isLoading: true }); | ||
|
||
expect(screen.queryByText('Version Content')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render children when version exists and is not loading', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByText('Version Content')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render no version message when version does not exist', () => { | ||
renderComponent({ versionId: null }); | ||
|
||
expect(screen.getByText('stripes-acq-components.versionHistory.noVersion')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onClose when Pane onClose is triggered', async () => { | ||
renderComponent(); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'stripes-components.closeItem' })); | ||
|
||
expect(defaultProps.onClose).toHaveBeenCalled(); | ||
}); | ||
}); |
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