@luomus/laji-form 15.1.1 → 15.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/laji-form.js +1 -1
  2. package/dist/styles.css +90 -81
  3. package/package.json +3 -3
  4. package/test-export/test-utils.d.ts +194 -121
  5. package/test-export/test-utils.js +221 -207
  6. package/tsconfig.test.json +1 -1
  7. package/test-export/array-spec.d.ts +0 -1
  8. package/test-export/array-spec.js +0 -204
  9. package/test-export/bird-point-count-spec.d.ts +0 -1
  10. package/test-export/bird-point-count-spec.js +0 -62
  11. package/test-export/collection-contest-form-spec.d.ts +0 -1
  12. package/test-export/collection-contest-form-spec.js +0 -38
  13. package/test-export/dataset-form-spec.d.ts +0 -1
  14. package/test-export/dataset-form-spec.js +0 -50
  15. package/test-export/date-time-widget-spec.d.ts +0 -1
  16. package/test-export/date-time-widget-spec.js +0 -188
  17. package/test-export/geocoder-spec.d.ts +0 -1
  18. package/test-export/geocoder-spec.js +0 -135
  19. package/test-export/image-array-spec.d.ts +0 -1
  20. package/test-export/image-array-spec.js +0 -94
  21. package/test-export/inject-field-spec.d.ts +0 -1
  22. package/test-export/inject-field-spec.js +0 -148
  23. package/test-export/internal-uuids-spec.d.ts +0 -1
  24. package/test-export/internal-uuids-spec.js +0 -157
  25. package/test-export/invasive-species-eradication-np-spec.d.ts +0 -1
  26. package/test-export/invasive-species-eradication-np-spec.js +0 -18
  27. package/test-export/invasive-species-eradication-spec.d.ts +0 -1
  28. package/test-export/invasive-species-eradication-spec.js +0 -25
  29. package/test-export/line-transect-spec.d.ts +0 -1
  30. package/test-export/line-transect-spec.js +0 -121
  31. package/test-export/mobile-form-spec.d.ts +0 -1
  32. package/test-export/mobile-form-spec.js +0 -84
  33. package/test-export/nafi-spec.d.ts +0 -1
  34. package/test-export/nafi-spec.js +0 -85
  35. package/test-export/select-widget-spec.d.ts +0 -1
  36. package/test-export/select-widget-spec.js +0 -68
  37. package/test-export/single-item-array-field-spec.d.ts +0 -1
  38. package/test-export/single-item-array-field-spec.js +0 -92
  39. package/test-export/syke-butterfly-spec.d.ts +0 -1
  40. package/test-export/syke-butterfly-spec.js +0 -163
  41. package/test-export/transaction-form-spec.d.ts +0 -1
  42. package/test-export/transaction-form-spec.js +0 -63
  43. package/test-export/trip-report-autosuggest-spec.d.ts +0 -1
  44. package/test-export/trip-report-autosuggest-spec.js +0 -272
  45. package/test-export/trip-report-spec.d.ts +0 -1
  46. package/test-export/trip-report-spec.js +0 -456
  47. package/test-export/unit-list-shorthand-array-field-spec.d.ts +0 -1
  48. package/test-export/unit-list-shorthand-array-field-spec.js +0 -71
  49. package/test-export/validation-spec.d.ts +0 -1
  50. package/test-export/validation-spec.js +0 -336
  51. package/test-export/water-bird-spec.d.ts +0 -1
  52. package/test-export/water-bird-spec.js +0 -30
  53. package/test-export/wbc-spec.d.ts +0 -1
  54. package/test-export/wbc-spec.js +0 -82
@@ -20,180 +20,149 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.maybeJSONPointerToLocator = exports.filterUUIDs = exports.mockImageMetadata = exports.updateValue = exports.removeUnit = exports.putForeignMarkerToMap = exports.waitUntilBlockingLoaderHides = exports.createForm = exports.NamedPlaceChooserPO = exports.isDisplayed = exports.Form = exports.getFocusedId = exports.getFocusedElement = exports.lajiFormLocate = exports.lajiFormLocator = exports.navigateToForm = exports.emptyForm = exports.getLocatorForContextId = exports.EC = void 0;
24
- const protractor_1 = require("protractor");
23
+ exports.getRemoveUnit = exports.updateValue = exports.maybeJSONPointerToLocator = exports.filterUUIDs = exports.mockImageMetadata = exports.createForm = exports.DemoPageForm = exports.Form = exports.getFocusedId = exports.getFocusedElement = exports.lajiFormLocate = exports.lajiFormLocator = exports.navigateToForm = exports.emptyForm = void 0;
25
24
  const path = require("path");
