diff --git a/packages/mui-joy/src/Chip/Chip.spec.tsx b/packages/mui-joy/src/Chip/Chip.spec.tsx new file mode 100644 index 00000000000000..b4a6e24039f67f --- /dev/null +++ b/packages/mui-joy/src/Chip/Chip.spec.tsx @@ -0,0 +1,34 @@ +import Chip from '@mui/joy/Chip'; +import * as React from 'react'; + +; + +; + +// `variant` +; +; +; +; + +// `color` +; +; +; +; +; +; + +// `size` +; +; +; + +// @ts-expect-error there is no variant `filled` +; + +// @ts-expect-error there is no color `secondary` +; + +// @ts-expect-error there is no size `xl2` +; diff --git a/packages/mui-joy/src/Chip/Chip.test.js b/packages/mui-joy/src/Chip/Chip.test.js new file mode 100644 index 00000000000000..cf7a0819d4921e --- /dev/null +++ b/packages/mui-joy/src/Chip/Chip.test.js @@ -0,0 +1,104 @@ +import * as React from 'react'; +import { expect } from 'chai'; +import { createRenderer, describeConformance } from 'test/utils'; +import { ThemeProvider } from '@mui/joy/styles'; +import Chip, { chipClasses as classes } from '@mui/joy/Chip'; +import { unstable_capitalize as capitalize } from '@mui/utils'; + +describe('', () => { + const { render } = createRenderer(); + + describeConformance(, () => ({ + classes, + inheritComponent: 'div', + render, + ThemeProvider, + muiName: 'MuiChip', + refInstanceof: window.HTMLDivElement, + testDeepOverrides: { slotName: 'label', slotClassName: classes.label }, + testComponentPropWith: 'span', + testVariantProps: { variant: 'light' }, + skip: ['classesRoot', 'componentsProp'], + })); + + describe('prop: variant', () => { + it('light by default', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes.variantLight); + }); + + ['outlined', 'light', 'contained'].forEach((variant) => { + it(`should render ${variant}`, () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes[`variant${capitalize(variant)}`]); + }); + }); + }); + + describe('prop: color', () => { + it('adds a neutral class by default', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes.colorNeutral); + }); + + ['primary', 'success', 'info', 'danger', 'neutral', 'warning'].forEach((color) => { + it(`should render ${color}`, () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes[`color${capitalize(color)}`]); + }); + }); + }); + + describe('prop: size', () => { + it('md by default', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes.sizeMd); + }); + ['sm', 'md', 'lg'].forEach((size) => { + it(`should render ${size}`, () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes[`size${capitalize(size)}`]); + }); + }); + }); + + describe('prop: clickable', () => { + it('renders as a clickable chip when `clickable` is `true`', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes.clickable); + }); + + it('renders as a non-clickable chip when `clickable` is `false`', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).not.to.have.class(classes.clickable); + }); + + it('renders as a clickable chip when `onClick` is passed', () => { + const { getByTestId } = render( {}} />); + + expect(getByTestId('root')).to.have.class(classes.clickable); + }); + }); + + describe('prop: disabled', () => { + it('renders as a disabled chip when `disabled` is `true`', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).to.have.class(classes.disabled); + }); + + it('renders as a non-disabled chip when `disabled` is `false`', () => { + const { getByTestId } = render(); + + expect(getByTestId('root')).not.to.have.class(classes.disabled); + }); + }); +});