Skip to content

Commit

Permalink
fixed formatting in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutens committed Dec 3, 2024
1 parent 55a5364 commit d5bfcec
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions tests/unit/design-system/components/Switch/Switch.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { render, screen } from '@testing-library/react';
import { fireEvent } from '@testing-library/react';
import { AppSwitch } from '~/design-system/components/switch/Switch';
import { render, screen } from '@testing-library/react'
import { fireEvent } from '@testing-library/react'
import { AppSwitch } from '~/design-system/components/switch/Switch'

describe('AppSwitch Component', () => {
it('renders correctly with default props', () => {
render(<AppSwitch />);
render(<AppSwitch />)

const switchEl = screen.getByRole('checkbox');
expect(switchEl).toBeInTheDocument();
expect(switchEl).not.toBeDisabled();
});
const switchEl = screen.getByRole('checkbox')
expect(switchEl).toBeInTheDocument()
expect(switchEl).not.toBeDisabled()
})

it('calls `onChange` when toggled', () => {
const handleChange = vi.fn();
render(<AppSwitch onChange={handleChange} />);
const handleChange = vi.fn()
render(<AppSwitch onChange={handleChange} />)

const switchEl = screen.getByRole('checkbox');
fireEvent.click(switchEl);
const switchEl = screen.getByRole('checkbox')
fireEvent.click(switchEl)

expect(handleChange).toHaveBeenCalledTimes(1);
});
expect(handleChange).toHaveBeenCalledTimes(1)
})

it('renders label when provided', () => {
render(<AppSwitch label="Test Label" />);
render(<AppSwitch label="Test Label" />)

const labelEl = screen.getByText('Test Label');
expect(labelEl).toBeInTheDocument();
});
const labelEl = screen.getByText('Test Label')
expect(labelEl).toBeInTheDocument()
})

describe('Size classes', () => {
it.each([
['lg', 's2s-switch--lg'],
['md', 's2s-switch--md'],
['sm', 's2s-switch--sm'],
])('applies the correct class for size: %s', (size, expectedClass) => {
render(<AppSwitch size={size} />);
const switchWrapper = screen.getByRole('checkbox').closest('.s2s-switch--lg, .s2s-switch--md, .s2s-switch--sm');
render(<AppSwitch size={size} />)
const switchWrapper = screen.getByRole('checkbox').closest('.s2s-switch--lg, .s2s-switch--md, .s2s-switch--sm')

expect(switchWrapper).toHaveClass(expectedClass);
});
});
expect(switchWrapper).toHaveClass(expectedClass)
})
})

it('is disabled when loading is true', () => {
render(<AppSwitch loading />);
const loaderEl = screen.getByTestId('loader');
render(<AppSwitch loading />)
const loaderEl = screen.getByTestId('loader')

expect(loaderEl).toBeInTheDocument();
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument();
});
expect(loaderEl).toBeInTheDocument()
expect(screen.queryByRole('checkbox')).not.toBeInTheDocument()
})

it('is disabled when disabled prop is true', () => {
render(<AppSwitch disabled />);
const switchEl = screen.getByRole('checkbox');
render(<AppSwitch disabled />)
const switchEl = screen.getByRole('checkbox')

expect(switchEl).toBeDisabled();
});
expect(switchEl).toBeDisabled()
})

describe('Label position', () => {
it.each([
Expand All @@ -65,11 +65,11 @@ describe('AppSwitch Component', () => {
])(
'renders label in correct position: %s',
(position, label) => {
render(<AppSwitch label={label} labelPosition={position} />);
const labelEl = screen.getByText(label);
render(<AppSwitch label={label} labelPosition={position} />)
const labelEl = screen.getByText(label)

expect(labelEl).toBeInTheDocument();
expect(labelEl).toBeInTheDocument()
}
);
});
});
)
})
})

0 comments on commit d5bfcec

Please sign in to comment.