-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.vitest.tsx
127 lines (96 loc) · 3.87 KB
/
index.vitest.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { vi } from 'vitest';
import { render, fireEvent } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { AppBar, Properties } from '.';
vi.mock('react-router-dom', () => ({
Link: ({ children, onClick, ...props }: any) => (
<a onClick={onClick} {...props}>
{children}
</a>
),
MemoryRouter: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
vi.mock('@zero-tech/zui/icons', () => ({
IconHome: 'IconHome',
IconSlashes: 'IconSlashes',
IconDotsGrid: 'IconDotsGrid',
IconGlobe3: 'IconGlobe3',
IconMessageSquare2: 'IconMessageSquare2',
IconList: 'IconList',
IconBell1: 'IconBell1',
}));
vi.mock('./more-apps-modal', () => ({
MoreAppsModal: () => <div data-testid='more-apps-modal' />,
}));
const mockWorldPanelItem = vi.fn();
vi.mock('./world-panel-item', () => ({
WorldPanelItem: (props: any) => {
mockWorldPanelItem(props);
return <div data-testid='world-panel-item' />;
},
}));
const DEFAULT_PROPS: Properties = {
activeApp: undefined,
hasUnreadNotifications: false,
hasUnreadHighlights: false,
};
const renderComponent = (props: Partial<Properties>) => {
return render(
<MemoryRouter>
<AppBar {...{ ...DEFAULT_PROPS, ...props }} />
</MemoryRouter>
);
};
describe(AppBar, () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('active app', () => {
it('should make conversation icon active when active app is conversation', () => {
renderComponent({ activeApp: 'conversation' });
expect(mockWorldPanelItem).toHaveBeenCalledWith(expect.objectContaining({ label: 'Messenger', isActive: true }));
});
it('should not make conversation icon active when active app is anything else', () => {
renderComponent({ activeApp: 'foo' });
expect(mockWorldPanelItem).toHaveBeenCalledWith(expect.objectContaining({ label: 'Messenger', isActive: false }));
});
});
describe('unhover functionality', () => {
let container: HTMLElement;
it('should add no-hover class when AppLink is clicked', () => {
const { getByText, container: renderedContainer } = renderComponent({});
container = renderedContainer.querySelector('.app-bar__container') as HTMLElement;
const link = getByText('Home');
fireEvent.click(link);
expect(container.classList.contains('no-hover')).toBe(true);
});
it('should remove no-hover class when mouse leaves container', () => {
const { getByText, container: renderedContainer } = renderComponent({});
container = renderedContainer.querySelector('.app-bar__container') as HTMLElement;
const link = getByText('Home');
fireEvent.click(link);
expect(container.classList.contains('no-hover')).toBe(true);
fireEvent.mouseLeave(container);
expect(container.classList.contains('no-hover')).toBe(false);
});
it('should keep no-hover class when mouse moves within container after click', () => {
const { getByText, container: renderedContainer } = renderComponent({});
container = renderedContainer.querySelector('.app-bar__container') as HTMLElement;
const link = getByText('Home');
fireEvent.click(link);
expect(container.classList.contains('no-hover')).toBe(true);
fireEvent.mouseMove(container);
expect(container.classList.contains('no-hover')).toBe(true);
});
it('should allow hover again after mouse leaves and re-enters', () => {
const { getByText, container: renderedContainer } = renderComponent({});
container = renderedContainer.querySelector('.app-bar__container') as HTMLElement;
const link = getByText('Home');
fireEvent.click(link);
fireEvent.mouseLeave(container);
expect(container.classList.contains('no-hover')).toBe(false);
fireEvent.mouseEnter(container);
expect(container.classList.contains('no-hover')).toBe(false);
});
});
});