-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
85 lines (79 loc) · 2.54 KB
/
index.test.js
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
const { default: Selection } = require('./dist/selection.min.js');
const bodyContent = `
<div>
<div class="container">
<div id="topArea"><div>
<div class="innerContainer">
<ul>
<li class="listitem">item1</li>
<li class="listitem">item2</li>
</ul>
</div>
</div>
<div id="bottomArea"><div>
</div>`;
const stylesContent = `
#topArea, #bottomArea {
height: 200px;
width: 2200px;
background-color: lightgrey;
}
.container {
height 200px;
background-color: darkgray;
}
.container:hover {
cursor: pointer;
}
ul {
list-style: none;
text-align: center;
}
.listitem {
padding: 10px 0;
border: 2px solid black;
width: 30%;
}
.listitem.active {
background-color: yellow;
}
`;
const createContentAndStyles = () => {
document.body.innerHTML = bodyContent;
const style = document.createElement('style');
style.type = 'text/css';
document.head.appendChild(style);
style.appendChild(document.createTextNode(stylesContent));
}
describe('Mounting & Positioning Tests.', () => {
const $ = v => document.querySelector(v);
createContentAndStyles();
const container = $('.container');
const sel = Selection({
container,
targetSelectors: '.listitem'
});
test('Component mounts and unmounts on DOM properly after mouse click & move.', () => {
const mouseDown = new MouseEvent('mousedown', { which: 1 });
const mouseMove = new MouseEvent("mousemove");
const mouseUp = new MouseEvent("mouseup");
container.dispatchEvent(mouseDown);
container.dispatchEvent(mouseMove);
let selectionEle = $('#selectionRectangle');
expect(selectionEle).not.toBe(null);
container.dispatchEvent(mouseUp);
selectionEle = $('#selectionRectangle');
expect(selectionEle).toBe(null);
});
// TODO: finish tests.
// test('Component has height and width after mouse click and drag.', () => {
// var mouseDown = new MouseEvent('mousedown', { which: 1, clientX: "2px", clientY: "2px" });
// var mouseMove = new MouseEvent("mousemove");
// var mouseUp = new MouseEvent("mouseup");
// });
});
// describe('Component has height and width after mouse click and drag.', () => {});
// describe('In a list, one element was selected properly.', () => {});
// describe('In a list, two adjacent elements were selected properly.', () => {});
// describe('In a list, one of two elements were removed properly.', () => {});
// describe('In a list, two elements were removed after being selected.', () => {});