-
Notifications
You must be signed in to change notification settings - Fork 857
/
Copy pathimagepicker.js
146 lines (132 loc) · 4.52 KB
/
imagepicker.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
import { ClientFunction, fixture, Selector, test } from "testcafe";
import { frameworks, url, initSurvey, getSurveyResult, getQuestionValue, getQuestionJson, checkSurveyWithEmptyQuestion, urlV2 } from "../helper";
// eslint-disable-next-line no-undef
const assert = require("assert");
const title = "imagepicker";
const json = {
questions: [
{
type: "imagepicker",
name: "choosepicture",
title: "What animal would you like to see first ?",
isRequired: true,
choices: [
{
value: "lion",
imageLink:
"https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
},
{
value: "giraffe",
imageLink:
"https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg"
},
{
value: "panda",
imageLink:
"https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg"
},
{
value: "camel",
imageLink:
"https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg"
}
]
}
]
};
frameworks.forEach(framework => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async t => {
await initSurvey(framework, json);
}
);
test("check integrity", async t => {
await t
.hover("fieldset.sd-imagepicker .sd-imagepicker__item:nth-of-type(1)")
.hover("fieldset.sd-imagepicker .sd-imagepicker__item:nth-of-type(2)")
.hover("fieldset.sd-imagepicker .sd-imagepicker__item:nth-of-type(3)")
.hover("fieldset.sd-imagepicker .sd-imagepicker__item:nth-of-type(4)");
});
test("choose empty", async t => {
await checkSurveyWithEmptyQuestion(t);
});
test("choose value", async t => {
let surveyResult;
await t
.click("fieldset.sd-imagepicker .sd-imagepicker__item:nth-of-type(2)")
.click("input[value=Complete]");
surveyResult = await getSurveyResult();
assert.equal(surveyResult.choosepicture, "giraffe");
});
test("imagelink reactiveness", async t => {
await t.expect(Selector(".sd-imagepicker__item").nth(0).find("img").exists).ok();
await t.expect(Selector(".sd-imagepicker__no-image").exists).notOk();
await ClientFunction(()=>{
window.survey.getAllQuestions()[0].choices[0].imageLink = "custom_link";
})();
await t.expect(Selector(".sd-imagepicker__item").nth(0).find("img").exists).notOk();
await t.expect(Selector(".sd-imagepicker__no-image").exists).ok();
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
async (t) => {
await initSurvey(framework, json, undefined, true);
}
);
test("click on question title state editable", async (t) => {
var newTitle = "MyText";
var json = JSON.parse(await getQuestionJson());
var questionValue = await getQuestionValue();
assert.equal(questionValue, undefined);
var outerSelector = ".sd-question__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);
json = JSON.parse(await getQuestionJson());
assert.equal(json.title, newTitle);
});
});
frameworks.forEach((framework) => {
fixture`${framework} ${title}`.page`${urlV2}${framework}`.beforeEach(
async (ctx) => {
const json = {
questions: [
{
"type": "imagepicker",
"name": "imagepicker",
"titleLocation": "hidden",
"choices": [
{
"value": "lion",
"imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg",
"text": "Lion"
},
{
"value": "giraffe",
"imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg",
"text": "Giraffe"
}
],
"readOnly": true,
"defaultValue": "lion"
}
]
};
await initSurvey(framework, json);
}
);
test("readonly:keyboard disabled", async (t) => {
await t.pressKey("tab").pressKey("right");
const getValue = ClientFunction(()=>{
return window["survey"].getAllQuestions()[0].value;
});
const value = await getValue();
await t.expect(value).eql("lion", "value doesn't change");
});
});