From 3bd680802264ee3f6d8e8dede670efb4d8de9878 Mon Sep 17 00:00:00 2001 From: donal <donalspring@gmail.com> Date: Sun, 22 Apr 2018 13:50:55 +0200 Subject: [PATCH] FIX - linting errors for the build --- tests/unit/javascript/actions.spec.js | 105 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 71 insertions(+), 34 deletions(-) diff --git a/tests/unit/javascript/actions.spec.js b/tests/unit/javascript/actions.spec.js index 8153743..554057f 100644 --- a/tests/unit/javascript/actions.spec.js +++ b/tests/unit/javascript/actions.spec.js @@ -1,14 +1,13 @@ import actions from "@/store/actions"; -import store from "@/store"; -import * as all from "../setup.js"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import sinon from "sinon"; const todos = [ - { id: 1, title: "learn testing", completed: true }, - { id: 2, title: "learn testing 2", completed: false } + { _id: 1, title: "learn testing", completed: true }, + { _id: 2, title: "learn testing 2", completed: false } ]; +let state; describe("loadTodos", () => { beforeEach(() => { @@ -41,36 +40,6 @@ }); }); -/* - addTodo({ commit, state }) { - if (!state.newTodo) { - // do not add empty todos - return; - } - // debugger - const todo = { - title: state.newTodo, - completed: false, - important: false - }; - axios - .post(config.todoEndpoint, todo) - .then(mongoTodo => { - commit("ADD_TODO", mongoTodo.data); - }) - .catch(err => { - if (err) { - console.info("INFO - Adding dummy todo because of ", err); - let mongoTodo = todo; - mongoTodo._id = "fake-todo-item-" + Math.random(); - commit("ADD_TODO", mongoTodo); - } - }); - }, - -*/ - -let state; describe("addTodos", () => { beforeEach(() => { state = {}; @@ -97,3 +66,71 @@ }); }); }); + +describe("setNewTodo", () => { + it("should call SET_NEW_TODO", () => { + const commit = sinon.spy(); + actions.setNewTodo({ commit, todo: "learn stuff about mockin" }); + expect(commit.firstCall.args[0]).toBe("SET_NEW_TODO"); + }); +}); + +describe("clearNewTodo", () => { + it("should call CLEAR_NEW_TODO", () => { + const commit = sinon.spy(); + actions.clearNewTodo({ commit }); + expect(commit.firstCall.args[0]).toBe("CLEAR_NEW_TODO"); + }); +}); + +describe("clearTodos", () => { + it("should call CLEAR_ALL_TODOS when all is true", () => { + const commit = sinon.spy(); + state.todos = todos; + actions.clearTodos({ commit, state }, true); + expect(commit.firstCall.args[0]).toBe("CLEAR_ALL_TODOS"); + }); + + it("should call CLEAR_ALL_DONE_TODOS when all is not passed", () => { + const commit = sinon.spy(); + state.todos = todos; + actions.clearTodos({ commit, state }); + expect(commit.firstCall.args[0]).toBe("CLEAR_ALL_DONE_TODOS"); + }); +}); + +describe("updateTodo", () => { + beforeEach(() => { + state = {}; + let mock = new MockAdapter(axios); + mock.onPut("http://localhost:9000/api/todos/1").reply(200, todos); + }); + it("should call commit to the mutation function once", done => { + const commit = sinon.spy(); + state.todos = todos; + actions.updateTodo({ commit, state }, { id: 1 }).then(() => { + expect(commit.calledOnce).toBe(true); + done(); + }); + }); + it("should call MARK_TODO_COMPLETED", done => { + const commit = sinon.spy(); + state.todos = todos; + actions.updateTodo({ commit, state }, { id: 1 }).then(() => { + // console.log(commit.firstCall.args[0]) + expect(commit.firstCall.args[0]).toBe("MARK_TODO_COMPLETED"); + done(); + }); + }); + it("should call MARK_TODO_IMPORTANT", done => { + const commit = sinon.spy(); + state.todos = todos; + actions + .updateTodo({ commit, state }, { id: 1, important: true }) + .then(() => { + // TODO - test goes here! + + done(); + }); + }); +}); -- Gitblit v1.9.3