Skip to content

Commit

Permalink
fix: do not move tabs out when all selected
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Jun 17, 2019
1 parent f6d325f commit d840e32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const withCommandContext = (fn: (...args: any[]) => void) => async () => {
export const commandActions = {
[COMMANDS.OUT]: withCommandContext(
async ({ windowId, selectedTabs: tabs, isAllTabsSelected }) => {
const from = isAllTabsSelected ? null : (windowId as number);
await handleAction(moveTabs({ tabs, from }));
if (isAllTabsSelected) return;
await handleAction(moveTabs({ tabs, from: windowId }));
},
),
[COMMANDS.NEXT]: withCommandContext(
Expand Down
35 changes: 19 additions & 16 deletions tests/background/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ describe("background", () => {
});

const expectedArgs = {
[COMMANDS.OUT]: [
moveTabs({ tabs: selectedTabs, from: 1 }),
moveTabs({ tabs: mockTabs, from: null }),
],
[COMMANDS.NEXT]: [
moveTabs({ tabs: selectedTabs, from: 1, to: 100 }),
moveTabs({ tabs: mockTabs, from: null, to: 100 }),
],
[COMMANDS.PREV]: [
moveTabs({ tabs: selectedTabs, from: 1, to: 99 }),
moveTabs({ tabs: mockTabs, from: null, to: 99 }),
],
[COMMANDS.BACK]: [undo(), undo()],
[COMMANDS.OUT]: {
some: moveTabs({ tabs: selectedTabs, from: 1 }),
},
[COMMANDS.NEXT]: {
all: moveTabs({ tabs: mockTabs, from: null, to: 100 }),
some: moveTabs({ tabs: selectedTabs, from: 1, to: 100 }),
},
[COMMANDS.PREV]: {
all: moveTabs({ tabs: mockTabs, from: null, to: 99 }),
some: moveTabs({ tabs: selectedTabs, from: 1, to: 99 }),
},
[COMMANDS.BACK]: { all: undo(), some: undo() },
};

it.each(Object.values(COMMANDS).map(v => [v]))(
Expand All @@ -53,7 +52,7 @@ describe("background", () => {
const commandSpy = jest.spyOn(commandActions, command);
await commandListener(command);
expect(commandSpy).toHaveBeenCalledTimes(1);
const [expected] = expectedArgs[command];
const expected = expectedArgs[command].some;
expect(handleActionSpy).toHaveBeenCalledWith(expected);
commandSpy.mockRestore();
},
Expand All @@ -66,8 +65,12 @@ describe("background", () => {
selectedTabsSpy.mockResolvedValueOnce(mockTabs);
await commandListener(command);
expect(commandSpy).toHaveBeenCalledTimes(1);
const [, expected] = expectedArgs[command];
expect(handleActionSpy).toHaveBeenCalledWith(expected);
const expected = expectedArgs[command].all;
if (!expected) {
expect(handleActionSpy).not.toHaveBeenCalled();
} else {
expect(handleActionSpy).toHaveBeenCalledWith(expected);
}
commandSpy.mockRestore();
},
);
Expand Down

0 comments on commit d840e32

Please sign in to comment.