From 854d2adfca693c2f7c00211f7debf0a28470c874 Mon Sep 17 00:00:00 2001 From: lana-k Date: Wed, 3 Mar 2021 22:33:57 +0100 Subject: [PATCH] add test to DbUpload check that it doesn't redirect to /editor if it's already there --- tests/unit/components/DbUpload.spec.js | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/unit/components/DbUpload.spec.js b/tests/unit/components/DbUpload.spec.js index 1810a9f..5f7089b 100644 --- a/tests/unit/components/DbUpload.spec.js +++ b/tests/unit/components/DbUpload.spec.js @@ -28,7 +28,7 @@ describe('DbUploader.vue', () => { // mock router const $router = { push: sinon.stub() } - const $route = { puth: '/' } + const $route = { path: '/' } // mount the component const wrapper = shallowMount(DbUpload, { @@ -57,7 +57,7 @@ describe('DbUploader.vue', () => { // mock router const $router = { push: sinon.stub() } - const $route = { puth: '/' } + const $route = { path: '/' } // mount the component const wrapper = shallowMount(DbUpload, { @@ -79,4 +79,30 @@ describe('DbUploader.vue', () => { expect(mutations.saveSchema.calledOnceWith(state, schema)).to.equal(true) expect($router.push.calledOnceWith('/editor')).to.equal(true) }) + + it("doesn't redirect if already on /editor", async () => { + // mock store state and mutations + const state = {} + const mutations = { + saveSchema: sinon.stub() + } + const store = new Vuex.Store({ state, mutations }) + + // mock db loading + const schema = {} + const $db = { loadDb: sinon.stub().resolves(schema) } + + // mock router + const $router = { push: sinon.stub() } + const $route = { path: '/' } + + // mount the component + const wrapper = shallowMount(DbUpload, { + store, + mocks: { $db, $router, $route } + }) + + await wrapper.find('.drop-area').trigger('click') + expect($router.push.called).to.equal(false) + }) })