-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFlyoutToolbarButton.spec.tsx
More file actions
117 lines (95 loc) · 4.27 KB
/
FlyoutToolbarButton.spec.tsx
File metadata and controls
117 lines (95 loc) · 4.27 KB
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
/* (c) Copyright Frontify Ltd., all rights reserved. */
import { IconAdobeCreativeCloud } from '@frontify/fondue/icons';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { DragPreviewContextProvider } from '../context/DragPreviewContext';
import { MultiFlyoutContextProvider } from '../context/MultiFlyoutContext';
import { FlyoutToolbarButton } from './FlyoutToolbarButton';
const BUTTON_ID = 'block-item-wrapper-toolbar-flyout';
const TOOLTIP_ID = 'fondue-tooltip-content';
const TEST_FLYOUT_ID = 'test';
const TEST_TOOLTIP = 'tooltip';
/**
* @vitest-environment happy-dom
*/
describe('FlyoutToolbarButton', () => {
it('should log error if not inside a flyout provider when opening', () => {
vi.spyOn(console, 'error');
const { getByTestId } = render(
<FlyoutToolbarButton
flyoutId={TEST_FLYOUT_ID}
icon={<IconAdobeCreativeCloud />}
tooltip={TEST_TOOLTIP}
content="screen"
/>,
);
fireEvent.click(getByTestId(BUTTON_ID));
expect(console.error).toBeCalled();
});
it('should use flyoutId in flyout context', () => {
const setOpenFlyoutIdsStub = vi.fn();
const { getByTestId } = render(
<MultiFlyoutContextProvider openFlyoutIds={[]} setOpenFlyoutIds={setOpenFlyoutIdsStub}>
<FlyoutToolbarButton
flyoutId={TEST_FLYOUT_ID}
icon={<IconAdobeCreativeCloud />}
tooltip={TEST_TOOLTIP}
content="children"
/>
</MultiFlyoutContextProvider>,
);
fireEvent.click(getByTestId(BUTTON_ID));
expect(setOpenFlyoutIdsStub).toHaveBeenCalled();
const dispatchedStateResult = setOpenFlyoutIdsStub.mock.lastCall?.[0]([]);
expect(dispatchedStateResult).toEqual([TEST_FLYOUT_ID]);
});
it('should display content', () => {
const setOpenFlyoutIdsStub = vi.fn();
const { getByTestId } = render(
<MultiFlyoutContextProvider openFlyoutIds={[TEST_FLYOUT_ID]} setOpenFlyoutIds={setOpenFlyoutIdsStub}>
<FlyoutToolbarButton
flyoutId={TEST_FLYOUT_ID}
icon={<IconAdobeCreativeCloud />}
tooltip={TEST_TOOLTIP}
flyoutFooter={<div data-test-id="footer">Footer</div>}
flyoutHeader={<div data-test-id="header">Header</div>}
content={<div data-test-id="content">Content</div>}
/>
</MultiFlyoutContextProvider>,
);
expect(getByTestId('content')).toBeVisible();
expect(getByTestId('header')).toBeVisible();
expect(getByTestId('footer')).toBeVisible();
});
it('should show tooltip content', async () => {
const setOpenFlyoutIdsStub = vi.fn();
const { getByTestId } = render(
<MultiFlyoutContextProvider openFlyoutIds={[]} setOpenFlyoutIds={setOpenFlyoutIdsStub}>
<FlyoutToolbarButton
flyoutId={TEST_FLYOUT_ID}
icon={<IconAdobeCreativeCloud />}
tooltip={TEST_TOOLTIP}
content="children"
/>
</MultiFlyoutContextProvider>,
);
getByTestId(BUTTON_ID).focus();
await waitFor(() => expect(getByTestId(TOOLTIP_ID)).toBeInTheDocument());
});
it('should disable tooltip and flyout when content is inside drag preview', async () => {
const { getByTestId, queryByTestId } = render(
<MultiFlyoutContextProvider openFlyoutIds={[TEST_FLYOUT_ID]} setOpenFlyoutIds={vi.fn()}>
<DragPreviewContextProvider isDragPreview>
<FlyoutToolbarButton
flyoutId={TEST_FLYOUT_ID}
icon={<IconAdobeCreativeCloud />}
tooltip={TEST_TOOLTIP}
content={<div data-test-id="content">Content</div>}
/>
</DragPreviewContextProvider>
</MultiFlyoutContextProvider>,
);
getByTestId(BUTTON_ID).focus();
await waitFor(() => expect(queryByTestId(TOOLTIP_ID)).toBeNull());
});
});