-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(FluidSearchSkeleton): add test file for component (#17826)
* test(FluidSearchSkeleton): add test file for component * fix(FluidSearchSkeleton): corrected contributor file Signed-off-by: Mariat Sebastian <[email protected]> --------- Signed-off-by: Mariat Sebastian <[email protected]> Co-authored-by: Alison Joseph <[email protected]>
- Loading branch information
1 parent
b667bba
commit b3e348b
Showing
3 changed files
with
65 additions
and
0 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
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
53 changes: 53 additions & 0 deletions
53
packages/react/src/components/FluidSearch/__tests__/FluidSearchSkeleton-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,53 @@ | ||
/** | ||
* Copyright IBM Corp. 2024 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import FluidSearchSkeleton from '../FluidSearch.Skeleton'; | ||
import { FormContext } from '../../FluidForm/FormContext'; | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
const prefix = 'cds'; | ||
|
||
describe('FluidSearchSkeleton', () => { | ||
it('should render as expected', () => { | ||
const { container } = render( | ||
<FluidSearchSkeleton className="test-class" /> | ||
); | ||
|
||
expect(container.firstChild).toHaveClass( | ||
`${prefix}--text-input--fluid__skeleton ${prefix}--form-item` | ||
); | ||
}); | ||
|
||
it('should apply additional custom class names if provided', () => { | ||
const customClass = 'test-class'; | ||
const { container } = render( | ||
<FluidSearchSkeleton className={customClass} /> | ||
); | ||
|
||
expect(container.firstChild).toHaveClass( | ||
`${prefix}--form-item ${prefix}--text-input--fluid__skeleton` | ||
); | ||
expect(container.firstChild).toHaveClass(customClass); | ||
}); | ||
it('provides "isFluid" context value as true', () => { | ||
let contextValue; | ||
|
||
render( | ||
<FormContext.Provider value={{ isFluid: true }}> | ||
<FluidSearchSkeleton /> | ||
<FormContext.Consumer> | ||
{(value) => { | ||
contextValue = value; | ||
return null; | ||
}} | ||
</FormContext.Consumer> | ||
</FormContext.Provider> | ||
); | ||
expect(contextValue.isFluid).toBe(true); | ||
}); | ||
}); |