26
- const { HOST, PORT } = process.env;
27
- exports.EC = protractor_1.protractor.ExpectedConditions;
28
- const getLocatorForContextId = (contextId) => (path) => `#_laji-form_${contextId}_root${typeof path === "string" && path.length ? `_${path.replace(/\./g, "_")}` : ""}`;
29
- exports.getLocatorForContextId = getLocatorForContextId;
30
- const emptyForm = (params = "") => __awaiter(void 0, void 0, void 0, function* () { return protractor_1.browser.get(`http://${HOST}:${PORT}?test=true&settings=false&mockApi=true&${params}`); });
25
+ const test_utils_1 = require("@luomus/laji-map/test-export/test-utils");
26
+ const emptyForm = (page, params = "") => __awaiter(void 0, void 0, void 0, function* () { return page.goto(`/?test=true&settings=false&mockApi=true&${params}`); });
31
27
  exports.emptyForm = emptyForm;
32
- const navigateToForm = (formID, params = "") => __awaiter(void 0, void 0, void 0, function* () { return protractor_1.browser.get(`http://${HOST}:${PORT}?id=${formID}&local=true&settings=false&mockApi=true${params}`); });
28
+ const navigateToForm = (page, formID, params = "") => __awaiter(void 0, void 0, void 0, function* () { return page.goto(`/?id=${formID}&local=true&settings=false&mockApi=true${params}`); });
33
29
  exports.navigateToForm = navigateToForm;
34
- exports.lajiFormLocator = exports.getLocatorForContextId(0);
35
- const lajiFormLocate = (str) => protractor_1.$(exports.lajiFormLocator(str));
30
+ const lajiFormLocator = (path) => `#_laji-form_root${typeof path === "string" && path.length ? `_${path.replace(/\./g, "_")}` : ""}`;
31
+ exports.lajiFormLocator = lajiFormLocator;
32
+ const lajiFormLocate = (page, str) => page.locator(exports.lajiFormLocator(str));
36
33
  exports.lajiFormLocate = lajiFormLocate;
37
- const getFocusedElement = () => protractor_1.browser.driver.switchTo().activeElement();
34
+ const getFocusedElement = (page) => page.locator("*:focus");
38
35
  exports.getFocusedElement = getFocusedElement;
39
- const getFocusedId = () => exports.getFocusedElement().getAttribute("id");
36
+ const getFocusedId = (page) => exports.getFocusedElement(page).getAttribute("id");
40
37
  exports.getFocusedId = getFocusedId;
41
38
  function getEnumWidgetForContainer($container) {
42
39
  return {
43
40
  $container,
44
- openEnums: () => __awaiter(this, void 0, void 0, function* () {
45
- yield $container.click();
46
- yield protractor_1.browser.wait(protractor_1.protractor.ExpectedConditions.visibilityOf($container.$$(".rw-list-option").first()), 300, "select list timeout");
47
- }),
48
- $enumContainer: $container.$(".rw-popup-container"),
49
- $$enums: $container.$$(".rw-list-option"),
50
- $input: $container.$("input")
41
+ openEnums: () => $container.click(),
42
+ $enumContainer: $container.locator(".rw-popup-container"),
43
+ $$enums: $container.locator(".rw-list-option"),
44
+ $input: $container.locator("input")
51
45
  };
52
46
  }
