-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-nvt-preference
- Loading branch information
Showing
2 changed files
with
68 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {describe, test, expect} from '@gsa/testing'; | ||
import {render, screen, fireEvent} from 'web/utils/testing'; | ||
|
||
import {withFolding, FoldState, withFoldToggle} from '../folding'; | ||
|
||
describe('withFolding', () => { | ||
const DummyComponent = props => <div {...props}>Dummy Component</div>; | ||
const FoldableComponent = withFolding(DummyComponent); | ||
|
||
test('hides content when foldState is Folded', () => { | ||
const {rerender} = render( | ||
<FoldableComponent foldState={FoldState.FOLDED} />, | ||
); | ||
expect(screen.getByText('Dummy Component')).not.toBeVisible(); | ||
|
||
rerender(<FoldableComponent foldState={FoldState.UNFOLDED} />); | ||
expect(screen.getByText('Dummy Component')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('withFoldToggle', () => { | ||
test('toggles foldState when onFolded isCalled', () => { | ||
const DummyComponent = ({foldState, onFoldToggle}) => ( | ||
<div> | ||
<span data-testid="foldState">{foldState}</span> | ||
<button onClick={onFoldToggle}>Toggle</button> | ||
</div> | ||
); | ||
|
||
const FoldToggleComponent = withFoldToggle(DummyComponent); | ||
|
||
render(<FoldToggleComponent />); | ||
|
||
expect(screen.getByTestId('foldState')).toHaveTextContent( | ||
FoldState.UNFOLDED, | ||
); | ||
|
||
fireEvent.click(screen.getByText('Toggle')); | ||
expect(screen.getByTestId('foldState')).toHaveTextContent( | ||
FoldState.FOLDING_START, | ||
); | ||
}); | ||
}); |
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