From af52b18a21074703cb54a3c18e97ccb3c278a6cc Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 28 Aug 2023 10:22:43 -0400 Subject: [PATCH 1/4] chore(Brand): update tests --- .../components/Brand/__tests__/Brand.test.tsx | 50 +++++++++---------- .../__snapshots__/Brand.test.tsx.snap | 11 ---- 2 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 packages/react-core/src/components/Brand/__tests__/__snapshots__/Brand.test.tsx.snap diff --git a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx index 08e4fd1051f..434311ecb05 100644 --- a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx +++ b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx @@ -3,34 +3,30 @@ import { render, screen } from '@testing-library/react'; import { Brand } from '../Brand'; import '@testing-library/jest-dom'; -describe('Brand', () => { - test('simple brand', () => { - const { asFragment } = render(); - expect(asFragment()).toMatchSnapshot(); - }); +test('simple brand', () => { + render(); + expect(screen.getByAltText('brand')).toBeInTheDocument(); +}); - test('passing children creates picture brand', () => { - render( - -
test
-
- ); - expect(screen.getByText('test')).toBeInTheDocument(); - }); +test('passing children creates picture brand', () => { + render( + +
test
+
+ ); + expect(screen.getByText('test')).toBeInTheDocument(); +}); - test('styles get spread when there are children', () => { - render( - -
test width
-
- ); - expect(screen.getByTestId('brand')).toHaveStyle(`color: blue`); - }); +test('styles get spread when there are children', () => { + render( + +
test width
+
+ ); + expect(screen.getByTestId('brand')).toHaveStyle(`color: blue`); +}); - test('styles get spread when there are no children', () => { - render( - - ); - expect(screen.getByAltText('brand no children')).toHaveStyle(`width: 30px`); - }); +test('styles get spread when there are no children', () => { + render(); + expect(screen.getByAltText('brand no children')).toHaveStyle(`width: 30px`); }); diff --git a/packages/react-core/src/components/Brand/__tests__/__snapshots__/Brand.test.tsx.snap b/packages/react-core/src/components/Brand/__tests__/__snapshots__/Brand.test.tsx.snap deleted file mode 100644 index 11d5e553ce6..00000000000 --- a/packages/react-core/src/components/Brand/__tests__/__snapshots__/Brand.test.tsx.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Brand simple brand 1`] = ` - - brand - -`; From 97db9440a2d631b7d36c26626235eea32797575c Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 11 Sep 2023 13:09:37 -0400 Subject: [PATCH 2/4] add more tests --- .../components/Brand/__tests__/Brand.test.tsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx index 434311ecb05..ae38beb225e 100644 --- a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx +++ b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx @@ -8,7 +8,12 @@ test('simple brand', () => { expect(screen.getByAltText('brand')).toBeInTheDocument(); }); -test('passing children creates picture brand', () => { +test('Renders with custom class name when className prop is provided', () => { + render(); + expect(screen.getByAltText('brand')).toHaveClass('custom-class'); +}); + +test('Renders passed children', () => { render(
test
@@ -17,6 +22,26 @@ test('passing children creates picture brand', () => { expect(screen.getByText('test')).toBeInTheDocument(); }); +test('Renders as picture when children are present', () => { + render( + +
test
+
+ ); + expect(screen.getByText('test')?.parentElement?.tagName).toBe('PICTURE'); +}); + +test('Renders as img when no children are present', () => { + render(); + expect(screen.getByAltText('brand')?.tagName).toBe('IMG'); +}); + +test('Renders with passed src prop', () => { + render(); + const image = screen.getByRole('img') as HTMLImageElement; + expect(image.src).toMatch('test.png'); +}); + test('styles get spread when there are children', () => { render( From cec56db15ca7624b21003af78426bb9d8f1c7287 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Thu, 14 Sep 2023 10:36:54 -0400 Subject: [PATCH 3/4] add width test --- .../components/Brand/__tests__/Brand.test.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx index ae38beb225e..1feb23ea115 100644 --- a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx +++ b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx @@ -55,3 +55,23 @@ test('styles get spread when there are no children', () => { render(); expect(screen.getByAltText('brand no children')).toHaveStyle(`width: 30px`); }); + +test('width styles are present when passed', () => { + render( + + ); + expect(screen.getByAltText('brand with widths')).toHaveAttribute( + 'style', + '--pf-v5-c-brand--Width: 100px; --pf-v5-c-brand--Width-on-sm: 25px; --pf-v5-c-brand--Width-on-md: 50px; --pf-v5-c-brand--Width-on-lg: 100px; --pf-v5-c-brand--Width-on-xl: 125px; --pf-v5-c-brand--Width-on-2xl: 150px;' + ); +}); From 4c5609c46a611568f2e11640faf1324536e88e97 Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Tue, 19 Sep 2023 11:20:55 -0400 Subject: [PATCH 4/4] test updates --- .../components/Brand/__tests__/Brand.test.tsx | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx index 1feb23ea115..7ed327f91db 100644 --- a/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx +++ b/packages/react-core/src/components/Brand/__tests__/Brand.test.tsx @@ -13,6 +13,15 @@ test('Renders with custom class name when className prop is provided', () => { expect(screen.getByAltText('brand')).toHaveClass('custom-class'); }); +test('Renders with custom class name when className prop and children are provided', () => { + render( + +
test
+
+ ); + expect(screen.getByText('test')?.parentElement).toHaveClass('custom-class'); +}); + test('Renders passed children', () => { render( @@ -36,12 +45,37 @@ test('Renders as img when no children are present', () => { expect(screen.getByAltText('brand')?.tagName).toBe('IMG'); }); -test('Renders with passed src prop', () => { +test('Has correct src with passed src prop', () => { render(); const image = screen.getByRole('img') as HTMLImageElement; expect(image.src).toMatch('test.png'); }); +test('Has correct alt text with passed alt prop', () => { + render(); + + expect(screen.getByAltText('brand')).toBeTruthy(); +}); + +test('Has correct src with passed children', () => { + render( + +
test width
+
+ ); + const image = screen.getByRole('img') as HTMLImageElement; + expect(image.src).toMatch('test.png'); +}); + +test('Has correct alt text with passed children', () => { + render( + +
test width
+
+ ); + expect(screen.getByAltText('brand')).toBeTruthy(); +}); + test('styles get spread when there are children', () => { render(