53
47
  class Form {
54
- constructor(params = {}) {
55
- this.$form = protractor_1.$(".laji-form .rjsf");
48
+ constructor(page, locator = page.locator(".laji-form")) {
49
+ this.page = page;
50
+ this.locator = locator;
51
+ this.$form = this.page.locator(".laji-form .rjsf");
56
52
  this.getMockStr = (path, query) => `window.mockResponses[window.getMockQueryKey(${JSON.stringify(path)}, ${JSON.stringify(query)})]`;
57
53
  this.createValidatorPO = (type) => ({
58
- $$all: protractor_1.$$(`.laji-form-error-list:not(.laji-form-failed-jobs-list) .${type}-panel .list-group button`),
59
- $panel: protractor_1.$(`.laji-form-error-list:not(.laji-form-failed-jobs-list) .${type}-panel`)
54
+ $$all: this.page.locator(`.laji-form-error-list:not(.laji-form-failed-jobs-list) .${type}-panel .list-group button`),
55
+ $panel: this.page.locator(`.laji-form-error-list:not(.laji-form-failed-jobs-list) .${type}-panel`)
60
56
  });
61
57
  this.errors = this.createValidatorPO("error");
62
58
  this.warnings = this.createValidatorPO("warning");
63
59
  this.failedJobs = {
64
- $container: protractor_1.$(".laji-form-failed-jobs-list")
60
+ $container: this.page.locator(".laji-form-failed-jobs-list"),
61
+ $$errors: this.page.locator(".laji-form-failed-jobs-list .list-group-item")
65
62
  };
66
- this.$acknowledgeWarnings = protractor_1.$(".laji-form-warning-list .panel-footer button");
67
- this.isBlocked = () => protractor_1.$(".laji-form.blocking-loader").isDisplayed();
68
- this.mockImageUpload = (lajiFormLocator) => __awaiter(this, void 0, void 0, function* () {
69
- const filePath = path.resolve(__dirname, "./pixel.png");
70
- const imageResponse = [{ name: "data", filename: "pixel.png", id: "mock", expires: 1575979685 }];
71
- const { resolve, remove } = yield this.setMockResponse("/images", false);
72
- const mdResponse = exports.mockImageMetadata;
73
- const { resolve: mdResolve, remove: mdRemove } = yield this.setMockResponse("/images/mock", false);
74
- yield this.getImageArrayField(lajiFormLocator).$dropzone.$("input").sendKeys(filePath);
63
+ this.$runningJobs = this.page.locator(".running-jobs");
64
+ this.$acknowledgeWarnings = this.page.locator(".laji-form-warning-list .panel-footer button");
65
+ this.$blocker = this.page.locator(".laji-form.blocking-loader");
66
+ this.$mapFieldFullscreenMap = this.page.locator(".laji-form.fullscreen .laji-form-map");
67
+ this.getImageArrayField = (lajiFormLocator) => {
68
+ const $container = this.$locate(lajiFormLocator).locator(".laji-form-medias");
69
+ const $imgContainers = this.$locate(lajiFormLocator).locator(".media-container");
70
+ const $modal = this.page.locator(".laji-form.media-modal");
71
+ const $addModal = this.page.locator(".laji-form.media-add-modal");
75
72
  return {
76
- resolve: () => __awaiter(this, void 0, void 0, function* () {
77
- yield resolve(imageResponse);
78
- yield protractor_1.browser.sleep(300);
79
- yield mdResolve(mdResponse);
80
- }),
81
- remove: () => __awaiter(this, void 0, void 0, function* () {
82
- yield remove();
83
- yield mdRemove();
84
- })
73
+ $container,
74
+ $imgContainers,
75
+ $$imgs: $imgContainers.locator("img"),
76
+ $$imgLoading: $imgContainers.locator(".react-spinner"),
77
+ $$imgRemoves: $imgContainers.locator(".button-corner"),
78
+ $imgRemoveConfirmButton: (id) => this.$locateAddition(id, "delete-confirm-yes", true),
79
+ $dropzone: this.$locate(lajiFormLocator).locator(".laji-form-drop-zone"),
80
+ $modal,
81
+ $addModal,
82
+ $modalClose: $modal.locator(".modal-header .close"),
83
+ $addModalCancel: $addModal.locator(".cancel")
85
84
  };
86
- });
87
- this._getImageArrayField = (form) => (lajiFormLocator) => new class ImageArrayFieldPO {
88
- constructor() {
89
- this.$container = form.$locate(lajiFormLocator).$(".laji-form-medias");
90
- this.$$imgs = form.$locate(lajiFormLocator).$$(".media-container");
91
- this.$$imgInteractives = this.$$imgs.$$(".media-container a");
92
- this.$$imgRemoves = this.$$imgs.$$(".button-corner");
93
- this.$imgRemoveConfirmButton = (id) => form.$locateAddition(id, "delete-confirm-yes");
94
- this.$dropzone = form.$locate(lajiFormLocator).$(".laji-form-drop-zone");
95
- this.$modal = protractor_1.$(".laji-form.media-modal");
96
- this.$modalClose = this.$modal.$(".close");
97
- }
98
85
  };
99
- this.getImageArrayField = this._getImageArrayField(this);
100
- this._getTaxonAutosuggestWidget = (form) => (lajiFormLocator) => new class TaxonAutosuggestWidgetPO {
101
- constructor() {
102
- this.$input = form.$locate(lajiFormLocator).$("input");
103
- this.$suggestionsContainer = form.$locate(lajiFormLocator).$(".rw-list");
104
- this.$$suggestions = form.$locate(lajiFormLocator).$$(".rw-list-option");
105
- this.waitForSuggestionsToLoad = () => protractor_1.browser.wait(exports.EC.visibilityOf(this.$suggestionsContainer), 5000, "Suggestion list timeout");
106
- this.waitForGlyph = () => protractor_1.browser.wait(exports.EC.visibilityOf(form.$locate(lajiFormLocator).$(".glyphicon.form-control-feedback")), 5000, "Glyph didn't load");
107
- this.isSuggested = () => exports.isDisplayed(form.$locate(lajiFormLocator).$(".glyphicon-ok"));
108
- this.isNonsuggested = () => exports.isDisplayed(form.$locate(lajiFormLocator).$(".glyphicon-warning-sign"));
109
- this.$powerUserButton = protractor_1.$(".power-user-addon");
110
- this.powerUserButtonIsActive = () => __awaiter(this, void 0, void 0, function* () { return (yield this.$powerUserButton.getAttribute("class")).includes("active"); });
111
- this.waitForPopoverToHide = () => protractor_1.browser.wait(exports.EC.invisibilityOf(form.$locate(lajiFormLocator).$(".popover-content")), 5000, "Popover didn't hide");
112
- }
86
+ this.getAutosuggestWidget = (lajiFormLocator) => {
87
+ return {
88
+ $input: this.$locate(lajiFormLocator).locator("input"),
89
+ $suggestionsContainer: this.$locate(lajiFormLocator).locator(".rw-list"),
90
+ $suggestions: this.$locate(lajiFormLocator).locator(".rw-list-option"),
91
+ };
92
+ };
93
+ this.getTaxonAutosuggestWidget = (lajiFormLocator) => {
94
+ const autosuggest = this.getAutosuggestWidget(lajiFormLocator);
95
+ return Object.assign(Object.assign({}, autosuggest), { $powerUserButton: this.page.locator(".power-user-addon"), $suggestedGlyph: this.$locate(lajiFormLocator).locator(".glyphicon-ok"), $nonsuggestedGlyph: this.$locate(lajiFormLocator).locator(".glyphicon-warning-sign") });
96
+ };
97
+ this.getPersonAutosuggestWidget = (lajiFormLocator) => {
98
+ const autosuggest = this.getAutosuggestWidget(lajiFormLocator);
99
+ return Object.assign(Object.assign({}, autosuggest), { $suggestedGlyph: this.$locate(lajiFormLocator).locator(".glyphicon-user") });
113
100
  };
114
- this.getTaxonAutosuggestWidget = this._getTaxonAutosuggestWidget(this);
115
101
  this.getScopeField = (lajiFormLocator) => ({
116
102
  $button: this.$locateButton(lajiFormLocator, "additionals"),
117
- $$listItems: this.$locate(lajiFormLocator).$$(".dropdown.open li a")
103
+ $$listItems: this.$locate(lajiFormLocator).locator(".dropdown.open li a"),
104
+ modal: {
105
+ $container: this.page.locator(".scope-field-modal"),
106
+ $close: this.page.locator(".scope-field-modal .close"),
107
+ $$loadingGroups: this.page.locator(".scope-field-modal .list-group .react-spinner"),
108
+ $$groupTitles: this.page.locator(".scope-field-modal .list-group .list-group-item strong"),
109
+ $$listItems: this.page.locator(".scope-field-modal .list-group-item"),
110
+ }
118
111
  });
112
+ this.getLocationChooser = (lajiFormLocator) => {
113
+ const $peeker = this.$locateButton(lajiFormLocator, "location-peeker", true);
114
+ return {
115
+ $button: this.$locateButton(lajiFormLocator, "location"),
116
+ modal: {
117
+ $container: this.page.locator(".map-dialog"),
118
+ map: new test_utils_1.MapPageObject(this.page, this.page.locator(".map-dialog .laji-map"))
119
+ },
120
+ peeker: {
121
+ $popover: $peeker,
122
+ $map: $peeker.locator(".laji-map"),
123
+ $$markers: $peeker.locator(".vector-marker path"),
124
+ }
125
+ };
126
+ };
119
127
  this.getUnitListShorthandArrayField = (lajiFormLocator) => ({
120
128
  $button: this.$locateButton(lajiFormLocator, "addUnitList"),
121
129
  modal: {
122
- $input: protractor_1.$(".unit-list-shorthand-modal input"),
123
- $addButton: protractor_1.$(".unit-list-shorthand-modal button")
130
+ $input: this.page.locator(".unit-list-shorthand-modal input"),
131
+ $addButton: this.page.locator(".unit-list-shorthand-modal button")
124
132
  }
125
133
  });
126
- this.props = params;
127
- }
128
- initialize(beforeInit, contextId) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- const query = (params) => Object.keys(params).reduce((q, key) => `${q}&${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`, "");
131
- if (this.props.id) {
132
- const _a = this.props, { id } = _a, _props = __rest(_a, ["id"]);
133
- yield exports.navigateToForm(id, query(_props));
134
- }
135
- else {
136
- yield exports.emptyForm();
137
- }
138
- beforeInit && (yield beforeInit(this));
139
- yield this.setState(this.props);
140
- this.contextId = contextId !== null && contextId !== void 0 ? contextId : yield this.e("lajiForm._id");
134
+ this.$getShortHandWidget = (lajiFormLocator) => this.$locateAddition(lajiFormLocator, "shortHandText");
135
+ this.getGeocoder = (lajiFormLocator = "") => ({
136
+ $btn: this.$locate(lajiFormLocator).locator(".geocoder-btn"),
137
+ $spinner: this.$locate(lajiFormLocator).locator(".geocoder-btn .react-spinner")
141
138
  });
142
- }
143
- e(path) {
144
- return protractor_1.browser.executeScript(`return window.lajiForm.${path}`);
145
- }
146
- setState(state) {
147
- const onSubmit = "function(data) {window.submittedData = data.formData;}";
148
- const onChange = "function(formData) {window.changedData = formData;}";
149
- return this.e(`setState({onSubmit: ${onSubmit}, onChange: ${onChange}, ...${JSON.stringify(state)}})`);
150
- }
151
- getState() {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- return protractor_1.browser.executeScript("const {formData} = window.lajiForm.lajiForm.state; return {formData};");
154
- });
155
- }
156
- submit() {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- yield this.e("submit()");
159
- yield waitUntilBlockingLoaderHides();
160
- });
161
- }
162
- startSubmit() {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- yield this.e("submit()");
165
- });
166
- }
167
- submitOnlySchemaValidations() {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- yield this.e("submitOnlySchemaValidations()");
170
- });
171
- }
172
- waitUntilBlockingLoaderHides(timeout) {
173
- return waitUntilBlockingLoaderHides(timeout);
174
- }
175
- getSubmittedData() {
176
- return protractor_1.browser.executeScript("return window.submittedData");
177
- }
178
- getChangedData() {
179
- return protractor_1.browser.executeScript("return window.changedData");
180
- }
181
- getPropsData() {
182
- return this.e("lajiForm.props.formData");
139
+ this.getNamedPlaceChooser = () => {
140
+ const $namedPlaceChooserModal = this.page.locator(".named-place-chooser-modal");
141
+ const $mapPopupContainer = this.page.locator(".named-place-popup");
142
+ return {
143
+ select: getEnumWidgetForContainer(this.page.locator("#named-place-chooser-select")),
144
+ mapPopup: {
145
+ $container: $mapPopupContainer,
146
+ $useBtn: $mapPopupContainer.locator(".btn-default")
147
+ },
148
+ $alert: $namedPlaceChooserModal.locator(".alert"),
149
+ $close: $namedPlaceChooserModal.locator(".close")
150
+ };
151
+ };
183
152
  }
