@ministryofjustice/frontend 2.2.3 → 2.2.4

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/moj/all.js CHANGED
@@ -1840,6 +1840,7 @@ MOJFrontend.PasswordReveal.prototype.onButtonClick = function() {
1840
1840
  }
1841
1841
  };
1842
1842
 
1843
+
1843
1844
  if('contentEditable' in document.documentElement) {
1844
1845
  MOJFrontend.RichTextEditor = function(options) {
1845
1846
  this.options = options;
@@ -0,0 +1,22 @@
1
+ const { getByText, getByTestId } = require("@testing-library/dom");
2
+
3
+ require("./helpers");
4
+ require("./all.js");
5
+
6
+ describe("initAll", () => {
7
+ test("initialises container", () => {
8
+ MOJFrontend.PasswordReveal = jest.fn();
9
+
10
+ const container = document.createElement("div");
11
+
12
+ container.innerHTML = `
13
+ <input data-module="moj-password-reveal" data-testid="password-reveal" type="password" />
14
+ `;
15
+
16
+ new MOJFrontend.initAll({ scope: container });
17
+
18
+ expect(MOJFrontend.PasswordReveal).toHaveBeenCalledWith(
19
+ getByTestId(container, "password-reveal"),
20
+ );
21
+ });
22
+ });
@@ -29,3 +29,4 @@ MOJFrontend.PasswordReveal.prototype.onButtonClick = function() {
29
29
  this.button.html('Show <span class="govuk-visually-hidden">password</span>');
30
30
  }
31
31
  };
32
+
@@ -0,0 +1,46 @@
1
+ const { getByDisplayValue, getByText } = require("@testing-library/dom");
2
+ const { axe } = require("jest-axe");
3
+
4
+ require("./password-reveal.js");
5
+
6
+ describe("Password reveal", () => {
7
+ let container;
8
+
9
+ beforeEach(() => {
10
+ const input = document.createElement("input");
11
+ input.type = "password";
12
+ input.value = "password";
13
+
14
+ new MOJFrontend.PasswordReveal(input);
15
+
16
+ container = input.parentNode;
17
+ });
18
+
19
+ test("initialises container", () => {
20
+ expect(container).toHaveClass("moj-password-reveal");
21
+ expect(container).toContainElement(getByText(container, "Show"));
22
+ });
23
+
24
+ test("toggle reveal", () => {
25
+ const input = getByDisplayValue(container, "password");
26
+ const button = getByText(container, "Show");
27
+
28
+ button.click();
29
+
30
+ expect(input).toHaveAttribute("type", "text");
31
+ expect(button).toHaveTextContent("Hide");
32
+
33
+ button.click();
34
+
35
+ expect(input).toHaveAttribute("type", "password");
36
+ expect(button).toHaveTextContent("Show");
37
+ });
38
+
39
+ test("accessibility", async () => {
40
+ const button = getByText(container, "Show");
41
+
42
+ expect(await axe(document.body)).toHaveNoViolations();
43
+ button.click();
44
+ expect(await axe(document.body)).toHaveNoViolations();
45
+ });
46
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/frontend",
3
3
  "description": "The MOJ Frontend contains the code you need to start building user interfaces for UK Ministry of Justice government services.",
4
- "version": "2.2.3",
4
+ "version": "2.2.4",
5
5
  "main": "moj/all.js",
6
6
  "sass": "moj/all.scss",
7
7
  "engines": {