From 4425f7b6abbd77a8567807b24be07c79c3592c21 Mon Sep 17 00:00:00 2001 From: alimpens Date: Fri, 19 Jul 2024 14:56:01 +0200 Subject: [PATCH] Add some missing tests --- packages/react/package.json | 2 +- packages/react/src/FieldSet/FieldSet.test.tsx | 8 ++++++++ packages/react/src/FormErrorList/FormErrorList.test.tsx | 8 ++++++++ packages/react/src/Image/Image.test.tsx | 8 ++++++++ packages/react/src/PageMenu/PageMenu.test.tsx | 8 ++++++++ packages/react/src/Row/Row.test.tsx | 8 ++++++++ packages/react/src/Screen/Screen.test.tsx | 8 ++++++++ 7 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/react/package.json b/packages/react/package.json index 5b1ec31ae6..37bc2d9f2a 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -22,7 +22,7 @@ "build:watch": "rollup -c --watch", "clean": "rimraf dist/", "lint": "tsc --project ./tsconfig.json --noEmit && tsc --noEmit --project ./tsconfig.test.json", - "test": "jest --verbose", + "test": "jest --verbose --coverage", "watch:test": "jest --verbose --watch" }, "main": "./dist/index.cjs.js", diff --git a/packages/react/src/FieldSet/FieldSet.test.tsx b/packages/react/src/FieldSet/FieldSet.test.tsx index 3d59b50c52..9bec6a3fb5 100644 --- a/packages/react/src/FieldSet/FieldSet.test.tsx +++ b/packages/react/src/FieldSet/FieldSet.test.tsx @@ -37,6 +37,14 @@ describe('FieldSet', () => { expect(component).toHaveClass('ams-field-set__legend') }) + it('renders the error class', () => { + const { container } = render(
) + + const component = container.querySelector(':only-child') + + expect(component).toHaveClass('ams-field-set--invalid') + }) + it('supports ForwardRef in React', () => { const ref = createRef() diff --git a/packages/react/src/FormErrorList/FormErrorList.test.tsx b/packages/react/src/FormErrorList/FormErrorList.test.tsx index 1c36564257..ad04ddba20 100644 --- a/packages/react/src/FormErrorList/FormErrorList.test.tsx +++ b/packages/react/src/FormErrorList/FormErrorList.test.tsx @@ -102,6 +102,14 @@ describe('Form error list', () => { describe('renders a custom document title label', () => { const label = { plural: 'errors', singular: 'error' } + it('no errors', async () => { + document.title = docTitle + + render() + + await waitFor(() => expect(document.title).toBe(docTitle)) + }) + it('single error', async () => { document.title = docTitle diff --git a/packages/react/src/Image/Image.test.tsx b/packages/react/src/Image/Image.test.tsx index f199eb3641..dbb18575a1 100644 --- a/packages/react/src/Image/Image.test.tsx +++ b/packages/react/src/Image/Image.test.tsx @@ -30,6 +30,14 @@ describe('Image', () => { expect(component).toHaveClass('ams-image') }) + it('renders a class name to display the image as large as its container', () => { + const { container } = render() + + const component = container.querySelector(':only-child') + + expect(component).toHaveClass('ams-image--cover') + }) + it('supports ForwardRef in React', () => { const ref = createRef() diff --git a/packages/react/src/PageMenu/PageMenu.test.tsx b/packages/react/src/PageMenu/PageMenu.test.tsx index 54012752c8..5f6522a326 100644 --- a/packages/react/src/PageMenu/PageMenu.test.tsx +++ b/packages/react/src/PageMenu/PageMenu.test.tsx @@ -44,6 +44,14 @@ describe('Page menu', () => { expect(component).toHaveClass('ams-page-menu--align-end') }) + it('renders a class name to prevent wrapping', () => { + const { container } = render() + + const component = container.querySelector(':only-child') + + expect(component).toHaveClass('ams-page-menu--no-wrap') + }) + it('is able to pass a React ref', () => { const ref = createRef() diff --git a/packages/react/src/Row/Row.test.tsx b/packages/react/src/Row/Row.test.tsx index 141c78f88a..68120522da 100644 --- a/packages/react/src/Row/Row.test.tsx +++ b/packages/react/src/Row/Row.test.tsx @@ -41,6 +41,14 @@ describe('Row', () => { expect(component).toHaveClass('ams-row extra') }) + it('renders a class name to allow wrapping', () => { + const { container } = render() + + const component = container.querySelector(':only-child') + + expect(component).toHaveClass('ams-row--wrap') + }) + it('renders with an article tag', () => { render() diff --git a/packages/react/src/Screen/Screen.test.tsx b/packages/react/src/Screen/Screen.test.tsx index cc2232e2aa..2ca5ae8831 100644 --- a/packages/react/src/Screen/Screen.test.tsx +++ b/packages/react/src/Screen/Screen.test.tsx @@ -29,6 +29,14 @@ describe('Screen', () => { expect(component).toHaveClass('ams-screen--x-wide') }) + it('renders the full-height class name', () => { + const { container } = render() + + const component = container.querySelector(':only-child') + + expect(component).toHaveClass('ams-screen--full-height') + }) + it('renders an additional class name', () => { const { container } = render()