184
153
  $locate(path) {
185
- return protractor_1.$(exports.getLocatorForContextId(this.contextId)(path));
154
+ return this.page.locator(exports.lajiFormLocator(path));
186
155
  }
187
- $locateButton(path, selector) {
188
- return protractor_1.$(`#root${typeof path === "string" && path.length > 0 ? `_${path.replace(/\./g, "_")}` : ""}-${selector}`);
156
+ $locateButton(path, selector, locateFromBody = false) {
157
+ return (locateFromBody ? this.page : this.locator).locator(`#root${typeof path === "string" && path.length > 0 ? `_${path.replace(/\./g, "_")}` : ""}-${selector}`);
189
158
  }
190
- $locateAddition(path, selector) {
191
- return this.$locateButton(path, selector);
159
+ $locateAddition(path, selector, locateFromBody = false) {
160
+ return this.$locateButton(path, selector, locateFromBody);
192
161
  }
193
162
  setMockResponse(path, query) {
194
163
  return __awaiter(this, void 0, void 0, function* () {
195
- yield protractor_1.browser.executeScript(`return window.setMockResponse(${JSON.stringify(path)}, ${JSON.stringify(query)})`);
196
- const mock = (method, response, raw) => protractor_1.browser.executeScript(`return ${this.getMockStr(path, query)}.${method}(${JSON.stringify(response)}, ${JSON.stringify(raw)})`);
164
+ yield this.page.evaluate(`window.setMockResponse(${JSON.stringify(path)}, ${JSON.stringify(query)})`);
165
+ const mock = (method, response, raw) => this.page.evaluate(`${this.getMockStr(path, query)}.${method}(${JSON.stringify(response)}, ${JSON.stringify(raw)})`);
197
166
  return {
198
167
  resolve: (response, raw) => mock("resolve", response, raw),
199
168
  reject: (response, raw) => mock("reject", response, raw),
@@ -203,15 +172,15 @@ class Form {
203
172
  }
204
173
  createMockResponseQueue(path, query) {
205
174
  return __awaiter(this, void 0, void 0, function* () {
206
- yield protractor_1.browser.executeScript(`return window.createMockResponseQueue(${JSON.stringify(path)}, ${JSON.stringify(query)})`);
175
+ yield this.page.evaluate(`window.createMockResponseQueue(${JSON.stringify(path)}, ${JSON.stringify(query)})`);
207
176
  const queueStr = `window.mockQueues[window.getMockQueryKey(${JSON.stringify(path)}, ${JSON.stringify(query)})]`;
208
177
  const mock = (method, response, raw, pointer) => {
209
- return protractor_1.browser.executeScript(`return ${this.getMockStr(path, query)}[${pointer}].${method}(${JSON.stringify(response)}, ${JSON.stringify(raw)})`);
178
+ return this.page.evaluate(`${this.getMockStr(path, query)}[${pointer}].${method}(${JSON.stringify(response)}, ${JSON.stringify(raw)})`);
210
179
  };
211
180
  let pointer = 0;
212
181
  return {
213
182
  create: () => __awaiter(this, void 0, void 0, function* () {
214
- yield protractor_1.browser.executeScript(`return ${queueStr}.create()`);
183
+ yield this.page.evaluate(`${queueStr}.create()`);
215
184
  const _pointer = pointer;
216
185
  pointer = pointer + 1;
217
186
  return {
@@ -219,112 +188,147 @@ class Form {
219
188
  reject: (response, raw) => mock("reject", response, raw, _pointer),
220
189
  };
221
190
  }),
222
- remove: () => protractor_1.browser.executeScript(`return ${queueStr}.remove()`)
191
+ remove: () => this.page.evaluate(`${queueStr}.remove()`)
223
192
  };
224
193
  });
225
194
  }
226
195
  getBooleanWidget(str) {
227
- const $container = this.$locate(str).$(".btn-toolbar");
196
+ const $container = this.$locate(str).locator(".btn-toolbar");
228
197
  return {
229
198
  $container,
230
- $true: $container.$$(".btn").get(0),
231
- $false: $container.$$(".btn").get(1),
232
- $undefined: this.$locate(str).$$(".btn").get(2),
233
- $active: $container.$(".btn.active"),
234
- $nonactive: $container.$$(".btn").filter(($btn) => __awaiter(this, void 0, void 0, function* () { return !(yield $btn.getAttribute("class")).includes("active"); })).first()
199
+ $true: $container.locator(".btn").nth(0),
200
+ $false: $container.locator(".btn").nth(1),
201
+ $undefined: this.$locate(str).locator(".btn").nth(2),
202
+ $active: $container.locator(".btn.active"),
203
+ $nonactive: $container.locator(".btn:not(.active)").first()
235
204
  };
236
205
  }
237
206
  $getInputWidget(str) {
238
- return this.$locate(str).$("input");
207
+ return this.$locate(str).locator("input");
239
208
  }
240
209
  $getTextareaWidget(str) {
241
- return this.$locate(str).$("textarea");
210
+ return this.$locate(str).locator("textarea");
242
211
  }
243
212
  $getEnumWidget(str) {
244
- const $container = this.$locate(str).$(".rw-combobox");
213
+ const $container = this.$locate(str).locator(".rw-combobox");
245
214
  return getEnumWidgetForContainer($container);
246
215
  }
247
216
  getDateWidget(str) {
248
- const $widget = this.$locate(str).$(".date-widget");
217
+ const $widget = this.$locate(str).locator(".date-widget");
249
218
  return {
250
219
  $container: $widget,
251
- $input: $widget.$("input"),
220
+ $input: $widget.locator("input"),
252
221
  buttons: {
253
- $today: $widget.$(".today"),
254
- $yesterday: $widget.$(".yesterday"),
255
- $same: $widget.$(".same"),
256
- $date: $widget.$(".rw-i-calendar"),
257
- $time: $widget.$(".rw-i-clock-o")
222
+ $today: $widget.locator(".today"),
223
+ $yesterday: $widget.locator(".yesterday"),
224
+ $same: $widget.locator(".same"),
225
+ $date: $widget.locator(".rw-i-calendar"),
226
+ $time: $widget.locator(".rw-i-clock-o")
258
227
  },
259
228
  calendar: {
260
- $today: $widget.$(".rw-calendar-footer button"),
261
- waitAnimation: () => protractor_1.browser.wait(exports.EC.visibilityOf($widget.$(".rw-calendar-footer button")), 1000, "Calendar didn't show")
229
+ $today: $widget.locator(".rw-calendar-footer button"),
262
230
  },
263
231
  clock: {
264
- "$01:00": $widget.$$(".rw-list li").get(2),
265
- waitAnimation: () => protractor_1.browser.wait(exports.EC.visibilityOf($widget.$(".rw-list")), 1000, "Clock didn't show")
232
+ "$01:00": $widget.locator(".rw-list li").nth(2),
266
233
  }
267
234
  };
268
235
  }
269
- $$getFieldErrors(str) {
270
- return this.$locate(str).$$(".laji-form-error-container li");
236
+ $getFieldErrors(str) {
237
+ return this.$locate(str).locator(".laji-form-error-container li");
238
+ }
239
+ /** Draws a marker to the center of a laji-map rendered to the given locator. The locator defaults to "gatherings" */
240
+ putMarkerToMap(lajiFormLocator = "gatherings") {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ const $map = this.$locate(lajiFormLocator).locator(".laji-map");
243
+ yield $map.scrollIntoViewIfNeeded();
244
+ const map = new test_utils_1.MapPageObject(this.page, $map);
245
+ yield map.drawMarker();
246
+ });
271
247
  }
272
248
  }
273
249
  exports.Form = Form;
274
- const isDisplayed = ($elem) => __awaiter(void 0, void 0, void 0, function* () { return (yield $elem.isPresent()) && (yield $elem.isDisplayed()); });
275
- exports.isDisplayed = isDisplayed;
276
- const $mapPopupContainer = protractor_1.$(".named-place-popup");
277
- const $namedPlaceChooserModal = protractor_1.$(".named-place-chooser-modal");
278
- class NamedPlaceChooserPO {
279
- constructor() {
280
- this.select = getEnumWidgetForContainer(protractor_1.$("#named-place-chooser-select"));
281
- this.mapPopup = {
282
- $container: $mapPopupContainer,
283
- $useBtn: $mapPopupContainer.$(".btn-default")
284
- };
285
- this.$alert = $namedPlaceChooserModal.$(".alert");
286
- this.$close = $namedPlaceChooserModal.$(".close");
250
+ class DemoPageForm extends Form {
251
+ constructor(page, props) {
252
+ super(page);
253
+ this.props = props;
254
+ this.mockImageUpload = (lajiFormLocator) => __awaiter(this, void 0, void 0, function* () {
255
+ const filePath = path.resolve(__dirname, "./mock/pixel.png");
256
+ const imageResponse = [{ name: "data", filename: "pixel.png", id: "mock", expires: 1575979685 }];
257
+ const { resolve, remove } = yield this.setMockResponse("/images", false);
258
+ const mdResponse = exports.mockImageMetadata;
259
+ const { resolve: mdResolve, remove: mdRemove } = yield this.setMockResponse("/images/mock", false);
260
+ yield this.getImageArrayField(lajiFormLocator).$dropzone.locator("input").setInputFiles(filePath);
261
+ return {
262
+ resolve: () => __awaiter(this, void 0, void 0, function* () {
263
+ yield resolve(imageResponse);
264
+ yield mdResolve(mdResponse);
265
+ }),
266
+ remove: () => __awaiter(this, void 0, void 0, function* () {
267
+ yield remove();
268
+ yield mdRemove();
269
+ })
270
+ };
271
+ });
272
+ }
273
+ initialize(beforeInit) {
274
+ var _a;
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const query = (params) => Object.keys(params).reduce((q, key) => `${q}&${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`, "");
277
+ if ((_a = this.props) === null || _a === void 0 ? void 0 : _a.id) {
278
+ const _b = this.props, { id } = _b, _props = __rest(_b, ["id"]);
279
+ yield exports.navigateToForm(this.page, id, query(_props));
280
+ }
281
+ else {
282
+ yield exports.emptyForm(this.page);
283
+ }
284
+ beforeInit && (yield beforeInit(this));
285
+ yield this.setState(this.props);
286
+ });
287
+ }
288
+ e(path) {
289
+ return this.page.evaluate(`window.lajiForm.${path}`);
290
+ }
291
+ setState(state) {
292
+ const onSubmit = "function(data) {window.submittedData = data.formData;}";
293
+ const onChange = "function(formData) {window.changedData = formData;}";
294
+ return this.e(`setState({onSubmit: ${onSubmit}, onChange: ${onChange}, ...${JSON.stringify(state)}})`);
295
+ }
296
+ getState() {
297
+ return this.page.evaluate(() => {
298
+ const { formData } = window.lajiForm.lajiForm.state;
299
+ return { formData };
300
+ });
301
+ }
302
+ submit() {
303
+ return __awaiter(this, void 0, void 0, function* () {
304
+ yield this.e("submit()");
305
+ });
306
+ }
307
+ startSubmit() {
308
+ this.e("submit()");
309
+ }
310
+ submitOnlySchemaValidations() {
311
+ return this.e("submitOnlySchemaValidations()");
312
+ }
313
+ getSubmittedData() {
314
+ return this.page.evaluate("window.submittedData");
315
+ }
316
+ getChangedData() {
317
+ return this.page.evaluate("window.changedData");
318
+ }
319
+ getPropsData() {
320
+ return this.e("lajiForm.props.formData");
287
321
  }
288
322
  }
289
- exports.NamedPlaceChooserPO = NamedPlaceChooserPO;
290
- function createForm(props, beforeInit) {
323
+ exports.DemoPageForm = DemoPageForm;
324
+ function createForm(page, props, beforeInit) {
291
325
  return __awaiter(this, void 0, void 0, function* () {
292
- const form = new Form(props);
326
+ const form = new DemoPageForm(page, props);
293
327
  yield form.initialize(beforeInit);
294
328
  return form;
295
329
  });
296
330
  }
297
331
  exports.createForm = createForm;
298
- function waitUntilBlockingLoaderHides(timeout) {
299
- return protractor_1.browser.wait(protractor_1.protractor.ExpectedConditions.invisibilityOf(protractor_1.$(".laji-form.blocking-loader")), timeout || 20000, "Blocking loader timeout");
300
- }
301
- exports.waitUntilBlockingLoaderHides = waitUntilBlockingLoaderHides;
302
- function putForeignMarkerToMap() {
303
- return __awaiter(this, void 0, void 0, function* () {
304
- const $gatheringsMap = exports.lajiFormLocate("gatherings").$(".laji-map");
305
- const $markerButton = protractor_1.$(".leaflet-draw-draw-marker");
306
- yield $markerButton.click();
307
- yield protractor_1.browser.actions().mouseMove($gatheringsMap.getWebElement(), { x: -100, y: -100 }).perform();
308
- yield protractor_1.browser.actions().click().perform();
309
- });
310
- }
311
- exports.putForeignMarkerToMap = putForeignMarkerToMap;
312
- function removeUnit(gatheringIdx, unitIdx) {
313
- return __awaiter(this, void 0, void 0, function* () {
314
- yield protractor_1.$(`#root_gatherings_${gatheringIdx}_units_${unitIdx}-delete`).click();
315
- return protractor_1.$(`#root_gatherings_${gatheringIdx}_units_${unitIdx}-delete-confirm-yes`).click();
316
- });
317
- }
318
- exports.removeUnit = removeUnit;
319
- const updateValue = ($input, value, blur = true) => __awaiter(void 0, void 0, void 0, function* () {
320
- const current = (yield $input.getAttribute("value")) || "";
321
- yield $input.click();
322
- yield $input.sendKeys(...Array(current.length).fill(protractor_1.protractor.Key.BACK_SPACE), value);
323
- if (blur) {
324
- return $input.sendKeys(protractor_1.protractor.Key.TAB);
325
- }
326
- });
327
- exports.updateValue = updateValue;
328
332
  exports.mockImageMetadata = {
329
333
  "id": "mock",
330
334
  "capturerVerbatim": [
@@ -352,3 +356,13 @@ const filterUUIDs = (any) => {
352
356
  exports.filterUUIDs = filterUUIDs;
353
357
  const maybeJSONPointerToLocator = (pointer) => pointer[0] === "/" ? pointer.slice(1).replace(/\//g, "_") : pointer;
354
358
  exports.maybeJSONPointerToLocator = maybeJSONPointerToLocator;
359
+ const updateValue = ($input, value) => __awaiter(void 0, void 0, void 0, function* () {
360
+ yield $input.fill(value);
361
+ yield $input.press("Tab");
362
+ });
363
+ exports.updateValue = updateValue;
364
+ const getRemoveUnit = (page) => (gatheringIdx, unitIdx) => __awaiter(void 0, void 0, void 0, function* () {
365
+ yield page.locator(`#root_gatherings_${gatheringIdx}_units_${unitIdx}-delete`).click();
366
+ return page.locator(`#root_gatherings_${gatheringIdx}_units_${unitIdx}-delete-confirm-yes`).click();
367
+ });
368
+ exports.getRemoveUnit = getRemoveUnit;
@@ -5,6 +5,6 @@
5
5
  "declaration": true
6
6
  },
7
7
  "include": [
8
- "./test/**/*"
8
+ "./test/test-utils.ts"
9
9
  ]
10
10
  }
@@ -1 +0,0 @@
1
- export {};