-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathshow.js
More file actions
183 lines (161 loc) · 7.84 KB
/
show.js
File metadata and controls
183 lines (161 loc) · 7.84 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import {test, expect} from '../fixtures.js'
test.describe("the show command", () => {
test("can show element, with display:block by default", async ({html, find}) => {
await html("<div style='display:none' _='on click show me'></div>");
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'block');
});
test("can show form, with display:block by default", async ({html, find}) => {
await html("<form style='display:none' _='on click show me'></form>");
await expect(find('form')).toHaveCSS('display', 'none');
await find('form').dispatchEvent('click');
await expect(find('form')).toHaveCSS('display', 'block');
});
test("can show element with display:block explicitly", async ({html, find}) => {
await html("<div style='display:none' _='on click show me with display'></div>");
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'block');
});
test("can show element with custom display value", async ({html, find}) => {
await html("<div style='display:none' _='on click show me with display: flex'></div>");
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'flex');
});
test("can show element with inline-block display value", async ({html, find}) => {
await html("<div style='display:none' _='on click show me with display: inline-block'></div>");
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'inline-block');
});
test("can show element with opacity:1", async ({html, find}) => {
await html("<div style='opacity:0' _='on click show me with opacity'></div>");
await expect(find('div')).toHaveCSS('opacity', '0');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('opacity', '1');
});
test("can show element with opacity style literal", async ({html, find}) => {
await html("<div style='opacity:0' _='on click show me with *opacity'></div>");
await expect(find('div')).toHaveCSS('opacity', '0');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('opacity', '1');
});
test("can show element, with visibility:visible", async ({html, find}) => {
await html("<div style='visibility:hidden' _='on click show me with visibility'></div>");
await expect(find('div')).toHaveCSS('visibility', 'hidden');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('visibility', 'visible');
});
test("can show element via the hidden attribute strategy", async ({html, find}) => {
await html("<div hidden _='on click show me with hidden'></div>");
await expect(find('div')).toHaveAttribute('hidden', '');
await find('div').dispatchEvent('click');
await expect(find('div')).not.toHaveAttribute('hidden', '');
});
test("can show other elements", async ({html, find}) => {
await html("<div style='display:none' class='showme'></div><div _='on click show .showme'></div>");
await expect(find('.showme')).toHaveCSS('display', 'none');
await find('div:nth-of-type(2)').dispatchEvent('click');
await expect(find('.showme')).toHaveCSS('display', 'block');
});
test("can show multiple elements with inline-block display value", async ({html, find}) => {
await html("<div _='on click show <#d1, #d2/> with display: inline-block'></div>" +
"<div style='display: none' id='d1'></div>" +
"<div style='display: none' id='d2'></div>");
await expect(find('#d1')).toBeHidden();
await expect(find('#d2')).toBeHidden();
await find('div').first().dispatchEvent('click');
await expect(find('#d1')).toHaveCSS('display', 'inline-block');
await expect(find('#d2')).toHaveCSS('display', 'inline-block');
});
test("can show multiple elements as class with inline-block display value", async ({html, find}) => {
await html("<div _='on click show .c1 with display:inline-block'></div>" +
"<div style='display: none' id='d1' class='c1'></div>" +
"<div style='display: none' id='d2' class='c1'></div>");
await expect(find('#d1')).toBeHidden();
await expect(find('#d2')).toBeHidden();
await find('div').first().dispatchEvent('click');
await expect(find('#d1')).toHaveCSS('display', 'inline-block');
await expect(find('#d2')).toHaveCSS('display', 'inline-block');
});
test("can use a when clause to show or hide an element", async ({html, find}) => {
await html("<div _='on click " +
" toggle .foo " +
" show when I match .foo'></div>");
await expect(find('div')).not.toHaveClass(/foo/);
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('display', 'block');
await find('div').dispatchEvent('click');
await expect(find('div')).not.toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('display', 'block');
});
test("can use a when clause and a with clause to show or hide an element", async ({html, find}) => {
await html("<div _='on click " +
" toggle .foo " +
" show with opacity when I match .foo'></div>");
await expect(find('div')).not.toHaveClass(/foo/);
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('opacity', '1');
await find('div').dispatchEvent('click');
await expect(find('div')).not.toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('opacity', '0');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveClass(/foo/);
await expect(find('div')).toHaveCSS('opacity', '1');
});
test("can filter over a set of elements using the its symbol", async ({html, find}) => {
await html("<div _='on click show <p/> in me when its innerText contains \"foo\"'>" +
"<p id='p1'>foo</p>" +
"<p id='p2'>bar</p>" +
"<p id='p3'>foo</p>" +
"<p id='p4'>doh</p>" +
"</div>");
await find('div').dispatchEvent('click');
await expect(find('#p1')).toBeVisible();
await expect(find('#p2')).toBeHidden();
await expect(find('#p3')).toBeVisible();
await expect(find('#p4')).toBeHidden();
});
test("the result in a when clause refers to previous command result, not element being tested", async ({html, find}) => {
await html(
"<div _=\"on click " +
" get 'found' " +
" show <span/> in me when the result is 'found'\">" +
"<span id='s1' style='display:none'>A</span>" +
"<span id='s2' style='display:none'>B</span>" +
"</div>"
);
await find('div').dispatchEvent('click');
await expect(find('#s1')).toBeVisible();
await expect(find('#s2')).toBeVisible();
});
test("the result after show...when is the matched elements", async ({html, find}) => {
await html(
"<div _=\"on click " +
" show <p/> in me when its textContent is 'yes' " +
" if the result is empty put 'none' into #out " +
" else put 'some' into #out\">" +
"<p style='display:none'>yes</p>" +
"<p style='display:none'>no</p>" +
"<span id='out'>--</span>" +
"</div>"
);
await find('div').dispatchEvent('click');
await expect(find('#out')).toHaveText("some");
});
test("starting off with display none does not stick", async ({html, find}) => {
await html("<div style='display: none' _='on click toggle .foo show when I match .foo'></div>");
await expect(find('div')).toHaveCSS('display', 'none');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'block');
await find('div').dispatchEvent('click');
await expect(find('div')).toHaveCSS('display', 'none');
});
});