Skip to content

Commit

Permalink
Merge branch 'master' into FE-6666
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-albu-sage authored Oct 28, 2024
2 parents e3c248b + c95af5e commit 8e180b9
Show file tree
Hide file tree
Showing 23 changed files with 2,280 additions and 1,922 deletions.
8 changes: 4 additions & 4 deletions src/__internal__/focus-trap/focus-trap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1324,21 +1324,21 @@ describe("when focus is lost to the document body and `topModalContext` has a va
render(<ComponentWithTopModalContext trapIsTopModal />);

await user.click(screen.getByText("I am some irrelevant text"));
expect(document.body).toBeFocused();
expect(document.body).toHaveFocus();

await user.tab();
expect(screen.getByRole("button", { name: "One" })).toBeFocused();
expect(screen.getByRole("button", { name: "One" })).toHaveFocus();
});

it("should not do anything when the user tabs and the focus trap is not in the top modal", async () => {
const user = userEvent.setup({ delay: null });
render(<ComponentWithTopModalContext trapIsTopModal={false} />);

await user.click(screen.getByText("I am some irrelevant text"));
expect(document.body).toBeFocused();
expect(document.body).toHaveFocus();

await user.tab();
expect(screen.getByText("Outside button")).toBeFocused();
expect(screen.getByText("Outside button")).toHaveFocus();
});
});

Expand Down
76 changes: 38 additions & 38 deletions src/__internal__/utils/helpers/events/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Events from "./events";

