-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathquerystring.test.js
More file actions
164 lines (155 loc) · 7.06 KB
/
Copy pathquerystring.test.js
File metadata and controls
164 lines (155 loc) · 7.06 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
import "./querystring";
import registry from "@patternslib/patternslib/src/core/registry";
import utils from "@patternslib/patternslib/src/core/utils";
const mockFetch = global.mockFetch;
describe("Querystring", function () {
beforeEach(() => {
document.body.innerHTML = `
<div id="formfield-query"><input class="pat-querystring text-widget list-field"
type="text" name="form.widgets.ICollection.query"
style="display: none;"
value='[
{
"i": "portal_type",
"o": "plone.app.querystring.operation.selection.any",
"v": [
"Event"
]
},
{
"i": "review_state",
"o": "plone.app.querystring.operation.selection.any",
"v": [
"published"
]
}
]'
data-pat-querystring='{
"indexOptionsUrl": "http://localhost:8080/Plone/@@qsOptions",
"previewURL": "http://localhost:8080/Plone/news/aggregator/@@querybuilder_html_results",
"previewCountURL": "http://localhost:8080/Plone/news/aggregator/@@querybuildernumberofresults",
"patternDateOptions": {
"time": false,
"date": {
"firstDay": 1,
"weekdaysFull": [
"Sonntag",
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag"
],
"weekdaysShort": [
"So",
"Mo",
"Di",
"Mi",
"Do",
"Fr",
"Sa"
],
"monthsFull": [
"Januar",
"Februar",
"M\u00e4rz",
"April",
"Mai",
"Juni",
"Juli",
"August",
"September",
"Oktober",
"November",
"Dezember"
],
"monthsShort": [
"Jan",
"Feb",
"Mrz",
"Apr",
"Mai",
"Jun",
"Jul",
"Aug",
"Sep",
"Okt",
"Nov",
"Dez"
],
"selectYears": 200,
"min": [
1921,
1,
1
],
"max": [
2041,
1,
1
],
"format": "d mmmm, yyyy",
"placeholder": "Datum eingeben\u2026"
},
"today": "Heute",
"clear": "Auswahl aufheben"
},
"patternAjaxSelectOptions": {
"separator": ";"
},
"patternRelateditemsOptions": {
"separator": ";",
"vocabularyUrl": "http://localhost:8080/Plone/@@getVocabulary?name=plone.app.vocabularies.Catalog&field=relatedItems",
"basePath": "/Plone/news",
"rootPath": "/Plone",
"rootUrl": "http://localhost:8080/Plone",
"contextPath": "/Plone/news/aggregator",
"favorites": [
{
"title": "Current Content",
"path": "/Plone/news"
},
{
"title": "Start Page",
"path": "/Plone"
}
]
}
}'></div>
<div id="formfield-sort_on">
<input id="form-widgets-sort_on" value="start" type="text">
</div>
<div id="formfield-sort_reversed">
<input id="form-widgets-sort_reversed-0" type="checkbox" checked="checked">
</div>
`;
});
afterEach(() => {
document.body.innerHTML = "";
});
it("create querystring pattern", async function () {
expect(document.querySelectorAll(".querystring-wrapper").length).toEqual(0);
const criterias = await import("./test-querystringcriteria.json");
global.fetch = jest.fn().mockImplementation(mockFetch(criterias));
registry.scan(document.body);
await utils.timeout(1);
// querystring pattern initialized
expect(document.querySelectorAll(".querystring-wrapper").length).toEqual(1);
expect(document.querySelectorAll(".querystring-sort-wrapper").length).toEqual(1);
expect(document.querySelectorAll(".querystring-preview-wrapper").length).toEqual(
1
);
// there should be 3 criteria rows now
expect(
document.querySelectorAll(".querystring-criteria-wrapper").length
).toEqual(3);
// check for correct initialized values
expect(document.querySelector(".querystring-sort-wrapper select").value).toEqual("start");
expect(
document.querySelectorAll(".querystring-sort-wrapper .querystring-sortreverse input[type='checkbox']")[0].checked
).toBeTruthy();
global.fetch.mockClear();
delete global.fetch;
});
});