-
Notifications
You must be signed in to change notification settings - Fork 856
/
Copy pathcomment.ts
227 lines (198 loc) · 7.04 KB
/
comment.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
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, setOptions, initSurvey, getSurveyResult, getQuestionValue, getQuestionJson } from "../helper";
import { ClientFunction, Selector } from "testcafe";
const title = "comment";
const commentQuestion = Selector(".sd-question textarea");
const json = {
questions: [
{
type: "comment",
name: "suggestions",
title: "What would make you more satisfied with the Product?"
}
]
};
frameworks.forEach(framework => {
fixture`${framework} ${title}`.page`${url}${framework}`;
test("autoGrowComment & acceptCarriageReturn", async t => {
await initSurvey(framework, {
"autoGrowComment": true,
"allowResizeComment": false,
"pages": [
{
"name": "page1",
"elements": [
{
"type": "comment",
"name": "question1",
},
{
"type": "radiogroup",
"name": "question2",
"hasComment": true,
"commentText": "Comment text"
},
{
"type": "comment",
"name": "question3",
"acceptCarriageReturn": false
},
]
}
],
});
await t
.click(commentQuestion)
.expect(commentQuestion.getStyleProperty("resize")).eql("none")
.expect(commentQuestion.clientHeight).eql(120)
.pressKey("a enter a enter a enter a enter")
.expect(commentQuestion.clientHeight).eql(144)
.pressKey("backspace")
.expect(commentQuestion.clientHeight).eql(120)
.pressKey("tab")
.expect(commentQuestion.nth(1).getStyleProperty("resize")).eql("none")
.expect(commentQuestion.nth(1).clientHeight).eql(72)
.pressKey("a enter a enter")
.expect(commentQuestion.nth(1).clientHeight).eql(96)
.pressKey("backspace")
.expect(commentQuestion.nth(1).clientHeight).eql(72)
.pressKey("tab")
.expect(commentQuestion.nth(2).getStyleProperty("resize")).eql("none")
.expect(commentQuestion.nth(2).clientHeight).eql(120)
.pressKey("a enter a enter a enter a enter")
.expect(commentQuestion.nth(2).clientHeight).eql(120)
.expect(commentQuestion.nth(2).value).eql("aaaa")
.typeText(commentQuestion.nth(2), "a\na\na\na\n", { replace: true })
.pressKey("tab")
.expect(commentQuestion.nth(2).value).eql("aaaa");
});
test("autoGrowComment after survey data set", async t => {
await t.resizeWindow(1280, 900);
await initSurvey(framework, {
"elements": [
{
"type": "comment",
"name": "question1",
"autoGrow": true,
"rows": 1
}
]
});
await t.expect(commentQuestion.clientHeight).eql(48);
await ClientFunction(() =>
window["survey"].data = { "question1": "<h3>Thank you for your feedback.</h3> <h5> We are glad that you share with us your ideas.We highly value all suggestions from our customers. We do our best to improve the product and reach your expectation.</h5><br/>" }
)();
await t.expect(commentQuestion.clientHeight).eql(120);
});
test("autoGrow with default value", async (t) => {
await t.resizeWindow(1280, 900);
await initSurvey(framework, {
"showQuestionNumbers": "off",
"widthMode": "static",
"width": "500px",
questions: [
{
name: "name",
type: "comment",
titleLocation: "hidden",
defaultValue: "The comment area has an initial height of two rows and automatically expands or shrinks to accomodate the content.",
autoGrow: true,
allowResize: false,
rows: 1
}
]
});
await t
.expect(commentQuestion.value).eql("The comment area has an initial height of two rows and automatically expands or shrinks to accomodate the content.")
.expect(commentQuestion.clientHeight).eql(96);
});
test("fill textarea", async t => {
await initSurvey(framework, json);
await t
.typeText(commentQuestion, "puppies")
.pressKey("enter")
.typeText(commentQuestion, "money")
.click("input[value=Complete]");
await t.expect(await getSurveyResult()).eql({ suggestions: "puppies\nmoney" });
});
test("change rows count", async t => {
await initSurvey(framework, json);
await t.expect(Selector("textarea[rows=\"4\"]").visible).ok();
await setOptions("suggestions", { rows: 2 });
await t.expect(Selector("textarea[rows=\"2\"]").visible).ok();
});
test("click on question title state editable", async (t) => {
const newTitle = "MyText";
const outerSelector = ".sd-question__title";
const innerSelector = ".sv-string-editor";
await initSurvey(framework, json, undefined, true);
await t
.expect(await getQuestionValue()).eql(undefined)
.click(outerSelector)
.typeText(outerSelector + " " + innerSelector, newTitle, { replace: true })
.click("body", { offsetX: 0, offsetY: 0 });
await t.expect(await getQuestionValue()).eql(undefined);
const questionJson = JSON.parse(await getQuestionJson());
await t.expect(questionJson.title).eql(newTitle);
});
test("Remaining character counter", async (t) => {
const characterCounter = Selector(".sd-remaining-character-counter");
await initSurvey(framework, {
focusFirstQuestionAutomatic: true,
questions: [
{
name: "comment",
type: "comment",
maxLength: 10,
}]
});
await t
.expect(characterCounter.textContent).eql("0/10")
.pressKey("A")
.expect(characterCounter.textContent).eql("1/10")
.typeText("textarea", "bcd")
.expect(characterCounter.textContent).eql("4/10")
.pressKey("backspace")
.pressKey("backspace")
.expect(characterCounter.textContent).eql("2/10")
.pressKey("backspace")
.pressKey("backspace")
.expect(characterCounter.textContent).eql("0/10");
});
});
const json2 = {
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "boolean",
"name": "question3"
},
{
"type": "text",
"name": "question1"
},
{
"type": "comment",
"name": "question2",
"visibleIf": "{question3} = true",
"setValueExpression": "{question1}"
}
]
}
]
};
frameworks.forEach(framework => {
fixture`${framework} ${title}`.page`${url}${framework}`;
test("Bug: 8921 - check long text reactivity when change visible property", async t => {
await initSurvey(framework, json2);
await t
.click(Selector("span").withText("Yes"))
.click(Selector("span").withText("No"))
.click(Selector("span").withText("Yes"))
.typeText(Selector("input[type='text']"), "test")
.pressKey("tab")
.expect(Selector("textarea").value).eql("test");
});
});