brut-js 0.0.2 → 0.0.5
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.
- package/package.json +5 -2
- package/specs/AjaxSubmit.spec.js +8 -5
- package/specs/Autosubmit.spec.js +1 -1
- package/specs/ConfirmSubmit.spec.js +1 -1
- package/specs/ConstraintViolationMessage.spec.js +1 -1
- package/specs/ConstraintViolationMessages.spec.js +1 -1
- package/specs/Form.spec.js +45 -1
- package/specs/I18nTranslation.spec.js +1 -1
- package/specs/LocaleDetection.spec.js +2 -2
- package/specs/Message.spec.js +1 -1
- package/specs/SpecHelper.js +23 -0
- package/specs/Tabs.spec.js +1 -1
- package/specs/public/js/bundle.js +17 -2
- package/specs/public/js/bundle.js.map +2 -2
- package/src/AjaxSubmit.js +2 -2
- package/src/CopyToClipboard.js +92 -0
- package/src/Form.js +16 -2
- package/src/testing/AssetMetadata.js +35 -0
- package/src/testing/AssetMetadataLoader.js +25 -0
- package/src/testing/CustomElementTest.js +235 -0
- package/src/testing/DOMCreator.js +45 -0
- package/src/testing/index.js +13 -313
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brut-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [ "WebComponents", "Custom Elements" ],
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/thirdtank/brut-js/issues",
|
|
8
8
|
"email": "davec@naildrivin5.com"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.js",
|
|
12
|
+
"./testing": "./src/testing/index.js"
|
|
13
|
+
},
|
|
11
14
|
"repository": "https://github.com/thirdtank/brut-js",
|
|
12
15
|
"author": {
|
|
13
16
|
"name": "David Copeland",
|
package/specs/AjaxSubmit.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withHTML
|
|
1
|
+
import { withHTML } from "./SpecHelper.js"
|
|
2
2
|
|
|
3
3
|
describe("<brut-ajax-submit>", () => {
|
|
4
4
|
withHTML(`
|
|
@@ -12,7 +12,9 @@ describe("<brut-ajax-submit>", () => {
|
|
|
12
12
|
`).onFetch( "/foo", [
|
|
13
13
|
{ then: { status: 200 }},
|
|
14
14
|
]
|
|
15
|
-
).test("submits the form, setting various attributes during the lifecycle",
|
|
15
|
+
).test("submits the form, setting various attributes during the lifecycle",
|
|
16
|
+
({document,assert,fetchRequests,waitForSetTimeout,readRequestBodyIntoString}) => {
|
|
17
|
+
|
|
16
18
|
const element = document.querySelector("brut-ajax-submit")
|
|
17
19
|
const button = element.querySelector("button")
|
|
18
20
|
const text = document.querySelector("input[name=some-text]")
|
|
@@ -80,7 +82,8 @@ describe("<brut-ajax-submit>", () => {
|
|
|
80
82
|
{ then: { status: 500 }},
|
|
81
83
|
{ then: { status: 200 }},
|
|
82
84
|
]
|
|
83
|
-
).test("submits the form after a retry",
|
|
85
|
+
).test("submits the form after a retry",
|
|
86
|
+
({document,assert,fetchRequests,waitForSetTimeout,readRequestBodyIntoString}) => {
|
|
84
87
|
const element = document.querySelector("brut-ajax-submit")
|
|
85
88
|
const button = element.querySelector("button")
|
|
86
89
|
const text = document.querySelector("input[name=some-text]")
|
|
@@ -124,7 +127,7 @@ describe("<brut-ajax-submit>", () => {
|
|
|
124
127
|
{ then: { status: 500 }},
|
|
125
128
|
{ then: { status: 500 }},
|
|
126
129
|
]
|
|
127
|
-
).test("when too many failures, submits the form the old-fashioned way", ({document,assert,fetchRequests}) => {
|
|
130
|
+
).test("when too many failures, submits the form the old-fashioned way", ({document,assert,fetchRequests, waitForSetTimeout}) => {
|
|
128
131
|
const form = document.querySelector("form")
|
|
129
132
|
const element = form.querySelector("brut-ajax-submit")
|
|
130
133
|
const button = element.querySelector("button")
|
|
@@ -195,7 +198,7 @@ Error that should be ignored
|
|
|
195
198
|
}
|
|
196
199
|
},
|
|
197
200
|
]
|
|
198
|
-
).test("when we get a 422, parses the result from the server", ({document,window,assert,fetchRequests}) => {
|
|
201
|
+
).test("when we get a 422, parses the result from the server", ({document,window,assert,fetchRequests,waitForSetTimeout}) => {
|
|
199
202
|
const form = document.querySelector("form")
|
|
200
203
|
const element = form.querySelector("brut-ajax-submit")
|
|
201
204
|
const button = element.querySelector("button")
|
package/specs/Autosubmit.spec.js
CHANGED
package/specs/Form.spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withHTML } from "
|
|
1
|
+
import { withHTML } from "./SpecHelper.js"
|
|
2
2
|
|
|
3
3
|
describe("<brut-form>", () => {
|
|
4
4
|
withHTML(`
|
|
@@ -133,4 +133,48 @@ describe("<brut-form>", () => {
|
|
|
133
133
|
assert(gotValid)
|
|
134
134
|
assert(!gotInvalid)
|
|
135
135
|
})
|
|
136
|
+
withHTML(`
|
|
137
|
+
<brut-form>
|
|
138
|
+
<form>
|
|
139
|
+
<label>
|
|
140
|
+
<input required type="text" name="text">
|
|
141
|
+
</label>
|
|
142
|
+
<brut-constraint-violation-messages input-name='text'>
|
|
143
|
+
</brut-constraint-violation-messages>
|
|
144
|
+
<input type="submit">Save</input>
|
|
145
|
+
</form>
|
|
146
|
+
</brut-form>
|
|
147
|
+
`).test("locates the messages for errors based on name", ({window,document,assert}) => {
|
|
148
|
+
|
|
149
|
+
const brutForm = document.querySelector("brut-form")
|
|
150
|
+
const form = brutForm.querySelector("form")
|
|
151
|
+
const button = form.querySelector("input[type=submit]")
|
|
152
|
+
const textFieldLabel = form.querySelector("label:has(input[type=text])")
|
|
153
|
+
|
|
154
|
+
let submitted = false
|
|
155
|
+
let gotInvalid = false
|
|
156
|
+
let gotValid = false
|
|
157
|
+
|
|
158
|
+
form.addEventListener("submit", (event) => {
|
|
159
|
+
event.preventDefault()
|
|
160
|
+
submitted = true
|
|
161
|
+
})
|
|
162
|
+
brutForm.addEventListener("brut:valid", () => {
|
|
163
|
+
gotValid = true
|
|
164
|
+
})
|
|
165
|
+
brutForm.addEventListener("brut:invalid", () => {
|
|
166
|
+
gotInvalid = true
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
button.click()
|
|
170
|
+
|
|
171
|
+
assert(!submitted)
|
|
172
|
+
assert(!gotValid)
|
|
173
|
+
assert(gotInvalid)
|
|
174
|
+
assert(form.dataset["submitted"] != null)
|
|
175
|
+
|
|
176
|
+
let error = brutForm.querySelector("brut-constraint-violation-message[input-name='text'][key='general.cv.fe.valueMissing']")
|
|
177
|
+
assert(error)
|
|
178
|
+
|
|
179
|
+
})
|
|
136
180
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withHTML
|
|
1
|
+
import { withHTML } from "./SpecHelper.js"
|
|
2
2
|
|
|
3
3
|
describe("<brut-locale-detection>", () => {
|
|
4
4
|
withHTML(`
|
|
@@ -6,7 +6,7 @@ describe("<brut-locale-detection>", () => {
|
|
|
6
6
|
`).onFetch( "/locale", [
|
|
7
7
|
{ then: { status: 200 }},
|
|
8
8
|
]
|
|
9
|
-
).test("Receives the locale and timeZone from the browser", ({document,assert,fetchRequests}) => {
|
|
9
|
+
).test("Receives the locale and timeZone from the browser", ({document,assert,fetchRequests,readRequestBodyIntoJSON}) => {
|
|
10
10
|
|
|
11
11
|
assert.equal(1,fetchRequests.length)
|
|
12
12
|
return readRequestBodyIntoJSON(fetchRequests[0]).then( (json) => {
|
package/specs/Message.spec.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createTestBasedOnHTML } from "../src/testing/index.js"
|
|
2
|
+
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import fs from "node:fs"
|
|
5
|
+
|
|
6
|
+
const __dirname = import.meta.dirname
|
|
7
|
+
|
|
8
|
+
const appRoot = path.resolve(__dirname)
|
|
9
|
+
const publicRoot = path.resolve(appRoot,"public")
|
|
10
|
+
const assetMetadataFilePath = path.resolve(appRoot,"config","asset_metadata.json")
|
|
11
|
+
const assetMetadata = JSON.parse(fs.readFileSync(assetMetadataFilePath))
|
|
12
|
+
|
|
13
|
+
const withHTML = (html) => {
|
|
14
|
+
return createTestBasedOnHTML({
|
|
15
|
+
html,
|
|
16
|
+
assetMetadata,
|
|
17
|
+
publicRoot
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
withHTML,
|
|
23
|
+
}
|
package/specs/Tabs.spec.js
CHANGED
|
@@ -978,9 +978,24 @@
|
|
|
978
978
|
#updateErrorMessages(event) {
|
|
979
979
|
const element = event.target;
|
|
980
980
|
const selector = `${ConstraintViolationMessages_default.tagName}:not([server-side])`;
|
|
981
|
-
|
|
981
|
+
let errorLabels = element.parentNode.querySelectorAll(selector);
|
|
982
|
+
if (errorLabels.length == 0) {
|
|
983
|
+
if (element.name && element.form) {
|
|
984
|
+
const moreGeneralSelector = `${ConstraintViolationMessages_default.tagName}[input-name='${element.name}']:not([server-side])`;
|
|
985
|
+
errorLabels = element.form.querySelectorAll(moreGeneralSelector);
|
|
986
|
+
if (errorLabels.length == 0) {
|
|
987
|
+
this.logger.warn(`Did not find any elements matching ${selector} or ${moreGeneralSelector}, so no error messages will be shown`);
|
|
988
|
+
}
|
|
989
|
+
} else {
|
|
990
|
+
this.logger.warn(
|
|
991
|
+
"Did not find any elements matching %s and the form element has %s %s",
|
|
992
|
+
selector,
|
|
993
|
+
element.name ? "no name" : "a name, but",
|
|
994
|
+
element.form ? "no form" : "though has a form"
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
982
998
|
if (errorLabels.length == 0) {
|
|
983
|
-
this.logger.warn(`Did not find any elements matching ${selector}, so no error messages will be shown`);
|
|
984
999
|
return;
|
|
985
1000
|
}
|
|
986
1001
|
let anyErrors = false;
|