forked from riccardo-forina/use-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppLayout.test.tsx
71 lines (65 loc) · 2.16 KB
/
AppLayout.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as React from 'react';
import { render, fireEvent } from '@test/setup';
import { AppLayout, IAppLayoutProps } from '.';
function makeAppLayout(
props: Partial<React.PropsWithChildren<IAppLayoutProps>> = {}
) {
props = Object.assign(
{
logo: <div>App logo</div>,
avatar: <div>Avatar</div>,
toolbar: <div>Toolbar</div>,
navVariant: 'vertical',
navItems: [
{
title: 'Samples',
to: '/samples/',
items: [
{ to: '/samples/foo', title: 'Foo' },
undefined,
{ to: '/samples/bar', title: 'Bar' },
{ to: '/samples/baz', title: 'Baz' },
],
},
{ to: '/support', title: 'Support' },
{ to: '/something', title: 'Something' },
],
navGroupsStyle: 'expandable',
startWithOpenNav: true,
theme: 'dark',
children: <div data-testid={'test-content'}>test</div>,
},
props
);
return <AppLayout {...(props as IAppLayoutProps)} />;
}
function renderAppLayout(...args: Parameters<typeof makeAppLayout>) {
return render(makeAppLayout(...args));
}
describe('AppLayout tests', () => {
test('should render as configured', async () => {
const { getByTestId, getByText } = renderAppLayout();
getByTestId('test-content');
getByText('App logo');
getByText('Avatar');
getByText('Toolbar');
getByTestId('app-sidebar');
});
it('should render a nav-toggle button', async () => {
const { getByLabelText } = renderAppLayout();
getByLabelText('Global navigation');
});
it('should hide the sidebar when clicking the nav-toggle button', async () => {
const { getByLabelText, getByTestId } = renderAppLayout();
const navButton = getByLabelText('Global navigation');
const sidebar = getByTestId('app-sidebar');
expect(sidebar).toHaveClass('pf-m-expanded');
fireEvent.click(navButton);
expect(sidebar).toHaveClass('pf-m-collapsed');
});
it('should start with an hidden sidebar', async () => {
const { getByTestId } = renderAppLayout({ startWithOpenNav: false });
const sidebar = getByTestId('app-sidebar');
expect(sidebar).toHaveClass('pf-m-collapsed');
});
});