generated from StanfordBDHG/NextJSTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SideLabel tests and stories (#70)
# Add SideLabel tests and stories ## ⚙️ Release Notes * Add SideLabel tests and stories  ### Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
b150aa0
commit 29e4fea
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/design-system/src/components/SideLabel/SideLabel.stories.tsx
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,35 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health ENGAGE-HF open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
import { type Meta } from '@storybook/react' | ||
import { SideLabel } from './SideLabel' | ||
import { Switch } from '../Switch' | ||
|
||
const meta: Meta<typeof SideLabel> = { | ||
title: 'Components/SideLabel', | ||
component: SideLabel, | ||
} | ||
|
||
export default meta | ||
|
||
export const WithSwitch = () => ( | ||
<SideLabel label="Check me"> | ||
<Switch /> | ||
</SideLabel> | ||
) | ||
|
||
export const Reversed = () => ( | ||
<SideLabel label="Check me" reverse> | ||
<Switch /> | ||
</SideLabel> | ||
) | ||
|
||
export const NoInput = () => ( | ||
<SideLabel label="Check me"> | ||
<span className="hidden">input goes here</span> | ||
</SideLabel> | ||
) |
30 changes: 30 additions & 0 deletions
30
packages/design-system/src/components/SideLabel/SideLabel.test.tsx
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,30 @@ | ||
// | ||
// This source file is part of the Stanford Biodesign Digital Health ENGAGE-HF open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import { vitest } from 'vitest' | ||
import { SideLabel } from '.' | ||
|
||
describe('SideLabel', () => { | ||
it('renders functional label element', () => { | ||
const onChange = vitest.fn() | ||
|
||
render( | ||
<SideLabel label="Toggle"> | ||
<input type="checkbox" onChange={onChange} /> | ||
</SideLabel>, | ||
) | ||
|
||
const textElement = screen.getByText('Toggle') | ||
fireEvent.click(textElement) | ||
|
||
expect(onChange).toHaveBeenCalledOnce() | ||
|
||
const element = screen.getByLabelText('Toggle') | ||
expect(element.tagName).toBe('INPUT') | ||
}) | ||
}) |
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