Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Jun 6, 2024
1 parent 8504c8f commit 6835746
Show file tree
Hide file tree
Showing 59 changed files with 266 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('SelectProjectInput', () => {
testServerRoute(server, '/api/admin/ui-config', {});
});

it('renders with default state', () => {
test('renders with default state', () => {
render(<SelectProjectInput {...mockProps} />);

const checkbox = screen.getByLabelText(
Expand All @@ -44,7 +44,7 @@ describe('SelectProjectInput', () => {
expect(input).toBeDisabled();
});

it('can toggle "ALL" checkbox', async () => {
test('can toggle "ALL" checkbox', async () => {
const user = userEvent.setup();
render(<SelectProjectInput {...mockProps} />);

Expand All @@ -65,7 +65,7 @@ describe('SelectProjectInput', () => {
expect(screen.getByLabelText('Projects')).toBeDisabled();
});

it('renders with autocomplete enabled if default value is not a wildcard', () => {
test('renders with autocomplete enabled if default value is not a wildcard', () => {
render(
<SelectProjectInput {...mockProps} defaultValue={['project1']} />,
);
Expand All @@ -81,7 +81,7 @@ describe('SelectProjectInput', () => {
});

describe('Select/Deselect projects in dropdown', () => {
it('selects and deselects all options', async () => {
test('selects and deselects all options', async () => {
const user = userEvent.setup();
render(<SelectProjectInput {...mockProps} defaultValue={[]} />);
await user.click(screen.getByLabelText('Projects'));
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('SelectProjectInput', () => {
});
});

it('can filter options', async () => {
test('can filter options', async () => {
const user = userEvent.setup();
render(
<SelectProjectInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { screen } from '@testing-library/react';
import { ProjectsList } from 'component/admin/apiToken/ProjectsList/ProjectsList';

describe('ProjectsList', () => {
it('should prioritize new "projects" array over deprecated "project"', async () => {
test('should prioritize new "projects" array over deprecated "project"', async () => {
render(
<ProjectsList
project='project'
Expand All @@ -19,27 +19,27 @@ describe('ProjectsList', () => {
expect(links[1]).toHaveAttribute('href', '/projects/project2');
});

it('should render correctly with single "project"', async () => {
test('should render correctly with single "project"', async () => {
render(<ProjectsList project='project' />);

const links = await screen.findAllByRole('link');
expect(links).toHaveLength(1);
expect(links[0]).toHaveTextContent('project');
});

it('should have comma between project links', async () => {
test('should have comma between project links', async () => {
const { container } = render(<ProjectsList projects={['a', 'b']} />);

expect(container.textContent).toContain(', ');
});

it('should render asterisk if no projects are passed', async () => {
test('should render asterisk if no projects are passed', async () => {
const { container } = render(<ProjectsList />);

expect(container.textContent).toEqual('*');
});

it('should render asterisk if empty projects array is passed', async () => {
test('should render asterisk if empty projects array is passed', async () => {
const { container } = render(<ProjectsList projects={[]} />);

expect(container.textContent).toEqual('*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { render } from 'utils/testRenderer';
import { screen } from '@testing-library/react';
import { OverwriteWarning } from './OverwriteWarning';
import type { ChangeRequestState } from 'component/changeRequest/changeRequest.types';
import { test } from 'vitest';

test.each([
['Draft', true],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { screen } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import { NameWithChangeInfo } from './NameWithChangeInfo';
import { test } from 'vitest';

test.each(['', undefined])(
'Should render only the new name if the previous name was %s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { IPermission } from '../../interfaces/user';
import { SWRConfig } from 'swr';
import type { ProjectMode } from '../project/Project/hooks/useProjectEnterpriseSettingsForm';
import { StickyProvider } from 'component/common/Sticky/StickyProvider';
import { test } from 'vitest';

const server = testServerSetup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { screen, waitFor } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import { testServerRoute, testServerSetup } from 'utils/testServer';
import { FeatureArchiveDialog } from './FeatureArchiveDialog';
import { test } from 'vitest';

const server = testServerSetup();
const setupHappyPathForChangeRequest = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const setup = (initialState: FilterItemParams | null) => {
};

describe('FilterDateItem Component', () => {
it('renders initial state correctly', async () => {
test('renders initial state correctly', async () => {
const mockState = {
operator: 'IS_ON_OR_AFTER',
values: ['2015-01-21'],
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('FilterDateItem Component', () => {
]);
});

it('renders initial popover when no existing value', async () => {
test('renders initial popover when no existing value', async () => {
const mockState = null;

setup(mockState);
Expand All @@ -65,7 +65,7 @@ describe('FilterDateItem Component', () => {
expect(results.length).toBeGreaterThanOrEqual(1);
});

it('switches operator', async () => {
test('switches operator', async () => {
const mockState = {
operator: 'IS_ON_OR_AFTER',
values: ['2020-01-01'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ import { PrettifyLargeNumber } from './PrettifyLargeNumber';
import { LARGE_NUMBER_PRETTIFIED } from 'utils/testIds';

describe('PrettifyLargeNumber', () => {
it('should render number with separator for value less than threshold', async () => {
test('should render number with separator for value less than threshold', async () => {
render(<PrettifyLargeNumber value={999999} threshold={1000000} />);

const prettifiedText = screen.getByTestId(LARGE_NUMBER_PRETTIFIED);

expect(prettifiedText.textContent).toHaveLength('999,999'.length);
});

it('should render prettified number for value equal to the threshold', async () => {
test('should render prettified number for value equal to the threshold', async () => {
render(<PrettifyLargeNumber value={1000000} threshold={1000000} />);

const prettifiedText = screen.getByTestId(LARGE_NUMBER_PRETTIFIED);

expect(prettifiedText.textContent).toBe('1M');
});

it('should render prettified number for value greater than threshold', async () => {
test('should render prettified number for value greater than threshold', async () => {
render(<PrettifyLargeNumber value={12345678} threshold={1000000} />);

const prettifiedText = screen.getByTestId(LARGE_NUMBER_PRETTIFIED);

expect(prettifiedText.textContent).toBe('12.35M');
});

it('should render prettified number with tooltip having raw value for value greater than threshold', async () => {
test('should render prettified number with tooltip having raw value for value greater than threshold', async () => {
render(<PrettifyLargeNumber value={12345678} threshold={1000000} />);

const prettifiedText = screen.getByTestId(LARGE_NUMBER_PRETTIFIED);
Expand All @@ -38,7 +38,7 @@ describe('PrettifyLargeNumber', () => {
);
});

it('should render prettified number with provided significant figures for value greater than threshold', async () => {
test('should render prettified number with provided significant figures for value greater than threshold', async () => {
render(
<PrettifyLargeNumber
value={12345678}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/component/common/Sticky/Sticky.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Sticky component', () => {
console.error = originalConsoleError;
});

it('renders correctly within StickyContext', () => {
test('renders correctly within StickyContext', () => {
render(
<StickyContext.Provider value={mockContextValue}>
<Sticky>Content</Sticky>
Expand All @@ -41,15 +41,15 @@ describe('Sticky component', () => {
expect(screen.getByText('Content')).toBeInTheDocument();
});

it('throws error when not wrapped in StickyContext', () => {
test('throws error when not wrapped in StickyContext', () => {
console.error = vi.fn();

expect(() => render(<Sticky>Content</Sticky>)).toThrow(
'Sticky component must be used within a StickyProvider',
);
});

it('applies sticky positioning', () => {
test('applies sticky positioning', () => {
render(
<StickyContext.Provider value={mockContextValue}>
<Sticky>Content</Sticky>
Expand All @@ -60,7 +60,7 @@ describe('Sticky component', () => {
expect(stickyElement).toHaveStyle({ position: 'sticky' });
});

it('registers and unregisters sticky item on mount/unmount', () => {
test('registers and unregisters sticky item on mount/unmount', () => {
const { unmount } = render(
<StickyContext.Provider value={mockContextValue}>
<Sticky>Content</Sticky>
Expand All @@ -74,7 +74,7 @@ describe('Sticky component', () => {
expect(mockUnregisterStickyItem).toHaveBeenCalledTimes(1);
});

it('correctly sets the top value when mounted', async () => {
test('correctly sets the top value when mounted', async () => {
render(
<StickyContext.Provider value={mockContextValue}>
<Sticky>Content</Sticky>
Expand All @@ -85,7 +85,7 @@ describe('Sticky component', () => {
expect(stickyElement).toHaveStyle({ top: '10px' });
});

it('updates top offset when stickyItems changes', async () => {
test('updates top offset when stickyItems changes', async () => {
const { rerender } = render(
<StickyContext.Provider value={mockContextValue}>
<Sticky>Content</Sticky>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/component/common/Sticky/StickyProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultGetBoundingClientRect = {
describe('StickyProvider component', () => {
afterEach(cleanup);

it('provides the sticky context with expected functions', () => {
test('provides the sticky context with expected functions', () => {
let receivedContext = null;
render(
<StickyProvider>
Expand All @@ -39,7 +39,7 @@ describe('StickyProvider component', () => {
expect(receivedContext).toHaveProperty('getTopOffset');
});

it('registers and unregisters sticky items', () => {
test('registers and unregisters sticky items', () => {
let contextValues: IStickyContext | undefined;
const refMock = { current: document.createElement('div') };

Expand Down Expand Up @@ -83,7 +83,7 @@ describe('StickyProvider component', () => {
expect(contextValues?.stickyItems).not.toContain(refMock);
});

it('sorts sticky items based on their DOM position', () => {
test('sorts sticky items based on their DOM position', () => {
let contextValues: IStickyContext | undefined;

const refMockA = { current: document.createElement('div') };
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('StickyProvider component', () => {
expect(contextValues?.stickyItems[1]).toBe(refMockA);
});

it('calculates top offset correctly', () => {
test('calculates top offset correctly', () => {
let contextValues: IStickyContext | undefined;
const refMockA = { current: document.createElement('div') };
const refMockB = { current: document.createElement('div') };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { LinkCell } from './LinkCell';

describe('LinkCell Component', () => {
it('renders the subtitle in an HtmlTooltip when length is greater than 40 characters', async () => {
test('renders the subtitle in an HtmlTooltip when length is greater than 40 characters', async () => {
const longSubtitle =
'This is a long subtitle that should trigger tooltip rendering.';
render(<LinkCell title='Test Title' subtitle={longSubtitle} />);
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/component/common/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const variantTemplate = {
};

describe('updateWeightEdit', () => {
it('can assign weight to one only variant', () => {
test('can assign weight to one only variant', () => {
const variants = [variantTemplate];
expect(updateWeightEdit(variants, 100)).toMatchInlineSnapshot(`
[
Expand All @@ -28,7 +28,7 @@ describe('updateWeightEdit', () => {
`);
});

it('can distribute weight between 2 variants evenly', () => {
test('can distribute weight between 2 variants evenly', () => {
const variants = [
variantTemplate,
{ ...variantTemplate, id: '2', name: 'B' },
Expand All @@ -38,7 +38,7 @@ describe('updateWeightEdit', () => {
});
});

it('can distribute weight between 8 variants evenly', () => {
test('can distribute weight between 8 variants evenly', () => {
const variants = Array.from({ length: 8 }, (_, i) => ({
...variantTemplate,
id: `${i}`,
Expand All @@ -50,7 +50,7 @@ describe('updateWeightEdit', () => {
});
});

it('can distribute weight between 8 variants evenly and assign the remainder to the last variant', () => {
test('can distribute weight between 8 variants evenly and assign the remainder to the last variant', () => {
const variants = Array.from({ length: 8 }, (_, i) => ({
...variantTemplate,
id: `${i}`,
Expand All @@ -63,7 +63,7 @@ describe('updateWeightEdit', () => {
expect(weights).toEqual([13, 12, 13, 12, 13, 12, 13, 12]);
});

it('can adjust variable weight to get correct sum', () => {
test('can adjust variable weight to get correct sum', () => {
const variants = [
{ ...variantTemplate, weightType: 'fix' as const, weight: 333 },
{ ...variantTemplate, id: '2', name: 'B' },
Expand All @@ -74,7 +74,7 @@ describe('updateWeightEdit', () => {
expect(weights).toEqual([333, 667]);
});

it('can deal with complex example', () => {
test('can deal with complex example', () => {
const variants = [
{ ...variantTemplate, weightType: 'fix' as const, weight: 333 },
{ ...variantTemplate, id: '2', name: 'B' },
Expand All @@ -97,7 +97,7 @@ describe('updateWeightEdit', () => {
expect(weights).toEqual([333, 93, 93, 93, 92, 111, 93, 92]);
});

it('can deal with 0-weight variable variant', () => {
test('can deal with 0-weight variable variant', () => {
const variants = [
{ ...variantTemplate, weightType: 'fix' as const, weight: 500 },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IFeatureMetricsRaw } from 'interfaces/featureToggle';
import { aggregateFeatureMetrics } from './aggregateFeatureMetrics';

describe('aggregateFeatureMetrics', () => {
it('should aggregate yes and no values for identical timestamps', () => {
test('should aggregate yes and no values for identical timestamps', () => {
const data: IFeatureMetricsRaw[] = [
{
featureName: 'Feature1',
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('aggregateFeatureMetrics', () => {
]);
});

it('should handle undefined variants correctly', () => {
test('should handle undefined variants correctly', () => {
const data: IFeatureMetricsRaw[] = [
{
featureName: 'Feature2',
Expand Down
Loading

0 comments on commit 6835746

Please sign in to comment.