describe("isEventType", () => {
test("Returns true when the event type and passed type match", () => {
it("returns true when the event type and passed type match", () => {
const event = { type: "click" } as Event;
const result = Events.isEventType(event, "click");

expect(result).toBeTruthy();
});

test("Returns false when the event type and passed type do not match", () => {
it("returns false when the event type and passed type do not match", () => {
const event = { type: "click" } as Event;
const result = Events.isEventType(event, "keyUp");

Expand All @@ -18,7 +18,7 @@ describe("isEventType", () => {

describe("isKeyboardEvent", () => {
test.each(["keyup", "keydown", "keypress"])(
"Returns true when the event type is a keyboard event type (%s)",
"returns true when the event type is a keyboard event type (%s)",
(type) => {
const event = { type } as Event;
const result = Events.isKeyboardEvent(event);
Expand All @@ -27,7 +27,7 @@ describe("isKeyboardEvent", () => {
}
);

test("Returns false when the event type is not a keyboard event type", () => {
it("returns false when the event type is not a keyboard event type", () => {
const event = { type: "click" } as Event;
const result = Events.isKeyboardEvent(event);

Expand All @@ -36,28 +36,28 @@ describe("isKeyboardEvent", () => {
});

describe("isEnterOrSpaceKey", () => {
test("Returns true when the event type is a keyup event, and the key is the Enter key", () => {
it("returns true when the event type is a keyup event, and the key is the Enter key", () => {
const event = { type: "keyup", key: "Enter" } as KeyboardEvent;
const result = Events.isEnterOrSpaceKey(event);

expect(result).toBeTruthy();
});

test("Returns true when the event type is a keyup event, and the key is the Space key", () => {
it("returns true when the event type is a keyup event, and the key is the Space key", () => {
const event = { type: "keyup", key: " " } as KeyboardEvent;
const result = Events.isEnterOrSpaceKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is a keyup event, but the key is not the Enter key or the Space key", () => {
it("returns false when the event type is a keyup event, but the key is not the Enter key or the Space key", () => {
const event = { type: "keyup", key: "Backspace" } as KeyboardEvent;
const result = Events.isEnterOrSpaceKey(event);

expect(result).toBeFalsy();
});

test("Returns false when the event type is not a keyup event", () => {
it("returns false when the event type is not a keyup event", () => {
const event = { type: "keydown" } as KeyboardEvent;
const result = Events.isEnterOrSpaceKey(event);

Expand All @@ -67,7 +67,7 @@ describe("isEnterOrSpaceKey", () => {

describe("isNumberKey", () => {
test.each(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])(
"Returns true when the event type is a number key event (%s)",
"returns true when the event type is a number key event (%s)",
(key) => {
const event = { key } as KeyboardEvent;
const result = Events.isNumberKey(event);
Expand All @@ -76,7 +76,7 @@ describe("isNumberKey", () => {
}
);

test("Returns false when the event type is not a number key event", () => {
it("returns false when the event type is not a number key event", () => {
const event = { key: "a" } as KeyboardEvent;
const result = Events.isNumberKey(event);

Expand All @@ -85,14 +85,14 @@ describe("isNumberKey", () => {
});

describe("isLeftKey", () => {
test("Returns false when the event type is not a left key event", () => {
it("returns false when the event type is not a left key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isLeftKey(event);

expect(result).toBeFalsy();
});

test("Returns true when the event type is a left key event", () => {
it("returns true when the event type is a left key event", () => {
const event = { key: "ArrowLeft" } as KeyboardEvent;
const result = Events.isLeftKey(event);

Expand All @@ -101,14 +101,14 @@ describe("isLeftKey", () => {
});

describe("isUpKey", () => {
test("Returns true when the event type is an up key event", () => {
it("returns true when the event type is an up key event", () => {
const event = { key: "ArrowUp" } as KeyboardEvent;
const result = Events.isUpKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not an up key event", () => {
it("returns false when the event type is not an up key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isUpKey(event);

Expand All @@ -117,14 +117,14 @@ describe("isUpKey", () => {
});

describe("isRightKey", () => {
test("Returns true when the event type is a right key event", () => {
it("returns true when the event type is a right key event", () => {
const event = { key: "ArrowRight" } as KeyboardEvent;
const result = Events.isRightKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a right key event", () => {
it("returns false when the event type is not a right key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isRightKey(event);

Expand All @@ -133,14 +133,14 @@ describe("isRightKey", () => {
});

describe("isDownKey", () => {
test("Returns true when the event type is a down key event", () => {
it("returns true when the event type is a down key event", () => {
const event = { key: "ArrowDown" } as KeyboardEvent;
const result = Events.isDownKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a down key event", () => {
it("returns false when the event type is not a down key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isDownKey(event);

Expand All @@ -149,14 +149,14 @@ describe("isDownKey", () => {
});

describe("isEscKey", () => {
test("Returns true when the event type is an Escape key event", () => {
it("returns true when the event type is an Escape key event", () => {
const event = { key: "Escape" } as KeyboardEvent;
const result = Events.isEscKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not an Escape key event", () => {
it("returns false when the event type is not an Escape key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isEscKey(event);

Expand All @@ -165,14 +165,14 @@ describe("isEscKey", () => {
});

describe("isEnterKey", () => {
test("Returns true when the event type is an Enter key event", () => {
it("returns true when the event type is an Enter key event", () => {
const event = { key: "Enter" } as KeyboardEvent;
const result = Events.isEnterKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not an Enter key event", () => {
it("returns false when the event type is not an Enter key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isEnterKey(event);

Expand All @@ -181,14 +181,14 @@ describe("isEnterKey", () => {
});

describe("isTabKey", () => {
test("Returns true when the event type is a Tab key event", () => {
it("returns true when the event type is a Tab key event", () => {
const event = { key: "Tab" } as KeyboardEvent;
const result = Events.isTabKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a Tab key event", () => {
it("returns false when the event type is not a Tab key event", () => {
const event = { key: "Backspace" } as KeyboardEvent;
const result = Events.isTabKey(event);

Expand All @@ -197,14 +197,14 @@ describe("isTabKey", () => {
});

describe("isShiftKey", () => {
test("Returns true when the event type is a Shift key event", () => {
it("returns true when the event type is a Shift key event", () => {
const event = { shiftKey: true } as KeyboardEvent;
const result = Events.isShiftKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a Shift key event", () => {
it("returns false when the event type is not a Shift key event", () => {
const event = { key: "Tab" } as KeyboardEvent;
const result = Events.isShiftKey(event);

Expand All @@ -213,14 +213,14 @@ describe("isShiftKey", () => {
});

describe("isSpaceKey", () => {
test("Returns true when the event type is a Space key event", () => {
it("returns true when the event type is a Space key event", () => {
const event = { key: " " } as KeyboardEvent;
const result = Events.isSpaceKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a Space key event", () => {
it("returns false when the event type is not a Space key event", () => {
const event = { key: "Tab" } as KeyboardEvent;
const result = Events.isSpaceKey(event);

Expand All @@ -229,14 +229,14 @@ describe("isSpaceKey", () => {
});

describe("isHomeKey", () => {
test("Returns true when the event type is a Home key event", () => {
it("returns true when the event type is a Home key event", () => {
const event = { key: "Home" } as KeyboardEvent;
const result = Events.isHomeKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not a Home key event", () => {
it("returns false when the event type is not a Home key event", () => {
const event = { key: "End" } as KeyboardEvent;
const result = Events.isHomeKey(event);

Expand All @@ -245,14 +245,14 @@ describe("isHomeKey", () => {
});

describe("isEndKey", () => {
test("Returns true when the event type is an End key event", () => {
it("returns true when the event type is an End key event", () => {
const event = { key: "End" } as KeyboardEvent;
const result = Events.isEndKey(event);

expect(result).toBeTruthy();
});

test("Returns false when the event type is not an End key event", () => {
it("returns false when the event type is not an End key event", () => {
const event = { key: "Home" } as KeyboardEvent;
const result = Events.isEndKey(event);

Expand All @@ -261,28 +261,28 @@ describe("isEndKey", () => {
});

describe("composedPath", () => {
test("Returns an empty array if there is no target", () => {
it("returns an empty array if there is no target", () => {
const event = new CustomEvent("click");
const result = Events.composedPath(event);

expect(result).toEqual([]);
});

test("Returns an empty array if target is null", () => {
it("returns an empty array if target is null", () => {
const event = { target: null } as CustomEvent;
const result = Events.composedPath(event);

expect(result).toEqual([]);
});

test("Returns an empty array if there is no parent element", () => {
it("returns an empty array if there is no parent element", () => {
const event = { target: document as EventTarget } as CustomEvent;
const result = Events.composedPath(event);

expect(result).toEqual([]);
});

test("Returns the path from event.composedPath() if it is available", () => {
it("returns the path from event.composedPath() if it is available", () => {
const path = Symbol("path");
const composedPath = jest.fn();
composedPath.mockReturnValue(path);
Expand All @@ -294,7 +294,7 @@ describe("composedPath", () => {
expect(result).toBe(path);
});

test("Builds path from DOM elements if event.composedPath is unavailable", () => {
it("builds path from DOM elements if event.composedPath is unavailable", () => {
const div = document.createElement("div");
const ul = document.createElement("ul");
const li = document.createElement("li");
Expand All @@ -311,7 +311,7 @@ describe("composedPath", () => {

/* TODO: FE-6826 Investigate if `composedPath` is still required post removal of Enzyme. */

test("Builds the path if it is not available on the element from a ReactWrapper", () => {
it("builds the path if it is not available on the element from a ReactWrapper", () => {
const div = document.createElement("div");
const ul = document.createElement("ul");
const li = document.createElement("li");
Expand Down
Loading

0 comments on commit 8e180b9

Please sign in to comment.