Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests on Dialog #399

Merged
merged 2 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions packages/yoga/src/Dialog/web/Dialog.test.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import renderer from 'react-test-renderer';
import { screen, render, fireEvent } from '@testing-library/react';
import { screen, render, fireEvent, cleanup } from '@testing-library/react';

import { ThemeProvider, Button } from '../..';

import Dialog from '.';

describe('<Dialog />', () => {
jest.useRealTimers();

beforeAll(() => {
ReactDOM.createPortal = jest.fn(element => {
return element;
});
});

afterEach(() => {
ReactDOM.createPortal.mockClear();
});
afterEach(cleanup);

it('should match snapshot', () => {
const container = renderer.create(
const { baseElement } = render(
<ThemeProvider>
<Dialog isOpen>
<Dialog.Header>Title</Dialog.Header>
Expand All @@ -33,11 +21,11 @@ describe('<Dialog />', () => {
</ThemeProvider>,
);

expect(container.toJSON()).toMatchSnapshot();
expect(baseElement).toMatchSnapshot();
});

it('should match snapshot with close button', () => {
const { container } = render(
const { baseElement } = render(
<ThemeProvider>
<Dialog isOpen onClose={jest.fn()}>
<Dialog.Header>Title</Dialog.Header>
Expand All @@ -49,7 +37,7 @@ describe('<Dialog />', () => {
</ThemeProvider>,
);

expect(container).toMatchSnapshot();
expect(baseElement).toMatchSnapshot();
});

it('should render a minimal dialog', () => {
Expand Down
157 changes: 85 additions & 72 deletions packages/yoga/src/Dialog/web/__snapshots__/Dialog.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -144,43 +144,51 @@ exports[`<Dialog /> should match snapshot 1`] = `
background-color: rgba(35,27,34,0.48);
}

<div
className="c0"
onClick={[Function]}
>
<section
className="c1 c2"
<body>
<div />
<div
id="dialog"
>
<header
className="c3"
color="text.primary"
>
Title
</header>
<div
className="c4"
color="text.secondary"
>
Subtitle
</div>
<footer
className="c5"
d="flex"
>
<button
className="c6"
disabled={false}
onClick={[Function]}
<div>
<div
class="c0"
>
Ok, got it
</button>
</footer>
</section>
</div>
<section
class="c1 c2"
>
<header
class="c3"
color="text.primary"
>
Title
</header>
<div
class="c4"
color="text.secondary"
>
Subtitle
</div>
<footer
class="c5"
d="flex"
>
<button
class="c6"
>
Ok, got it
</button>
</footer>
</section>
</div>
</div>
</div>
</body>
`;

exports[`<Dialog /> should match snapshot with close button 1`] = `
.c9 {
<body>
<div />
.c9 {
box-sizing: border-box;
text-align: center;
outline: none;
Expand Down Expand Up @@ -442,50 +450,55 @@ exports[`<Dialog /> should match snapshot with close button 1`] = `
background-color: rgba(35,27,34,0.48);
}

<div>
<div
class="c0"
<div
id="dialog"
>
<section
class="c1 c2"
>
<div>
<div
class="c3"
d="flex"
class="c0"
>
<button
class="c4"
<section
class="c1 c2"
>
<svg
class="c5"
height="24"
width="24"
/>
</button>
<div
class="c3"
d="flex"
>
<button
class="c4"
>
<svg
class="c5"
height="24"
width="24"
/>
</button>
</div>
<header
class="c6"
color="text.primary"
>
Title
</header>
<div
class="c7"
color="text.secondary"
>
Subtitle
</div>
<footer
class="c8"
d="flex"
>
<button
class="c9"
>
Ok, got it
</button>
</footer>
</section>
</div>
<header
class="c6"
color="text.primary"
>
Title
</header>
<div
class="c7"
color="text.secondary"
>
Subtitle
</div>
<footer
class="c8"
d="flex"
>
<button
class="c9"
>
Ok, got it
</button>
</footer>
</section>
</div>
</div>
</div>
</body>
`;