@@ -10,17 +10,20 @@ const TEMPLATE = fs.readFileSync(
10
10
const EVENTS = { } ;
11
11
12
12
/**
13
- * send an input event
13
+ * send an keydown event
14
14
* @param {HTMLElement } el the element to sent the event to
15
15
*/
16
- EVENTS . input = ( el ) => {
17
- el . dispatchEvent ( new KeyboardEvent ( "keyup " , { bubbles : true } ) ) ;
16
+ EVENTS . keydown = ( el ) => {
17
+ el . dispatchEvent ( new KeyboardEvent ( "keydown " , { bubbles : true } ) ) ;
18
18
} ;
19
19
20
- const inputMaskingSelector = ( ) => document . querySelector ( ".usa-input-masking" ) ;
20
+ const inputMaskSelector = ( ) => document . querySelector ( ".usa-input-mask" ) ;
21
+ // const inputMaskShellSelector = () =>
22
+ // document.querySelector(".usa-input-mask__content");
23
+
21
24
const tests = [
22
25
{ name : "document.body" , selector : ( ) => document . body } ,
23
- { name : "input mask" , selector : inputMaskingSelector } ,
26
+ { name : "input mask" , selector : inputMaskSelector } ,
24
27
] ;
25
28
26
29
tests . forEach ( ( { name, selector : containerSelector } ) => {
@@ -29,27 +32,64 @@ tests.forEach(({ name, selector: containerSelector }) => {
29
32
30
33
let root ;
31
34
let input ;
35
+ let statusMessageVisual ;
36
+ let statusMessageSR ;
32
37
let shell ;
33
38
34
39
beforeEach ( ( ) => {
35
40
body . innerHTML = TEMPLATE ;
36
- InputMask . on ( containerSelector ( ) ) ;
37
-
38
- root = inputMaskingSelector ( ) ;
39
- input = root . querySelector ( ".usa-input" ) ;
41
+ root = containerSelector ( ) . parentNode ;
42
+ console . log ( 'ROOT: ' , root . outerHTML ) ;
43
+ InputMask . on ( root ) ;
44
+ input = root . querySelector ( ".usa-input-mask" ) ;
45
+ statusMessageVisual = root . querySelector ( "#alphanumericError" ) ;
46
+ statusMessageSR = root . querySelector ( "#alphanumericErrorSrOnly" ) ;
40
47
} ) ;
41
48
42
49
afterEach ( ( ) => {
43
- InputMask . off ( containerSelector ( ) ) ;
50
+ InputMask . off ( root ) ;
44
51
body . textContent = "" ;
45
52
} ) ;
46
53
47
- it ( "formats an alphanumeric example to A1B 2C3" , ( ) => {
48
- input . value = "A1B2C3" ;
54
+ it ( "creates a visual status message on init" , ( ) => {
55
+ const visibleStatus = document . getElementById ( "#alphanumericError" ) ;
56
+
57
+ assert . strictEqual ( visibleStatus . length , 1 ) ;
58
+ } ) ;
59
+
60
+ it ( "creates a screen reader status message on init" , ( ) => {
61
+ const srStatus = document . querySelectorAll ( "#alphanumericErrorSrOnly" ) ;
62
+
63
+ assert . strictEqual ( srStatus . length , 1 ) ;
64
+ } ) ;
65
+
66
+ it ( "informs the user only a number character is allowed" , ( ) => {
67
+ input . value = "a" ;
68
+
69
+ EVENTS . keydown ( input ) ;
49
70
50
- EVENTS . input ( input ) ;
51
- shell = root . querySelector ( ".usa-input-mask--content" ) ;
52
- assert . strictEqual ( shell . textContent , "A1B 2C3" ) ;
71
+ assert . strictEqual (
72
+ statusMessageVisual . innerHTML ,
73
+ "You must enter a number" ,
74
+ ) ;
53
75
} ) ;
76
+
77
+ // it("formats an alphanumeric example to A1B 2C3", () => {
78
+ // const value = "A1B2C3";
79
+
80
+ // for (let i = 0; i < value.length; i += 1) {
81
+ // input.dispatchEvent(
82
+ // new KeyboardEvent("keydown", {
83
+ // bubbles: true,
84
+ // key: value[i],
85
+ // keyCode: value[i].charCodeAt(0),
86
+ // which: value[i].charCodeAt(0),
87
+ // })
88
+ // );
89
+ // }
90
+
91
+ // shell = inputMaskShellSelector();
92
+ // assert.strictEqual(shell.textContent, "1EG4-TE5-MK73");
93
+ // });
54
94
} ) ;
55
95
} ) ;
0 commit comments