-
Notifications
You must be signed in to change notification settings - Fork 51.2k
Expand file tree
/
Copy pathComponentSettings-test.js
More file actions
102 lines (71 loc) · 2.98 KB
/
Copy pathComponentSettings-test.js
File metadata and controls
102 lines (71 loc) · 2.98 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
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import ComponentsSettings from '../devtools/views/Settings/ComponentsSettings';
describe('ComponentsSettings', () => {
let container;
beforeEach(() => {
// Set up a DOM element as a render target
container = document.createElement('div');
document.body.appendChild(container);
});
afterEach(() => {
// Clean up on exiting
unmountComponentAtNode(container);
container.remove();
container = null;
});
// @reactVersion >= 17
it('should update collapseNodesByDefault setting', () => {
const useContextMock = jest.fn().mockReturnValue({
collapseNodesByDefault: true,
addListener: jest.fn(),
removeListener: jest.fn(),
});
render(<ComponentsSettings />, container);
const toggleElement = container.querySelector('.Settings input[type="checkbox"]');
expect(toggleElement.checked).toBe(true);
toggleElement.click();
expect(useContextMock().collapseNodesByDefault).toBe(false);
});
it('should update parseHookNames setting', () => {
const setParseHookNamesMock = jest.fn();
const useContextMock = jest.fn().mockReturnValue({
parseHookNames: true,
setParseHookNames: setParseHookNamesMock,
});
render(<ComponentsSettings />, container);
const toggleElement = container.querySelector('.Settings input[type="checkbox"]');
expect(toggleElement.checked).toBe(true);
toggleElement.click();
expect(setParseHookNamesMock).toHaveBeenCalledWith(false);
});
it('should update openInEditorURLPreset setting', () => {
const setLocalStorageMock = jest.spyOn(Storage.prototype, 'setItem');
const useContextMock = jest.fn().mockReturnValue({
openInEditorURLPreset: 'custom',
setOpenInEditorURLPreset: jest.fn(),
});
render(<ComponentsSettings />, container);
const selectElement = container.querySelector('.Settings select');
expect(selectElement.value).toBe('custom');
selectElement.value = 'vscode';
selectElement.dispatchEvent(new Event('change'));
expect(setLocalStorageMock).toHaveBeenCalledWith('OPEN_IN_EDITOR_URL_PRESET', 'vscode');
});
it('should update openInEditorURL setting', () => {
const setLocalStorageMock = jest.spyOn(Storage.prototype, 'setItem');
const useContextMock = jest.fn().mockReturnValue({
openInEditorURLPreset: 'custom',
setOpenInEditorURL: jest.fn(),
});
render(<ComponentsSettings />, container);
const selectElement = container.querySelector('.Settings select');
const inputElement = container.querySelector('.Settings input[type="text"]');
selectElement.value = 'custom';
selectElement.dispatchEvent(new Event('change'));
inputElement.value = 'https://example.com';
inputElement.dispatchEvent(new Event('change'));
expect(setLocalStorageMock).toHaveBeenCalledWith('OPEN_IN_EDITOR_URL', 'https://example.com');
});
// Add additional test cases for other functionality...
});