Skip to content

Commit

Permalink
Merge pull request AdaptiveConsulting#276 from wenfeng-xing/test-addon
Browse files Browse the repository at this point in the history
chore: add the test addon
  • Loading branch information
wenfeng-xing authored Dec 22, 2022
2 parents 1f8ae74 + 22b25b1 commit 8102456
Show file tree
Hide file tree
Showing 7 changed files with 1,006 additions and 27 deletions.
2 changes: 2 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"@storybook/addon-essentials": "^6.5.12",
"@storybook/addon-interactions": "^6.5.12",
"@storybook/addon-links": "^6.5.12",
"@storybook/addon-storyshots": "^6.5.15",
"@storybook/addon-storysource": "^6.5.12",
"@storybook/builder-vite": "^0.2.2",
"@storybook/jest": "^0.0.10",
"@storybook/react": "^6.5.12",
"@storybook/testing-library": "^0.0.13",
"@ui-kit-2022/components": "0.0.1",
Expand Down
17 changes: 17 additions & 0 deletions docs/src/components/TextSearch.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { action } from '@storybook/addon-actions';
import { expect } from '@storybook/jest';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { userEvent, within } from '@storybook/testing-library';
import { TextSearch, TextSearchOptionBase } from '@ui-kit-2022/components';
import * as React from 'react';

Expand Down Expand Up @@ -94,8 +96,23 @@ BasicTextSearch.args = {
{ label: 'Another Option' },
{ label: 'A fourth option' },
],
disablePortal: true,
};

BasicTextSearch.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole('combobox');
await userEvent.click(input);
await userEvent.click(
canvas.getByRole('presentation').querySelectorAll('[role="option"]')[0],
);
expect(input.value).toBe('Option 1');
await userEvent.click(input);
await userEvent.click(
canvasElement.querySelector('.MuiAutocomplete-clearIndicator') as HTMLElement,
);
await userEvent.click(input);
};
interface Option extends TextSearchOptionBase {
type: 'stock' | 'currency';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import '@testing-library/jest-dom';

import { act, fireEvent, render, screen } from '@testing-library/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import '@testing-library/jest-dom';

import { render, screen } from '@testing-library/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import '@testing-library/jest-dom';

import { render, screen, fireEvent, within } from '@testing-library/react';
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-kit-components/src/utils/useIsDarkMode.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';
import { renderHook, RenderResult } from '@testing-library/react-hooks';
import { renderHook, RenderResult } from '@testing-library/react';
import { createTheme, ThemeProvider, Palette } from '@mui/material';
import UseIsDarkMode from './useIsDarkMode';

describe('Test UseIsDarkMode', () => {
describe('Given the UseIsDarkMode hook', () => {
describe('When the theme is dark', () => {
let res: RenderResult<boolean>;
let res: { current: boolean };
beforeEach(() => {
const theme = createTheme({
palette: {
Expand All @@ -26,7 +26,7 @@ describe('Test UseIsDarkMode', () => {
});

describe('When the theme is light', () => {
let res: RenderResult<boolean>;
let res: { current: boolean };
beforeEach(() => {
const theme = createTheme({
palette: {
Expand Down
Loading

0 comments on commit 8102456

Please sign in to comment.