small fix to make the alert test more readable (#85)

This commit is contained in:
Erik Jan de Wit 2020-09-11 20:34:43 +02:00 committed by GitHub
parent 1297c9f391
commit 55a0f443ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 70 deletions

View file

@ -18,10 +18,12 @@ const WithButton = () => {
); );
}; };
it("renders global alerts", () => { it("renders empty alert panel", () => {
const empty = mount(<AlertPanel alerts={[]} onCloseAlert={() => {}} />); const empty = mount(<AlertPanel alerts={[]} onCloseAlert={() => {}} />);
expect(empty).toMatchSnapshot(); expect(empty).toMatchSnapshot();
});
it("remove alert after timeout", () => {
const tree = mount(<WithButton />); const tree = mount(<WithButton />);
const button = tree.find("button"); const button = tree.find("button");
expect(button).not.toBeNull(); expect(button).not.toBeNull();
@ -29,10 +31,10 @@ it("renders global alerts", () => {
act(() => { act(() => {
button!.simulate("click"); button!.simulate("click");
}); });
expect(tree).toMatchSnapshot(); expect(tree).toMatchSnapshot("with alert");
act(() => { act(() => {
jest.runAllTimers(); jest.runAllTimers();
}); });
expect(tree).toMatchSnapshot(); expect(tree).toMatchSnapshot("cleared alert");
}); });

View file

@ -1,6 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders global alerts 1`] = ` exports[`remove alert after timeout: cleared alert 1`] = `
<WithButton>
<AlertPanel <AlertPanel
alerts={Array []} alerts={Array []}
onCloseAlert={[Function]} onCloseAlert={[Function]}
@ -27,9 +28,27 @@ exports[`renders global alerts 1`] = `
</Portal> </Portal>
</AlertGroup> </AlertGroup>
</AlertPanel> </AlertPanel>
<Button
onClick={[Function]}
>
<button
aria-disabled={false}
aria-label={null}
className="pf-c-button pf-m-primary"
data-ouia-component-id={0}
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={false}
onClick={[Function]}
type="button"
>
Add
</button>
</Button>
</WithButton>
`; `;
exports[`renders global alerts 2`] = ` exports[`remove alert after timeout: with alert 1`] = `
<WithButton> <WithButton>
<AlertPanel <AlertPanel
alerts={Array []} alerts={Array []}
@ -146,8 +165,7 @@ exports[`renders global alerts 2`] = `
</WithButton> </WithButton>
`; `;
exports[`renders global alerts 3`] = ` exports[`renders empty alert panel 1`] = `
<WithButton>
<AlertPanel <AlertPanel
alerts={Array []} alerts={Array []}
onCloseAlert={[Function]} onCloseAlert={[Function]}
@ -174,22 +192,4 @@ exports[`renders global alerts 3`] = `
</Portal> </Portal>
</AlertGroup> </AlertGroup>
</AlertPanel> </AlertPanel>
<Button
onClick={[Function]}
>
<button
aria-disabled={false}
aria-label={null}
className="pf-c-button pf-m-primary"
data-ouia-component-id={0}
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={false}
onClick={[Function]}
type="button"
>
Add
</button>
</Button>
</WithButton>
`; `;