diff --git a/.vscode/settings.json b/.vscode/settings.json index 63ece50f..9a5a7e7f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,24 +1,19 @@ { - "eslint.packageManager": "yarn", - "eslint.enable": true, - "eslint.autoFixOnSave": true, - "eslint.validate": [ - "javascript", - "javascriptreact", - { - "language": "typescript", - "autoFix": true - }, - { - "language": "typescriptreact", - "autoFix": true - } - ], - "typescript.tsdk": "node_modules/typescript/lib", - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - }, - "cSpell.words": [ - "datepicker" - ] + "eslint.enable": true, + "eslint.validate": [ + "javascript", + "javascriptreact", + { + "language": "typescript", + "autoFix": true + }, + { + "language": "typescriptreact", + "autoFix": true + } + ], + "typescript.tsdk": "node_modules/typescript/lib", + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + } } diff --git a/package.json b/package.json index e2e74338..388e6eae 100644 --- a/package.json +++ b/package.json @@ -1,120 +1,121 @@ { - "name": "flipper-ui", - "version": "0.31.3", - "description": "", - "main": "dist/index.js", - "homepage": "https://flipper-ui.ngi.com.br/", - "author": "NG", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/nginformatica/flipper-ui.git" - }, - "resolutions": { - "wrap-ansi": "7.0.0" - }, - "scripts": { - "start": "storybook dev -p 6006", - "build": "yarn clean && yarn build:ts && yarn build:babel", - "build:ts": "tsc --emitDeclarationOnly", - "build:babel": "babel src --out-dir dist --extensions \".ts,.tsx\" --ignore \"**/*.spec.tsx\" --ignore \"**/*.stories.tsx\"", - "build:link": "yarn build && yarn copy:package && yarn publish:yalc", - "lint": "eslint -c .eslintrc.js 'src/**/*.{ts,tsx}'", - "lint:fix": "eslint -c .eslintrc.js --fix 'src/**/*.{ts,tsx}'", - "lint:quiet": "eslint --quiet .eslintrc.js 'src/**/*.{ts,tsx}'", - "format": "prettier -w 'src/**/*.{ts,tsx}'", - "docs:build": "storybook build -o docs", - "clean": "rm -rf ./dist/*", - "type-check": "tsc --noEmit", - "copy:package": "cp package.json dist/", - "publish:yalc": "cd dist/ && yalc publish && cd ..", - "predeploy": "yarn build && yarn storybook:build", - "deploy": "gh-pages -d docs", - "release": "yarn build && node pre-publish.js && npm publish ./dist --access public", - "test:ci": "yarn test --coverage", - "test": "jest --silent --passWithNoTests --noStackTrace --runInBand" - }, - "dependencies": { - "@date-io/date-fns": "1.3.6", - "@emotion/react": "11.11.4", - "@emotion/styled": "11.11.0", - "@material-ui/core": "4.12.4", - "@material-ui/icons": "4.11.3", - "@material-ui/lab": "4.0.0-alpha.61", - "@material-ui/pickers": "3.3.11", - "@mui/icons-material": "5.15.12", - "@mui/material": "5.15.12", - "@mui/styles": "5.15.12", - "date-fns": "2.30.0", - "faker": "5.5.3", - "material-table": "1.69.3", - "material-ui-chip-input": "2.0.0-beta.2", - "ramda": "0.25.0", - "react-loading-skeleton": "3.4.0", - "react-number-format": "4.4.1", - "sprintf-js": "1.1.3", - "stylis": "4.3.1", - "uuid": "9.0.1" - }, - "devDependencies": { - "@babel/cli": "7.23.9", - "@babel/core": "7.24.0", - "@babel/plugin-transform-runtime": "7.24.0", - "@babel/preset-env": "7.24.0", - "@babel/preset-typescript": "7.23.3", - "@storybook/addon-essentials": "7.6.17", - "@storybook/addon-styling-webpack": "0.0.6", - "@storybook/react": "7.6.17", - "@storybook/react-webpack5": "7.6.17", - "@stylistic/eslint-plugin": "1.5.4", - "@testing-library/react": "14.2.1", - "@testing-library/user-event": "14.5.2", - "@types/faker": "5.5.3", - "@types/history": "5.0.0", - "@types/jest": "29.5.12", - "@types/node": "20.11.25", - "@types/ramda": "0.25.36", - "@types/react": "18.2.63", - "@types/sprintf-js": "1.1.4", - "@types/styled-components": "5.1.34", - "@types/uuid": "9.0.8", - "@typescript-eslint/eslint-plugin": "7.1.1", - "@typescript-eslint/parser": "7.1.1", - "babel-loader": "9.1.3", - "babel-plugin-module-resolver": "5.0.0", - "babel-plugin-transform-class-properties": "6.24.1", - "babel-plugin-transform-imports": "2.0.0", - "eslint": "8.57.0", - "eslint-config-prettier": "9.1.0", - "eslint-import-resolver-typescript": "3.6.1", - "eslint-plugin-import": "2.29.1", - "eslint-plugin-prettier": "5.1.3", - "eslint-plugin-react": "7.34.0", - "eslint-plugin-react-hooks": "4.6.0", - "fs-extra": "11.2.0", - "identity-obj-proxy": "3.0.0", - "jest": "29.7.0", - "jest-environment-jsdom": "29.7.0", - "node-fetch": "3.3.2", - "prettier": "3.2.5", - "react": "18.2.0", - "react-dom": "18.2.0", - "storybook": "7.6.17", - "styled-components": "6.1.8", - "ts-jest": "29.1.2", - "ts-loader": "9.5.1", - "typescript": "5.3.3", - "webpack": "5.90.3" - }, - "peerDependencies": { - "date-fns": "^2.30.0", - "react": "16.x || 17.x || 18.x", - "styled-components": "5.x || 6.x" - }, - "publishConfig": { - "ignore": [ - "!dist/", - "!/node_modules/" - ] - } + "name": "flipper-ui", + "version": "0.31.4", + "description": "", + "main": "dist/index.js", + "homepage": "https://flipper-ui.ngi.com.br/", + "author": "NG", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/nginformatica/flipper-ui.git" + }, + "resolutions": { + "wrap-ansi": "7.0.0" + }, + "scripts": { + "start": "storybook dev -p 6006", + "build": "yarn clean && yarn build:ts && yarn build:babel", + "build:ts": "tsc --emitDeclarationOnly", + "build:babel": "babel src --out-dir dist --extensions \".ts,.tsx\" --ignore \"**/*.spec.tsx\" --ignore \"**/*.stories.tsx\"", + "build:link": "yarn build && yarn copy:package && yarn publish:yalc", + "lint": "eslint -c .eslintrc.js 'src/**/*.{ts,tsx}'", + "lint:fix": "eslint -c .eslintrc.js --fix 'src/**/*.{ts,tsx}'", + "lint:quiet": "eslint --quiet .eslintrc.js 'src/**/*.{ts,tsx}'", + "format": "prettier -w 'src/**/*.{ts,tsx}'", + "docs:build": "storybook build -o docs", + "clean": "rm -rf ./dist/*", + "type-check": "tsc --noEmit", + "copy:package": "cp package.json dist/", + "publish:yalc": "cd dist/ && yalc publish && cd ..", + "predeploy": "yarn build && yarn storybook:build", + "deploy": "gh-pages -d docs", + "release": "yarn build && node pre-publish.js && npm publish ./dist --access public", + "test:ci": "yarn test --coverage", + "test": "jest --verbose --silent --passWithNoTests --noStackTrace --runInBand" + }, + "dependencies": { + "@date-io/date-fns": "1.3.6", + "@emotion/react": "11.11.4", + "@emotion/styled": "11.11.0", + "@material-ui/core": "4.12.4", + "@material-ui/icons": "4.11.3", + "@material-ui/lab": "4.0.0-alpha.61", + "@material-ui/pickers": "3.3.11", + "@mui/icons-material": "5.15.13", + "@mui/material": "5.15.13", + "@mui/styles": "5.15.13", + "date-fns": "2.30.0", + "faker": "5.5.3", + "material-table": "1.69.3", + "material-ui-chip-input": "2.0.0-beta.2", + "ramda": "0.25.0", + "react-loading-skeleton": "3.4.0", + "react-number-format": "4.4.1", + "sprintf-js": "1.1.3", + "stylis": "4.3.1", + "uuid": "9.0.1" + }, + "devDependencies": { + "@babel/cli": "7.23.9", + "@babel/core": "7.24.0", + "@babel/plugin-transform-runtime": "7.24.0", + "@babel/preset-env": "7.24.0", + "@babel/preset-typescript": "7.23.3", + "@storybook/addon-essentials": "7.6.17", + "@storybook/addon-styling-webpack": "0.0.6", + "@storybook/react": "7.6.17", + "@storybook/react-webpack5": "7.6.17", + "@stylistic/eslint-plugin": "1.5.4", + "@testing-library/jest-dom": "6.4.2", + "@testing-library/react": "14.2.1", + "@testing-library/user-event": "14.5.2", + "@types/faker": "5.5.3", + "@types/history": "5.0.0", + "@types/jest": "29.5.12", + "@types/node": "20.11.28", + "@types/ramda": "0.25.36", + "@types/react": "18.2.66", + "@types/sprintf-js": "1.1.4", + "@types/styled-components": "5.1.34", + "@types/uuid": "9.0.8", + "@typescript-eslint/eslint-plugin": "7.2.0", + "@typescript-eslint/parser": "7.2.0", + "babel-loader": "9.1.3", + "babel-plugin-module-resolver": "5.0.0", + "babel-plugin-transform-class-properties": "6.24.1", + "babel-plugin-transform-imports": "2.0.0", + "eslint": "8.57.0", + "eslint-config-prettier": "9.1.0", + "eslint-import-resolver-typescript": "3.6.1", + "eslint-plugin-import": "2.29.1", + "eslint-plugin-prettier": "5.1.3", + "eslint-plugin-react": "7.34.0", + "eslint-plugin-react-hooks": "4.6.0", + "fs-extra": "11.2.0", + "identity-obj-proxy": "3.0.0", + "jest": "29.7.0", + "jest-environment-jsdom": "29.7.0", + "node-fetch": "3.3.2", + "prettier": "3.2.5", + "react": "18.2.0", + "react-dom": "18.2.0", + "storybook": "7.6.17", + "styled-components": "6.1.8", + "ts-jest": "29.1.2", + "ts-loader": "9.5.1", + "typescript": "5.4.2", + "webpack": "5.90.3" + }, + "peerDependencies": { + "date-fns": "^2.30.0", + "react": "16.x || 17.x || 18.x", + "styled-components": "5.x || 6.x" + }, + "publishConfig": { + "ignore": [ + "!dist/", + "!/node_modules/" + ] + } } diff --git a/src/core/context/theme-provider/theme-provider.spec.tsx b/src/core/context/theme-provider/theme-provider.spec.tsx index 1abe4c91..4bc91565 100644 --- a/src/core/context/theme-provider/theme-provider.spec.tsx +++ b/src/core/context/theme-provider/theme-provider.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import ThemeProvider from '.' diff --git a/src/core/data-display/advertise/advertise.spec.tsx b/src/core/data-display/advertise/advertise.spec.tsx index 0803b296..19705632 100644 --- a/src/core/data-display/advertise/advertise.spec.tsx +++ b/src/core/data-display/advertise/advertise.spec.tsx @@ -1,11 +1,8 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import Advertise from '.' describe('Advertise', () => { - const newPadding = '10px 10px' - const CUSTOM = { padding: newPadding } - it('should render', () => { render() @@ -14,38 +11,39 @@ describe('Advertise', () => { expect(author).toBeDefined() expect(author).toHaveProperty('style.padding', '6px 18px') + expect(comment).toBeDefined() expect(comment).toHaveProperty('style.padding', '6px 18px') }) it('should render with custom author style', () => { - const newPadding = '10px 10px' - render( - + ) const author = screen.getByText('author') expect(author).toBeDefined() - expect(author).toHaveProperty('style.padding', newPadding) + expect(author).toHaveProperty('style.padding', '10px 10px') }) it('should render with custom comment style', () => { - const newPadding = '10px 10px' - render( ) const comment = screen.getByText('comment') expect(comment).toBeDefined() - expect(comment).toHaveProperty('style.padding', newPadding) + expect(comment).toHaveProperty('style.padding', '10px 10px') }) it('should match snapshot', () => { diff --git a/src/core/data-display/advertise/index.tsx b/src/core/data-display/advertise/index.tsx index 7c66cd95..c429a688 100644 --- a/src/core/data-display/advertise/index.tsx +++ b/src/core/data-display/advertise/index.tsx @@ -4,23 +4,9 @@ import type { DefaultProps } from '../../types' import { AdvertiseTypography, Paper } from './styles' export interface AdvertiseProps extends DefaultProps { - /** - * The comment to be displayed - */ comment: string - /** - * The author of the comment - */ author: string - /** - * The style of the comments - * @optional - */ commentStyle?: CSSProperties - /** - * The style of the author - * @optional - */ authorStyle?: CSSProperties } diff --git a/src/core/data-display/avatar/__snapshots__/avatar.spec.tsx.snap b/src/core/data-display/avatar/__snapshots__/avatar.spec.tsx.snap new file mode 100644 index 00000000..da5cb889 --- /dev/null +++ b/src/core/data-display/avatar/__snapshots__/avatar.spec.tsx.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Avatar should match snapshot 1`] = ` +
+
+ F +
+
+`; diff --git a/src/core/data-display/avatar/avatar.spec.tsx b/src/core/data-display/avatar/avatar.spec.tsx index bdb6585a..ee7176d5 100644 --- a/src/core/data-display/avatar/avatar.spec.tsx +++ b/src/core/data-display/avatar/avatar.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import Typography from '@/core/data-display/typography' import { Avatar } from '.' @@ -12,7 +12,7 @@ describe('Avatar', () => { expect(avatar).toBeDefined() }) - it('should render primary', () => { + it('should render primary color', () => { render( F @@ -29,12 +29,10 @@ describe('Avatar', () => { }) it('should render with custom className', () => { - const customClass = 'custom-class' - render( F @@ -42,7 +40,7 @@ describe('Avatar', () => { const container = screen.getByTestId('avatar-container') - expect(container.classList).toContain(customClass) + expect(container.classList).toContain('custom-class') }) it('should render nested children', () => { @@ -58,4 +56,14 @@ describe('Avatar', () => { expect(avatar).toBeDefined() }) + + it('should match snapshot', () => { + const { container } = render( + + F + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/avatar/index.tsx b/src/core/data-display/avatar/index.tsx index cef8231c..ca25be80 100644 --- a/src/core/data-display/avatar/index.tsx +++ b/src/core/data-display/avatar/index.tsx @@ -7,9 +7,6 @@ import type { AvatarProps as MuiAvatarProps } from '@material-ui/core' import type { Theme } from '@material-ui/core/styles' export interface AvatarProps extends DefaultProps, MuiAvatarProps { - /** - * If true, the avatar will have a primary color background. - */ primary?: boolean children?: ReactNode 'data-testid'?: string diff --git a/src/core/data-display/badge/__snapshots__/badge.spec.tsx.snap b/src/core/data-display/badge/__snapshots__/badge.spec.tsx.snap index d545dbbf..061287a7 100644 --- a/src/core/data-display/badge/__snapshots__/badge.spec.tsx.snap +++ b/src/core/data-display/badge/__snapshots__/badge.spec.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Badges - Snapshots should match snapshot 1`] = ` +exports[`Badge should match snapshot 1`] = `
{ it('should render', () => { render(Badge) - const avatar = screen.getByText('Badge') - const badge = screen.getByText('2') + const badge = screen.getByText('Badge') + const counter = screen.getByText('2') - expect(avatar).toBeDefined() expect(badge).toBeDefined() + expect(counter).toBeDefined() }) it('should render with primary color', () => { @@ -24,9 +24,7 @@ describe('Badge', () => { expect(badge.classList).toContain('MuiBadge-colorPrimary') }) -}) -describe('Badges - Snapshots', () => { it('should match snapshot', () => { const { container } = render(Badge) diff --git a/src/core/data-display/badge/index.tsx b/src/core/data-display/badge/index.tsx index 909b44a2..fb7081e6 100644 --- a/src/core/data-display/badge/index.tsx +++ b/src/core/data-display/badge/index.tsx @@ -7,13 +7,7 @@ import type { BadgeProps as MuiBadgeProps } from '@material-ui/core/Badge' export interface BadgeProps extends DefaultProps, MuiBadgeProps { children: ReactNode - /** - * The number to display in the badge. - */ counter: number | string - /** - * The position of the badge. - */ position?: { top?: number bottom?: number diff --git a/src/core/data-display/chapter/__snapshots__/chapter.spec.tsx.snap b/src/core/data-display/chapter/__snapshots__/chapter.spec.tsx.snap new file mode 100644 index 00000000..6d051e11 --- /dev/null +++ b/src/core/data-display/chapter/__snapshots__/chapter.spec.tsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Chapter should match snapshot 1`] = ` +
+
+
+

+ Chapter +

+
+
+
+`; diff --git a/src/core/data-display/chapter/chapter.spec.tsx b/src/core/data-display/chapter/chapter.spec.tsx index b9a02920..b7c69f1d 100644 --- a/src/core/data-display/chapter/chapter.spec.tsx +++ b/src/core/data-display/chapter/chapter.spec.tsx @@ -1,16 +1,17 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import Chapter from '.' describe('Chapter', () => { it('should render', () => { render(Chapter) + const chapter = screen.getByText('Chapter') expect(chapter).toBeDefined() }) - it('should spread props', () => { + it('should render primary color', () => { render( Chapter @@ -20,4 +21,10 @@ describe('Chapter', () => { expect(chapter).toBeDefined() }) + + it('should match snapshot', () => { + const { container } = render(Chapter) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/chapter/index.tsx b/src/core/data-display/chapter/index.tsx index c94d07ff..3a12cab1 100644 --- a/src/core/data-display/chapter/index.tsx +++ b/src/core/data-display/chapter/index.tsx @@ -6,25 +6,10 @@ import Typography from '@/core/data-display/typography' import { Container, StyledLine } from './styles' export interface LineProps extends DefaultProps { - /** - * If true, the avatar will have a primary color background. - */ primary?: boolean - /** - * The width of the component container. - */ width?: string - /** - * The variant to use. - */ variant?: TypographyProps['variant'] - /** - * The style applied to the children Typography component. - */ childrenStyle?: CSSProperties - /** - * The children of the component. - */ children?: ReactNode 'data-testid'?: string } diff --git a/src/core/data-display/chip/__snapshots__/chip.spec.tsx.snap b/src/core/data-display/chip/__snapshots__/chip.spec.tsx.snap new file mode 100644 index 00000000..4e03947d --- /dev/null +++ b/src/core/data-display/chip/__snapshots__/chip.spec.tsx.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Chip should match snapshot 1`] = ` +
+
+ + chip-label + +
+
+`; diff --git a/src/core/data-display/chip/chip.spec.tsx b/src/core/data-display/chip/chip.spec.tsx index 4b1f8674..904b25fe 100644 --- a/src/core/data-display/chip/chip.spec.tsx +++ b/src/core/data-display/chip/chip.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen, waitFor } from '@testing-library/react' import Chip from '.' @@ -38,4 +38,12 @@ describe('Chip', () => { expect(onDelete).toHaveBeenCalled() }) }) + + it('should match snapshot', () => { + const { container } = render( + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/chip/index.tsx b/src/core/data-display/chip/index.tsx index 6a5f9095..c773e986 100644 --- a/src/core/data-display/chip/index.tsx +++ b/src/core/data-display/chip/index.tsx @@ -7,9 +7,6 @@ import type { ChipProps as MuiChipProps } from '@material-ui/core' export interface IChipProps extends MuiChipProps, Omit { - /** - * If `true`, the chip will be squared. - */ square?: boolean } diff --git a/src/core/data-display/data-table/data-table-field.spec.tsx b/src/core/data-display/data-table/data-table-field.spec.tsx new file mode 100644 index 00000000..1d049a68 --- /dev/null +++ b/src/core/data-display/data-table/data-table-field.spec.tsx @@ -0,0 +1,185 @@ +import React from 'react' +import { fireEvent, render, screen, waitFor } from '@testing-library/react' +import { DataTableField } from './data-table-field' +import '@testing-library/jest-dom' + +const dataInput = [ + { + branch: 'Keepfy Joinville', + local: 'Joiville', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy São Paulo', + local: 'São Paulo', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Rio Grande do Sul', + local: 'Rio Grande do Sul', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Rio de Janeiro', + local: 'Rio de Janeiro', + status: 'Ativo', + companyCode: '', + branchCode: '' + } +] + +const tableHead = [ + { + title: 'Nome da Filial', + field: 'branch', + type: 'text', + editable: false + }, + { + title: 'Localidade', + field: 'local', + type: 'text', + editable: false + }, + { + title: 'Status', + field: 'status', + type: 'text', + editable: false + }, + { + title: 'Código da Empresa', + field: 'companyCode', + type: 'number', + editable: true + }, + { + title: 'Código da Filial', + field: 'branchCode', + type: 'text', + editable: true + } +] + +describe('DataTableField', () => { + it('should render', () => { + render( + + ) + + const container = screen.getByTestId('data-table-field') + + expect(container).toBeDefined() + }) + + it('should render with all the rows', () => { + render( + + ) + + const rows = screen.getAllByRole('rowgroup')[1].childElementCount + + expect(rows).toBe(4) + }) + + it('should render header and rows content', () => { + const { findAllByText } = render( + + ) + + const tableRowValue = findAllByText('Keepfy Joinville') + const tableHeadValue = findAllByText('Nome da Filial') + + expect(tableRowValue).toBeDefined() + expect(tableHeadValue).toBeDefined() + }) + + it('should check the checkbox when clicked', () => { + render( + + ) + + const checkbox = screen.getAllByRole('checkbox')[0] + + expect(checkbox).not.toBeChecked() + + fireEvent.click(checkbox) + + waitFor(() => { + expect(checkbox).toBeChecked() + }) + }) + + it('should render text field when checkRow is true', () => { + render( + + ) + + const textField = screen.getByRole('textbox') + + waitFor(() => { + expect(textField).toBeInTheDocument() + }) + }) +}) diff --git a/src/core/data-display/data-table/data-table-field.tsx b/src/core/data-display/data-table/data-table-field.tsx index 0c680139..5ac54da1 100644 --- a/src/core/data-display/data-table/data-table-field.tsx +++ b/src/core/data-display/data-table/data-table-field.tsx @@ -195,7 +195,7 @@ export const DataTableField = >( }) return ( - +
{checkbox && ( diff --git a/src/core/data-display/data-table/data-table-query-paginated.tsx b/src/core/data-display/data-table/data-table-query-paginated.tsx index a85e881a..2c4538eb 100644 --- a/src/core/data-display/data-table/data-table-query-paginated.tsx +++ b/src/core/data-display/data-table/data-table-query-paginated.tsx @@ -34,83 +34,24 @@ export type DataTableProps< D extends Data, V extends StackView = Record > = { - /** - * The data to be shown in the table - */ data: D[] - /** - * The total elements present in query - */ totalElements: number - /** - * Change current page handler - */ handleChangePage: (page: number) => void - /** - * Per page value - */ perPage: number - /** - * Change page handler - */ handleChangePerPage: (value: number) => void - /** - * Actual page - */ page: number - /** - * Errors as an object where the key is the ID of the row and the value is - * a Set with the fields of error - */ errors?: Errors - /** - * The columns specification - */ columns: ColumnSpec[] - /** - * Hide the table header - */ noHeader?: boolean - /** - * Component to show when there are no data - */ componentForEmpty?: ReactNode - /** - * Custom style to be applied to the table body - */ bodyStyle?: CSSProperties - /** - * Custom style to be applied to the table head - */ headStyle?: CSSProperties - /** - * Custom style to be applied to all rows of the table body - */ bodyRowStyle?: CSSProperties - /** - * Custom style to be applied to all rows of the table head - */ headRowStyle?: CSSProperties - /** - * Height of a hidden row, when you need to have some blank space in case - * you fill in the pagination.rowsPerPage - */ hiddenRowHeight?: number - /** - * The pagination configuration - */ pagination?: Partial - /** - * A React MutableRefObject for the row controller - */ controllerRef?: MutableRefObject | undefined> - /** - * Initialize with hidden values - */ hidden?: boolean - /** - * Custom rowViews used as a Stac - */ rowViews?: Record> onRowClick?: (event: MouseEvent, rowData: D) => void } diff --git a/src/core/data-display/data-table/data-table.spec.tsx b/src/core/data-display/data-table/data-table.spec.tsx index 32d40c93..29b93e1c 100644 --- a/src/core/data-display/data-table/data-table.spec.tsx +++ b/src/core/data-display/data-table/data-table.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { fireEvent, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' diff --git a/src/core/data-display/data-table/data-table.stories.tsx b/src/core/data-display/data-table/data-table.stories.tsx index 03556a28..ccda2e4e 100644 --- a/src/core/data-display/data-table/data-table.stories.tsx +++ b/src/core/data-display/data-table/data-table.stories.tsx @@ -33,15 +33,29 @@ type Data = { date: Date } +type DataCrud = { + id: Identifier + product: string + price: number + quantity: number + date: Date +} + +type DataCrudWithHidden = { + id: Identifier + name: string + key: string + secret: string + rowMode: RowMode +} + +type View = { + confirmDelete(): JSX.Element +} + export const Default = () => { - type Data = { - id: number - product: string - price: number - quantity: number - date: Date - } const date = () => new Date() + const data = [ { id: 1, @@ -177,6 +191,7 @@ export const Empty = () => { export const NoHeader = () => { const date = () => new Date() + const data = [ { id: 1, @@ -257,6 +272,7 @@ export const NoHeader = () => { export const NoPagination = () => { const date = () => new Date() + const data = [ { id: 1, @@ -334,25 +350,13 @@ export const NoPagination = () => { } export const Crud = () => { - type Data = { - id: Identifier - product: string - price: number - quantity: number - date: Date - } - - type View = { - confirmDelete(): JSX.Element - } - const date = () => new Date() - const controllerRef = useRef>() + const controllerRef = useRef>() const [errors, setErrors] = useState({}) const randomId = () => Math.random().toString(36).substr(0, 12) - const [data, setData] = useState([ + const [data, setData] = useState([ { id: 1, product: 'Magazine', price: 13.5, quantity: 12, date: date() }, { id: 2, product: 'Table', price: 200.49, quantity: 3, date: date() }, { id: 3, product: 'Chair', price: 53.5, quantity: 9, date: date() }, @@ -599,24 +603,13 @@ export const Crud = () => { } export const CrudWithHidden = () => { - type Data = { - id: Identifier - name: string - key: string - secret: string - rowMode: RowMode - } - - type View = { - confirmDelete(): JSX.Element - } - - const controllerRef = useRef>() + const controllerRef = + useRef>() const [errors, setErrors] = useState({}) const randomId = () => Math.random().toString(36).substr(0, 12) - const [data, setData] = useState([ + const [data, setData] = useState([ { id: 1, name: 'PowerBI', @@ -708,7 +701,11 @@ export const CrudWithHidden = () => { if (isNew) { setData(data => [ - { ...nextItem, key: uuid(), secret: uuid() } as Data, + { + ...nextItem, + key: uuid(), + secret: uuid() + } as DataCrudWithHidden, ...data ]) } else { @@ -729,7 +726,7 @@ export const CrudWithHidden = () => { controllerRef.current?.viewRow(id) } - const columns: ColumnSpec[] = [ + const columns: ColumnSpec[] = [ { title: 'Name', field: 'name', @@ -841,7 +838,7 @@ export const CrudWithHidden = () => { ] const rowViews = { - confirmDelete: ({ data }: { data: Data }) => { + confirmDelete: ({ data }: { data: DataCrudWithHidden }) => { return (
{ ) } -const dataInput = [ - { - branch: 'Keepfy Joinville', - local: 'Joiville', - status: 'Ativo', - companyCode: '', - branchCode: '' - }, - { - branch: 'Keepfy São Paulo', - local: 'São Paulo', - status: 'Ativo', - companyCode: '', - branchCode: '' - }, - { - branch: 'Keepfy Rio Grande do Sul', - local: 'Rio Grande do Sul', - status: 'Ativo', - companyCode: '', - branchCode: '' - }, - { - branch: 'Keepfy Rio de Janeiro', - local: 'Rio de Janeiro', - status: 'Ativo', - companyCode: '', - branchCode: '' - }, - { - branch: 'Keepfy Curitiba', - local: 'Curitiba', - status: 'Ativo', - companyCode: '', - branchCode: '' - }, - { - branch: 'Keepfy Teresópolis', - local: 'Teresópolis', - status: 'Ativo', - companyCode: '', - branchCode: '' - } -] - -const tableHead = [ - { - title: 'Nome da Filial', - field: 'branch', - type: 'text', - editable: false - }, - { - title: 'Localidade', - field: 'local', - type: 'text', - editable: false - }, - { - title: 'Status', - field: 'status', - type: 'text', - editable: false - }, - { - title: 'Código da Empresa', - field: 'companyCode', - type: 'number', - editable: true - }, - { - title: 'Código da Filial', - field: 'branchCode', - type: 'text', - editable: true - } -] - export const WithField = () => { + const dataInput = [ + { + branch: 'Keepfy Joinville', + local: 'Joiville', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy São Paulo', + local: 'São Paulo', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Rio Grande do Sul', + local: 'Rio Grande do Sul', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Rio de Janeiro', + local: 'Rio de Janeiro', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Curitiba', + local: 'Curitiba', + status: 'Ativo', + companyCode: '', + branchCode: '' + }, + { + branch: 'Keepfy Teresópolis', + local: 'Teresópolis', + status: 'Ativo', + companyCode: '', + branchCode: '' + } + ] + + const tableHead = [ + { + title: 'Nome da Filial', + field: 'branch', + type: 'text', + editable: false + }, + { + title: 'Localidade', + field: 'local', + type: 'text', + editable: false + }, + { + title: 'Status', + field: 'status', + type: 'text', + editable: false + }, + { + title: 'Código da Empresa', + field: 'companyCode', + type: 'number', + editable: true + }, + { + title: 'Código da Filial', + field: 'branchCode', + type: 'text', + editable: true + } + ] + const [data, setData] = useState[]>(() => dataInput) const [selectedAll, setSelectedAll] = useState(false) const [selected, setSelected] = useState( diff --git a/src/core/data-display/data-table/data-table.tsx b/src/core/data-display/data-table/data-table.tsx index 7e76460b..378fbe96 100644 --- a/src/core/data-display/data-table/data-table.tsx +++ b/src/core/data-display/data-table/data-table.tsx @@ -37,71 +37,21 @@ export type DataTableProps< D extends Data, V extends StackView = Record > = { - /** - * The data to be shown in the table - */ data: D[] - /** - * Errors as an object where the key is the ID of the row and the value is - * a Set with the fields of error - */ errors?: Errors - /** - * The columns specification - */ columns: ColumnSpec[] - /** - * Hide the table header - */ noHeader?: boolean - /** - * Component to show when there are no data - */ componentForEmpty?: ReactNode - /** - * Custom style to be applied to the table body - */ bodyStyle?: CSSProperties - /** - * Custom style to be applied to the table head - */ headStyle?: CSSProperties - /** - * Custom style to be applied to all rows of the table body - */ bodyRowStyle?: CSSProperties - /** - * Custom style to be applied to all rows of the table head - */ headRowStyle?: CSSProperties - /** - * Height of a hidden row, when you need to have some blank space in case - * you fill in the pagination.rowsPerPage - */ hiddenRowHeight?: number - /** - * The pagination configuration - */ pagination?: Partial - /** - * A React MutableRefObject for the row controller - */ controllerRef?: MutableRefObject | undefined> - /** - * Initialize with hidden values - */ hidden?: boolean - /** - * Custom rowViews used as a Stac - */ rowViews?: Record> - /** - * Hide or show the checkbox - */ checkbox?: boolean - /** - * Handle the selected states and values - */ checkboxProps?: { checkRow?: boolean[] checkAllRows?: boolean diff --git a/src/core/data-display/data-table/rows.tsx b/src/core/data-display/data-table/rows.tsx index 12f25906..4a78fe75 100644 --- a/src/core/data-display/data-table/rows.tsx +++ b/src/core/data-display/data-table/rows.tsx @@ -13,6 +13,13 @@ type RowStateUpdater = ( value: D[keyof D] ) => void +type NewRowProps = { + data: PartialData + errors?: Errors + columns: ColumnSpec[] + onUpdate?(partial: Partial): void +} + const isEditable = (column: ColumnSpec) => column.type === 'actions' || column.editable @@ -210,13 +217,6 @@ export const StatefulRow = ({ ) } -type NewRowProps = { - data: PartialData - errors?: Errors - columns: ColumnSpec[] - onUpdate?(partial: Partial): void -} - export const NewRow = ({ data, columns, diff --git a/src/core/data-display/data-table/types.ts b/src/core/data-display/data-table/types.ts index 4b509fb4..3a0bcf59 100644 --- a/src/core/data-display/data-table/types.ts +++ b/src/core/data-display/data-table/types.ts @@ -103,29 +103,11 @@ export type RowViewComponent = FunctionComponent<{ }> export type DataTableController = { - /** - * Actives the edit mode for a row - */ editRow(id: Identifier): void - /** - * Actives the view mode for a row - */ viewRow(id: Identifier): void - /** - * Hides the view mode for a row - */ hideRow(id: Identifier): void - /** - * Adds a new row on the DataTable - */ addRow(data: PartialData): void - /** - * Returns only the edited properties of a row in edit mode - */ getEditedRowData(id: Identifier): PartialData - /** - * Returns the edited properties and the old data of a row in edit mode - */ getRowData(id: Identifier): { edited: PartialData; current?: D } pushRowView(id: Identifier, view: keyof V): void popRowView(id: Identifier): void diff --git a/src/core/data-display/data-table/use-paginated.ts b/src/core/data-display/data-table/use-paginated.ts index df8a2ee2..181000f2 100644 --- a/src/core/data-display/data-table/use-paginated.ts +++ b/src/core/data-display/data-table/use-paginated.ts @@ -35,15 +35,11 @@ export const generateRandomDate = (size: number): Data[] => { return content } -const MOCK_DELAY_VALUE = 1000 -const DEFAULT_PAGE_SIZE = 5 -const DEFAULT_MOCK_LENGTH = 35 - -const mockData = generateRandomDate(DEFAULT_MOCK_LENGTH) +const mockData = generateRandomDate(35) const INITIAL_STATE: IPaginated = { items: [], - size: DEFAULT_PAGE_SIZE, + size: 5, actualPage: 0, totalItens: 0 } @@ -61,7 +57,7 @@ export const usePaginated = () => { setState(prev => ({ ...prev, totalItens: mockData.length })) setTimeout(() => { setLoading(false) - }, MOCK_DELAY_VALUE) + }, 1000) }, []) useEffect(() => { @@ -85,18 +81,22 @@ export const usePaginated = () => { const handleChangePage = (newPage: number) => { setLoading(true) + setState(prev => ({ ...prev, actualPage: newPage })) + setTimeout(() => { setLoading(false) - }, MOCK_DELAY_VALUE) + }, 1000) } const handleChangePerPage = (value: number) => { setLoading(true) + setState(prev => ({ ...prev, size: value })) + setTimeout(() => { setLoading(false) - }, MOCK_DELAY_VALUE) + }, 1000) } const setData: Dispatch> = (data: Data[]) => { diff --git a/src/core/data-display/divider/divider.spec.tsx b/src/core/data-display/divider/divider.spec.tsx index f709a622..d1e96073 100644 --- a/src/core/data-display/divider/divider.spec.tsx +++ b/src/core/data-display/divider/divider.spec.tsx @@ -1,10 +1,11 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import { Divider } from '.' describe('Divider', () => { it('should render', () => { render() + const divider = screen.getByTestId('divider') expect(divider).toBeDefined() @@ -19,6 +20,7 @@ describe('Divider', () => { style={{ backgroundColor: 'blue' }} /> ) + const divider = screen.getByTestId('divider') expect(divider).toHaveProperty('style.margin', '10px') diff --git a/src/core/data-display/editable-table/editable-table-with-date.spec.tsx b/src/core/data-display/editable-table/editable-table-with-date.spec.tsx index 063b45e2..b5f951ab 100644 --- a/src/core/data-display/editable-table/editable-table-with-date.spec.tsx +++ b/src/core/data-display/editable-table/editable-table-with-date.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event/' @@ -92,6 +92,7 @@ describe('EditableTable - With Date', () => { const dateInput = screen.getByRole('date-picker') as HTMLInputElement expect(dateInput.value).toBe('01/07/2019 17:21') + jest.clearAllMocks() }) }) diff --git a/src/core/data-display/editable-table/editable-table.spec.tsx b/src/core/data-display/editable-table/editable-table.spec.tsx index 1653c318..4e8d47b9 100644 --- a/src/core/data-display/editable-table/editable-table.spec.tsx +++ b/src/core/data-display/editable-table/editable-table.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { fireEvent, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event/' @@ -128,26 +128,6 @@ describe('EditableTable', () => { expect(label).toBeDefined() }) - it('should render with no data', () => { - render( - - ) - - const label = screen.getByText( - 'Não há dados para serem exibidos no momento' - ) - - expect(label).toBeDefined() - }) - it('should render with no data or columns', () => { render( { const label = screen.getByText('Adicionar item') await userEvent.click(label) + const nameInput = screen.getByRole('name-input').firstElementChild ?.firstElementChild as HTMLInputElement const valueInput = screen.getByRole('name-input').firstElementChild @@ -322,27 +303,6 @@ describe('EditableTable', () => { expect(label).toBeDefined() }) - it('should render with no pagination info', () => { - render( - - ) - - const label = screen.getByText('Fulano') - - expect(label).toBeDefined() - }) - it('should call update row with correct values', async () => { const onUpdateSpy = jest .fn() @@ -539,10 +499,9 @@ describe('EditableTable', () => { await act(async () => await userEvent.click(editFirstRow)) const dateInput = screen.getByRole('date-picker') as HTMLInputElement - - expect(dateInput.value).toBe('01/07/2019 17:21') const textInput = screen.getAllByTestId('text-field')[0] + expect(dateInput.value).toBe('01/07/2019 17:21') expect(dateInput.parentElement?.classList).toContain('Mui-error') expect(textInput.classList).toContain('Mui-error') }) diff --git a/src/core/data-display/editable-table/editable-table.stories.tsx b/src/core/data-display/editable-table/editable-table.stories.tsx index d1feeb75..3092a02a 100644 --- a/src/core/data-display/editable-table/editable-table.stories.tsx +++ b/src/core/data-display/editable-table/editable-table.stories.tsx @@ -3,7 +3,7 @@ import type { Meta, StoryFn } from '@storybook/react' import EditableTable from '.' export default { - title: 'DataDisplay/EditTable', + title: 'DataDisplay/EditableTable', component: EditableTable, args: { title: 'adicionar', diff --git a/src/core/data-display/fab/fab.spec.tsx b/src/core/data-display/fab/fab.spec.tsx index 7fbbab67..e6cae539 100644 --- a/src/core/data-display/fab/fab.spec.tsx +++ b/src/core/data-display/fab/fab.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import Fab from '.' diff --git a/src/core/data-display/line/index.tsx b/src/core/data-display/line/index.tsx index 65975076..3598431c 100644 --- a/src/core/data-display/line/index.tsx +++ b/src/core/data-display/line/index.tsx @@ -5,9 +5,6 @@ import { theme } from '@/theme' const { grays, secondary } = theme.colors export interface LineProps extends DefaultProps { - /** - * If true, the line will use the primary color. - */ primary?: boolean 'data-testid'?: string } diff --git a/src/core/data-display/line/line.spec.tsx b/src/core/data-display/line/line.spec.tsx index 0532940c..d8e739c2 100644 --- a/src/core/data-display/line/line.spec.tsx +++ b/src/core/data-display/line/line.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import { Line } from '.' import { theme } from '@/theme' @@ -12,7 +12,6 @@ describe('Line', () => { const element = screen.getByTestId('line-component') expect(element).toBeDefined() - expect(element).toHaveProperty('style.flex', '1') }) it('should render with custom styles', () => { @@ -27,6 +26,7 @@ describe('Line', () => { const element = screen.getByTestId('line-component') + expect(element).toHaveProperty('style.flex', '1') expect(element).toHaveProperty('style.color', 'red') expect(element).toHaveProperty('style.margin', '10px') expect(element).toHaveProperty('style.padding', '5px') diff --git a/src/core/data-display/list-item/__snapshots__/list-item.spec.tsx.snap b/src/core/data-display/list-item/__snapshots__/list-item.spec.tsx.snap new file mode 100644 index 00000000..0a0af15f --- /dev/null +++ b/src/core/data-display/list-item/__snapshots__/list-item.spec.tsx.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ListItem should match snapshot 1`] = ` +
+
+
+
+ Avatar +
+
+
+ + Item 1 + +
+
+
+ Action +
+
+ +
+
+`; diff --git a/src/core/data-display/list-item/index.tsx b/src/core/data-display/list-item/index.tsx index 5f6bc8d0..5931e3e9 100644 --- a/src/core/data-display/list-item/index.tsx +++ b/src/core/data-display/list-item/index.tsx @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react' +import React from 'react' import type { MouseEvent } from 'react' import { ListItem as MuiListItem, @@ -49,7 +49,7 @@ const ListItem = (props: ListItemProps) => { const typographyProps = { className } return ( - + <> {props.avatar && ( {props.avatar} )} @@ -73,7 +73,7 @@ const ListItem = (props: ListItemProps) => { {props.action} )} - + ) } diff --git a/src/core/data-display/list-item/list-item.spec.tsx b/src/core/data-display/list-item/list-item.spec.tsx index f542349a..881fc880 100644 --- a/src/core/data-display/list-item/list-item.spec.tsx +++ b/src/core/data-display/list-item/list-item.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import ListItem from '.' @@ -14,20 +14,28 @@ describe('ListItem', () => { it('should render with avatar', () => { render(Avatar
} />) - const listItem = screen.getByText('Item 1') const avatar = screen.getByText('Avatar') - expect(listItem).toBeDefined() expect(avatar).toBeDefined() }) it('should render with action', () => { render(Action} />) - const listItem = screen.getByText('Item 1') const action = screen.getByText('Action') - expect(listItem).toBeDefined() expect(action).toBeDefined() }) + + it('should match snapshot', () => { + const { container } = render( + Avatar} + action={
Action
} + /> + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/list/__snapshots__/list.spec.tsx.snap b/src/core/data-display/list/__snapshots__/list.spec.tsx.snap new file mode 100644 index 00000000..ce19961d --- /dev/null +++ b/src/core/data-display/list/__snapshots__/list.spec.tsx.snap @@ -0,0 +1,44 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`List should match snapshot 1`] = ` +
+
    + + + +
+
+`; diff --git a/src/core/data-display/list/index.tsx b/src/core/data-display/list/index.tsx index 46fb861c..62ef5789 100644 --- a/src/core/data-display/list/index.tsx +++ b/src/core/data-display/list/index.tsx @@ -8,14 +8,8 @@ import type { DefaultProps } from '../../types' import type { Theme } from '@material-ui/core/styles' export interface ListProps extends DefaultProps { - /** - * The title of the list - */ title?: string dense?: boolean - /** - * The color of the list - */ color?: 'primary' | 'secondary' | 'default' | 'inherit' } diff --git a/src/core/data-display/list/list.spec.tsx b/src/core/data-display/list/list.spec.tsx index aad6ea5a..79f92f6e 100644 --- a/src/core/data-display/list/list.spec.tsx +++ b/src/core/data-display/list/list.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import ListItem from '@/core/data-display/list-item' import List from '.' @@ -27,10 +27,8 @@ describe('List', () => { ) - const list = screen.queryAllByRole('menuitem') const title = screen.queryByText('My beautiful list') - expect(list).toHaveLength(3) expect(title).toBeDefined() }) @@ -47,4 +45,16 @@ describe('List', () => { expect(listContainer.classList).toContain('my-custom-class') }) + + it('should match snapshot', () => { + const { container } = render( + + Item 1 + Item 2 + Item 3 + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/menu-item/__snapshots__/menu-item.spec.tsx.snap b/src/core/data-display/menu-item/__snapshots__/menu-item.spec.tsx.snap new file mode 100644 index 00000000..444e452d --- /dev/null +++ b/src/core/data-display/menu-item/__snapshots__/menu-item.spec.tsx.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MenuItem should match snapshot 1`] = ` +
+ +
+`; diff --git a/src/core/data-display/menu-item/menu-item.spec.tsx b/src/core/data-display/menu-item/menu-item.spec.tsx index c142f095..cd6984e5 100644 --- a/src/core/data-display/menu-item/menu-item.spec.tsx +++ b/src/core/data-display/menu-item/menu-item.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import MenuItem from '.' @@ -10,4 +10,10 @@ describe('MenuItem', () => { expect(menuItem).toBeDefined() }) + + it('should match snapshot', () => { + const { container } = render() + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/node/__snapshots__/node.spec.tsx.snap b/src/core/data-display/node/__snapshots__/node.spec.tsx.snap new file mode 100644 index 00000000..5b109467 --- /dev/null +++ b/src/core/data-display/node/__snapshots__/node.spec.tsx.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Node should match snapshot 1`] = ` +
+
    +
  • + + Branch +
  • +
+
+`; diff --git a/src/core/data-display/node/node.spec.tsx b/src/core/data-display/node/node.spec.tsx index 5a9fdcb5..b8a004e2 100644 --- a/src/core/data-display/node/node.spec.tsx +++ b/src/core/data-display/node/node.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' @@ -38,4 +38,15 @@ describe('Node', () => { expect(node1).toBeDefined() expect(node2).toBeDefined() }) + + it('should match snapshot', () => { + const { container } = render( + + + + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/table/table.spec.tsx b/src/core/data-display/table/table.spec.tsx index 634d968d..3c073a8b 100644 --- a/src/core/data-display/table/table.spec.tsx +++ b/src/core/data-display/table/table.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' @@ -57,6 +57,7 @@ describe('Table', () => { it('should render with sort', async () => { const onSortSpy = jest.fn() + const { getByText } = render() const tableHeadName = getByText('Table-Head-Name') diff --git a/src/core/data-display/tree/__snapshots__/tree.spec.tsx.snap b/src/core/data-display/tree/__snapshots__/tree.spec.tsx.snap new file mode 100644 index 00000000..b09ce6c4 --- /dev/null +++ b/src/core/data-display/tree/__snapshots__/tree.spec.tsx.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Tree should match snapshot 1`] = ` +
+
    +
  • + + root +
  • +
+
+`; diff --git a/src/core/data-display/tree/tree.spec.tsx b/src/core/data-display/tree/tree.spec.tsx index 75187639..f880b109 100644 --- a/src/core/data-display/tree/tree.spec.tsx +++ b/src/core/data-display/tree/tree.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { act } from 'react-dom/test-utils' import { render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' @@ -75,4 +75,10 @@ describe('Tree', () => { expect(leaf.length).toEqual(3) }) + + it('should match snapshot', () => { + const { container } = render() + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/data-display/typography/__snapshots__/typography.spec.tsx.snap b/src/core/data-display/typography/__snapshots__/typography.spec.tsx.snap new file mode 100644 index 00000000..688252ca --- /dev/null +++ b/src/core/data-display/typography/__snapshots__/typography.spec.tsx.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Typography should match snapshot 1`] = ` +
+

+ Some text +

+
+`; diff --git a/src/core/data-display/typography/typography.spec.tsx b/src/core/data-display/typography/typography.spec.tsx index 81a55607..d9c95201 100644 --- a/src/core/data-display/typography/typography.spec.tsx +++ b/src/core/data-display/typography/typography.spec.tsx @@ -1,9 +1,9 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import Typography from '.' describe('Typography', () => { - it('should render with no variant', () => { + it('should render', () => { render(Some text) const typography = screen.getByText('Some text') @@ -12,12 +12,19 @@ describe('Typography', () => { expect(typography.classList).toContain('MuiTypography-body2') }) + it('should render without variant', () => { + render(Some text) + + const typography = screen.getByText('Some text') + + expect(typography.classList).toContain('MuiTypography-body2') + }) + it('should render with variant', () => { render(Title) const typography = screen.getByText('Title') - expect(typography).toBeDefined() expect(typography.classList).toContain('MuiTypography-h1') }) @@ -34,4 +41,14 @@ describe('Typography', () => { expect(typography.style.margin).toBe('10px') expect(typography.style.padding).toBe('5px') }) + + it('should match snapshot', () => { + const { container } = render( + + Some text + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/feedback/collapse/__snapshots__/collapse.spec.tsx.snap b/src/core/feedback/collapse/__snapshots__/collapse.spec.tsx.snap new file mode 100644 index 00000000..758781ea --- /dev/null +++ b/src/core/feedback/collapse/__snapshots__/collapse.spec.tsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Collapse should match snapshot 1`] = ` +
+
+
+
+ I am open for discussions +
+
+
+
+`; diff --git a/src/core/feedback/collapse/collapse.spec.tsx b/src/core/feedback/collapse/collapse.spec.tsx index 89c07341..62c45088 100644 --- a/src/core/feedback/collapse/collapse.spec.tsx +++ b/src/core/feedback/collapse/collapse.spec.tsx @@ -1,4 +1,4 @@ -import * as React from 'react' +import React from 'react' import { render, screen } from '@testing-library/react' import { Collapse } from '.' @@ -28,4 +28,14 @@ describe('Collapse', () => { expect(container.classList).toContain('MuiCollapse-hidden') }) + + it('should match snapshot', () => { + const { container } = render( + + I am open for discussions + + ) + + expect(container).toMatchSnapshot() + }) }) diff --git a/src/core/feedback/dialog/__snapshots__/dialog.spec.tsx.snap b/src/core/feedback/dialog/__snapshots__/dialog.spec.tsx.snap new file mode 100644 index 00000000..4e0fe4a4 --- /dev/null +++ b/src/core/feedback/dialog/__snapshots__/dialog.spec.tsx.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Dialog should match snapshot 1`] = ` +