-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathlanguageSelectBox.spec.ts
106 lines (82 loc) · 2.73 KB
/
languageSelectBox.spec.ts
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
import {
LanguageSelectBox,
WRAPPER_CLASS_NAME,
INPUT_CLASS_NANE,
LIST_CLASS_NAME,
} from '@/nodeViews/languageSelectBox';
import { cls } from '@/utils/dom';
import type { Emitter } from '@toast-ui/editor';
Element.prototype.scrollIntoView = jest.fn();
describe('languageSelectBox', () => {
let selectBox: LanguageSelectBox,
eventEmitter: Emitter,
wrapper: HTMLElement,
input: HTMLInputElement,
list: HTMLElement,
wwContainer: HTMLElement;
beforeEach(() => {
eventEmitter = {
emit: jest.fn(),
emitReduce: jest.fn(),
listen: jest.fn(),
removeEventHandler: jest.fn(),
addEventType: jest.fn(),
getEvents: jest.fn(),
holdEventInvoke: jest.fn(),
};
wwContainer = document.createElement('div');
wwContainer.className = 'toastui-editor ww-mode';
document.body.appendChild(wwContainer);
selectBox = new LanguageSelectBox(document.body, eventEmitter, ['js', 'css', 'ts']);
wrapper = document.body.querySelector(`.${cls(WRAPPER_CLASS_NAME)}`)!;
input = document.body.querySelector(`.${cls(INPUT_CLASS_NANE)} > input`)!;
list = document.body.querySelector(`.${cls(LIST_CLASS_NAME)}`)!;
});
afterEach(() => {
selectBox.destroy();
document.body.removeChild(wwContainer);
});
it('should create language select box element', () => {
expect(wrapper).toHaveClass(`${cls(WRAPPER_CLASS_NAME)}`);
});
it('show() should show language select box element', () => {
selectBox.show();
expect(wrapper).not.toHaveStyle('display: none');
});
it('hide() should hide language select box element', () => {
selectBox.show();
selectBox.hide();
expect(wrapper).toHaveStyle('display: none');
});
it('destory() should remove element on body', () => {
selectBox.destroy();
expect(wwContainer).toBeEmptyDOMElement();
expect(eventEmitter.removeEventHandler).toHaveBeenCalled();
});
it('setLanguage() should change input value to selected language', () => {
selectBox.setLanguage('foo');
expect(input).toHaveValue('foo');
});
describe('wrapper element', () => {
it('should change to active state when input is focused', () => {
input.focus();
expect(wrapper).toHaveClass('active');
});
it('should change to inactive state when input is focused out', () => {
input.focus();
input.blur();
expect(wrapper).not.toHaveClass('active');
});
});
describe('language list element', () => {
it('should show when input is focused', () => {
input.focus();
expect(list).toHaveStyle('display: block');
});
it('should hide when input is focused out', () => {
input.focus();
input.blur();
expect(list).toHaveStyle('display: none');
});
});
});