Skip to content

Commit

Permalink
best tests thank you nmanu1
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaing committed Oct 24, 2023
1 parent 401f4aa commit a576979
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/studio-ui/src/components/UndoRedo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function UndoRedo(): JSX.Element {

const handleUndoKeydown = useCallback(
(event: KeyboardEvent) => {
const actionKey = ["OS X", "Darwin"].includes(platform.os.family)
const actionKey = platform.os.family === "OS X"
? event.metaKey
: event.ctrlKey;
if (actionKey && event.key === "z") {
Expand Down
29 changes: 24 additions & 5 deletions packages/studio-ui/tests/components/UndoRedo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { searchBarComponent } from "../__fixtures__/componentStates";
import mockStore from "../__utils__/mockStore";
import platform from "platform";

jest.mock("platform", () => ({
__esModule: true,
default: {
os: {
family: null
}
}
}))

describe("Undo/redo", () => {
beforeEach(() => {
jest.useFakeTimers();
Expand Down Expand Up @@ -47,15 +56,25 @@ describe("Undo/redo", () => {
expect(useStudioStore.getState().pages.activeComponentUUID).toBeUndefined();
});

it("undoes last state update using control/command + z", async () => {
const actionKey = ["OS X", "Darwin"].includes(platform.os.family)
? "Meta"
: "Control";
it("undoes last state update using control + z", async () => {
platform.os.family = "Windows"

render(<UndoRedo />);
expect(useStudioStore.getState().pages.activeComponentUUID).toBe(
"searchbar-uuid"
);
await userEvent.keyboard("{Control>}z{/Control}");
expect(useStudioStore.getState().pages.activeComponentUUID).toBeUndefined();
});

it("undoes last state update using command + z", async () => {
platform.os.family = "OS X"

render(<UndoRedo />);
expect(useStudioStore.getState().pages.activeComponentUUID).toBe(
"searchbar-uuid"
);
await userEvent.keyboard(`{${actionKey}>}z{/${actionKey}}`);
await userEvent.keyboard("{Meta>}z{/Meta}");
expect(useStudioStore.getState().pages.activeComponentUUID).toBeUndefined();
});

Expand Down

0 comments on commit a576979

Please sign in to comment.