From 6623f1dab8fff3e5cd750f20c63ccd40fccaf4b5 Mon Sep 17 00:00:00 2001 From: Raphael Beer Date: Sun, 12 Apr 2020 02:23:01 +0200 Subject: [PATCH] Review: clean and comment tests --- webapp/components/Editor/Editor.spec.js | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/webapp/components/Editor/Editor.spec.js b/webapp/components/Editor/Editor.spec.js index b4d9510d9..976c6bd93 100644 --- a/webapp/components/Editor/Editor.spec.js +++ b/webapp/components/Editor/Editor.spec.js @@ -35,7 +35,7 @@ describe('Editor.vue', () => { beforeEach(() => { propsData = {} mocks = { - $t: () => 'some cool placeholder', + $t: (t) => t, } wrapper = Wrapper() }) @@ -59,7 +59,7 @@ describe('Editor.vue', () => { it('translates the placeholder', () => { expect(wrapper.vm.editor.extensions.options.placeholder.emptyNodeText).toEqual( - 'some cool placeholder', + 'editor.placeholder', ) }) @@ -162,30 +162,27 @@ describe('Editor.vue', () => { afterAll(() => jest.useRealTimers()) describe('when false', () => { - let routerWrapper + const content = '

NOOP WIP

' - beforeEach(() => { - propsData = {} - mocks = { - $t: (key) => key, + beforeEach(async () => { + propsData = { + // + // plugin ignores all changes (transactions) on this instance + autosave: false, } - router = new VueRouter({ - routes: [{ path: 'post/create' }], - }) mocks = { - $t: (key) => key, + $t: (t) => t, } - router.push('/post/create') - propsData.autosave = false - routerWrapper = Wrapper() + + // testing against localStorage, so letting + // the editor do its thing without keeping + // a reference is enough + Wrapper().vm.editor.setContent(content, true) + + await jest.runAllTimers() }) it('does nothing', () => { - const content = '

NOOP WIP

' - - routerWrapper.vm.editor.setContent(content, true) - jest.runAllTimers() - expect(Object.keys(localStorage).length).toBe(0) }) }) @@ -194,10 +191,14 @@ describe('Editor.vue', () => { const content = '

Post WIP

' beforeEach(async () => { - propsData = {} - mocks = { - $t: (key) => key, + propsData = { + // :autosave defaults to true } + mocks = { + $t: (t) => t, + } + + // plugin creates storage ids from $route.path router = new VueRouter({ routes: [{ path: 'post/create' }], }) @@ -225,13 +226,12 @@ describe('Editor.vue', () => { beforeEach(async () => { propsData = {} mocks = { - $t: (key) => key, + $t: (t) => t, } router = new VueRouter({ routes: [{ path: `/post/${postId}/foo-title-slug` }], }) router.push(`/post/${postId}/foo-title-slug`) - Wrapper().vm.editor.setContent(content, true) await jest.runAllTimers() }) @@ -247,9 +247,9 @@ describe('Editor.vue', () => { }) it('loads an existing autosave', () => { - const { value: autoSaveHTML } = getFirstInStorage() + const { value: autosaveHTML } = getFirstInStorage() const _wrapper = Wrapper() - expect(_wrapper.vm.editor.getHTML()).toBe(autoSaveHTML) + expect(_wrapper.vm.editor.getHTML()).toBe(autosaveHTML) }) }) })