-
Notifications
You must be signed in to change notification settings - Fork 855
/
Copy pathpanel.js
227 lines (209 loc) · 6.38 KB
/
panel.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { frameworks, url, initSurvey, getQuestionValue, getPanelJson } from "../helper";
import { Selector, ClientFunction, fixture, test } from "testcafe";
// eslint-disable-next-line no-undef
const assert = require("assert");
const title = "panel";
var json = {
pages: [
{
name: "page1",
elements: [
{
type: "comment",
name: "question1",
},
{
type: "panel",
title: "Panel 1",
state: "expanded",
elements: [
{
type: "checkbox",
choices: [
{
value: "1",
text: "first item",
},
{
value: "2",
text: "second item",
},
{
value: "3",
text: "third item",
},
],
name: "question2",
},
{
type: "panel",
elements: [
{
type: "dropdown",
choices: [
{
value: "1",
text: "first item",
},
{
value: "2",
text: "second item",
},
{
value: "3",
text: "third item",
},
],
name: "question3",
},
{
type: "rating",
name: "question4",
},
],
innerIndent: 1,
name: "panel2",
},
],
innerIndent: 1,
name: "panel1",
},
{
type: "panel",
name: "panel2",
state: "collapsed",
elements: [
{ type: "text", name: "q1" }
]
}
],
},
],
};
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, json);
}
);
test("titles and margins", async (t) => {
const getTitle1 = Selector("div").withText("question1").with({
visibilityCheck: true,
timeout: 1000,
});
const getTitle2 = Selector("div").withText("question2").with({
visibilityCheck: true,
timeout: 1000,
});
const getTitle3 = Selector("div").withText("question3").with({
visibilityCheck: true,
timeout: 1000,
});
const getTitle4 = Selector("div").withText("question4").with({
visibilityCheck: true,
timeout: 1000,
});
const getPanelsCountByMargin = ClientFunction(
() => document.querySelectorAll('div[style*="padding-left: 20px"]').length
);
assert(await getTitle1());
assert(await getTitle2());
assert(await getTitle3());
assert(await getTitle4());
assert.equal(await getPanelsCountByMargin(), 2);
});
test("expand collapse title", async (t) => {
const panelTitle = Selector("h4").withText("Panel 1");
const contentItem = Selector("[data-name='question2']");
assert.equal(await contentItem.visible, true);
await t.click(panelTitle);
await t.wait(1000);
assert.equal(await contentItem.visible, false);
});
test("expand collapse title by name", async (t) => {
const panelTitle = Selector("h4").withText("panel2");
const contentItem = Selector("[data-name='q1']");
assert.equal(await contentItem.visible, false);
await t.click(panelTitle);
assert.equal(await contentItem.visible, true);
});
test("panel description reactivity", async (t) => {
await ClientFunction(() => {
window["survey"].getAllPanels()[0].description = "desc1";
})();
await t
.expect(Selector(".sd-panel__description").withText("desc1").visible).ok();
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, json, undefined, true);
}
);
test("click on panel title state editable", async (t) => {
var newTitle = "MyText";
var questionValue = await getQuestionValue();
assert.equal(questionValue, undefined);
var outerSelector = ".sd-panel__title";
var innerSelector = ".sv-string-editor";
await t
.click(outerSelector)
.typeText(outerSelector + " " + innerSelector, newTitle, { replace: true })
.click("body", { offsetX: 0, offsetY: 0 });
questionValue = await getQuestionValue();
assert.equal(questionValue, undefined);
var json = JSON.parse(await getPanelJson());
assert.equal(json.title, newTitle);
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, { elements: [{ type: "text", name: "q1" }] }, undefined, true);
}
);
test("Show content for collapsed panel in designer", async (t) => {
const updateSurvey = ClientFunction(() => {
window.survey.setDesignMode(true);
window.survey.fromJSON({
elements: [
{
"type": "panel",
"name": "panel1",
"elements": [
{
"type": "text",
"name": "question1"
}
],
"state": "collapsed"
}
]
});
});
await t
.expect(Selector("span").withText("question1").visible).notOk();
await updateSurvey();
await t
.expect(Selector("span").withText("question1").visible).ok();
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, { elements: [{ type: "panel", name: "panel", elements: [{ type: "text", name: "q1" }] }] });
}
);
test("Check panel title reactivity", async (t) => {
const setTitle = ClientFunction((title) => {
window.survey.getAllPanels()[0].title = title;
});
const titleSelector = Selector(".sd-panel__title");
await t.expect(titleSelector.exists).notOk();
await setTitle("panel title");
await t.expect(titleSelector.exists).ok().expect(titleSelector.find(".sv-string-viewer").innerText).eql("panel title");
await setTitle("");
await t.expect(titleSelector.exists).notOk();
});
});