Skip to content

Commit

Permalink
Implement tests for #7 "clear" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbeng89 committed Aug 27, 2019
1 parent bb2cd0e commit 566a132
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/unit/test.basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from "vue";
import store from "../store";
import { undo, redo } from "./utils-test";
import { undo, redo, clear } from "./utils-test";

const item = {
foo: "bar"
Expand Down Expand Up @@ -95,4 +95,36 @@ describe("Simple testing for undo/redo on a namespaced vuex store", () => {
// Check shadow: should contain no items
expect(state.list.shadow).toEqual([]);
});

it('"clear" should return the state to an empty list', async () => {
await clear(store)("list");
const expectedState: [] = [];

expect(state.list.list).toEqual(expectedState);
});

it('"canUndo" and "canRedo" should be reset', () => {
expect(state.list.canUndo).toBeFalsy();
expect(state.list.canUndo).toBeFalsy();
});

it("Add item to list", () => {
const expectedState = [{ ...item }];

// Commit the item to the store and assert
store.commit("list/addItem", { item });

expect(state.list.list).toEqual(expectedState);
});

it("Check 'canUndo' value; The undo function should remove the item", async () => {
expect(state.list.canUndo).toBeTruthy();

await undo(store)("list");
await Vue.nextTick();

// Check 'canUndo' value, Assert list items after undo
expect(state.list.canUndo).toBeFalsy();
expect(state.list.list).toEqual([]);
});
});
5 changes: 5 additions & 0 deletions tests/unit/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ export const undo = (store: any) => async (namespace: string = "") => {
await store.dispatch(`${namespace ? `${namespace}/` : ""}undo`);
await Vue.nextTick();
};

export const clear = (store: any) => async (namespace: string = "") => {
await store.dispatch(`${namespace ? `${namespace}/` : ""}clear`);
await Vue.nextTick();
};

0 comments on commit 566a132

Please sign in to comment.