Skip to content

Commit

Permalink
test: undo limit
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Apr 20, 2019
1 parent d7dc67c commit e868ba3
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 854 deletions.
File renamed without changes.
774 changes: 6 additions & 768 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"./node_modules"
],
"setupFilesAfterEnv": [
"./tests/setup.ts"
"./config/setupTests.ts"
],
"testPathIgnorePatterns": [
"./artifacts/",
Expand Down Expand Up @@ -113,7 +113,6 @@
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
Expand All @@ -135,6 +134,7 @@
"eslint": "^5.16.0",
"husky": "^1.3.1",
"jest": "^24.1.0",
"jest-mock-props": "^1.0.4",
"lint-staged": "^8.1.5",
"prettier": "^1.17.0",
"prettier-eslint": "^8.8.2",
Expand Down
61 changes: 0 additions & 61 deletions tests/@extend/jest.ts

This file was deleted.

1 change: 1 addition & 0 deletions tests/@types/jest-mock-props.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "jest-mock-props";
13 changes: 0 additions & 13 deletions tests/@types/jest.d.ts

This file was deleted.

49 changes: 40 additions & 9 deletions tests/background/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as mockProps from "jest-mock-props";
mockProps.extend(jest);

import { moveTabs, undo } from "background/actions";
import * as constants from "background/constants";
import { handleAction } from "background/handler";
import { log } from "utils/base";
import * as chromeUtils from "utils/chrome";

const undoLimitSpy = jest.spyOnProp(constants, "UNDO_LIMIT").mockValue(2);
jest.spyOn(log, "error").mockImplementation(jest.fn());
const createWindowSpy = jest
.spyOn(chromeUtils, "createWindow")
Expand Down Expand Up @@ -43,7 +48,7 @@ describe("handler", () => {
to: targetWindowId,
});
await handleAction(moveAction);
expect(chromeUtils.moveTabsToWindow).toHaveBeenCalledWith(
expect(moveTabsToWindowSpy).toHaveBeenCalledWith(
mockTabs,
targetWindowId,
);
Expand All @@ -63,10 +68,7 @@ describe("handler", () => {
} as ChromeWindow);
await handleAction(moveAction);
expect(createWindowSpy).toHaveBeenCalledWith(null);
expect(chromeUtils.moveTabsToWindow).toHaveBeenCalledWith(
mockTabs,
newWindowId,
);
expect(moveTabsToWindowSpy).toHaveBeenCalledWith(mockTabs, newWindowId);
expect(chromeUtils.focusOnTab).toHaveBeenCalledWith(tabIds[0]);
expect(chromeUtils.selectTabs).toHaveBeenCalledWith(tabIds);
expect(chromeUtils.focusOnWindow).toHaveBeenCalledWith(newWindowId);
Expand All @@ -83,7 +85,7 @@ describe("handler", () => {
} as ChromeWindow);
await handleAction(moveAction);
expect(createWindowSpy).toHaveBeenCalledWith(activeTabId);
expect(chromeUtils.moveTabsToWindow).toHaveBeenCalledWith(
expect(moveTabsToWindowSpy).toHaveBeenCalledWith(
mockTabsActive,
newWindowId,
);
Expand All @@ -101,7 +103,7 @@ describe("handler", () => {
const mockError = new Error("move failed");
moveTabsToWindowSpy.mockRejectedValueOnce(mockError);
await handleAction(moveAction);
expect(chromeUtils.moveTabsToWindow).toHaveBeenCalledWith(
expect(moveTabsToWindowSpy).toHaveBeenCalledWith(
mockTabs,
targetWindowId,
);
Expand All @@ -118,8 +120,8 @@ describe("handler", () => {
to: targetWindowId,
});
await handleAction(moveAction).then(() => handleAction(undo()));
expect(chromeUtils.moveTabsToWindow).toHaveBeenCalledTimes(2);
expect(chromeUtils.moveTabsToWindow).toHaveBeenLastCalledWith(
expect(moveTabsToWindowSpy).toHaveBeenCalledTimes(2);
expect(moveTabsToWindowSpy).toHaveBeenLastCalledWith(
mockTabs,
sourceWindowId,
);
Expand All @@ -132,4 +134,33 @@ describe("handler", () => {
sourceWindowId,
);
});

it("undoes only up to limit", async () => {
const moveAction = moveTabs({
from: sourceWindowId,
tabs: mockTabs,
to: targetWindowId,
});
const doMove = () => handleAction(moveAction);
const undoMove = () => handleAction(undo());
await doMove()
.then(doMove)
.then(doMove);
expect(moveTabsToWindowSpy).toHaveBeenCalledTimes(3);
expect(moveTabsToWindowSpy).toHaveBeenLastCalledWith(
mockTabs,
targetWindowId,
);
expect(chromeUtils.focusOnTab).toHaveBeenLastCalledWith(tabIds[0]);
moveTabsToWindowSpy.mockClear();
await undoMove()
.then(undoMove)
.then(undoMove);
expect(moveTabsToWindowSpy).toHaveBeenCalledTimes(2);
expect(moveTabsToWindowSpy).toHaveBeenLastCalledWith(
mockTabs,
sourceWindowId,
);
undoLimitSpy.mockReset();
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": { "*": ["*", "../tests/*", "../tests/@types/*"] },
"moduleResolution": "node",
"outDir": "./built",
"target": "es6",
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit e868ba3

Please sign in to comment.