From 355f03f413ac218248984758ae67e8873049ac79 Mon Sep 17 00:00:00 2001 From: David Braun Date: Mon, 5 Nov 2018 19:02:23 -0500 Subject: [PATCH 01/13] Create tests for PageProposalsNewText and wire up text proposal creation. --- .../govern/PageProposalsNewText.vue | 7 +- .../govern/PageProposalsNewText.spec.js | 46 +++++ .../PageProposalsNewText.spec.js.snap | 191 ++++++++++++++++++ 3 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 test/unit/specs/components/govern/PageProposalsNewText.spec.js create mode 100644 test/unit/specs/components/govern/__snapshots__/PageProposalsNewText.spec.js.snap diff --git a/app/src/renderer/components/govern/PageProposalsNewText.vue b/app/src/renderer/components/govern/PageProposalsNewText.vue index 0db0584960..e76043f6f5 100644 --- a/app/src/renderer/components/govern/PageProposalsNewText.vue +++ b/app/src/renderer/components/govern/PageProposalsNewText.vue @@ -68,9 +68,10 @@ export default { onSubmit() { this.$v.$touch() if (!this.$v.$error) { - this.$store.commit(`notify`, { - title: `TODO: Create Text Proposal`, - body: `You will have successfully created a text proposal` + this.$store.dispatch(`submitProposal`, { + description: this.fields.body, + proposal_type: `Text`, + title: this.fields.title }) this.resetForm() this.$router.push({ name: `proposals` }) diff --git a/test/unit/specs/components/govern/PageProposalsNewText.spec.js b/test/unit/specs/components/govern/PageProposalsNewText.spec.js new file mode 100644 index 0000000000..c8de1b1938 --- /dev/null +++ b/test/unit/specs/components/govern/PageProposalsNewText.spec.js @@ -0,0 +1,46 @@ +import PageProposalsNewText from "renderer/components/govern/PageProposalsNewText" +import Vuelidate from "vuelidate" +import { createLocalVue, mount } from "@vue/test-utils" + +describe(`PageProposalsNewText`, () => { + let $store + let wrapper + + beforeEach(() => { + const localVue = createLocalVue() + localVue.use(Vuelidate) + + $store = { + dispatch: jest.fn(), + getters: { lastPage: null, user: { history: [] } } + } + + wrapper = mount(PageProposalsNewText, { + localVue, + mocks: { + $router: [], + $store + } + }) + }) + + it(`has the expected HTML structure`, () => { + expect(wrapper.vm.$el).toMatchSnapshot() + }) + + it(`onSubmit`, () => { + wrapper.setData({ fields: { body: `description`, title: `proposaltitle` } }) + wrapper.vm.onSubmit() + + expect($store.dispatch.mock.calls).toEqual([ + [ + `submitProposal`, + { + description: `description`, + proposal_type: `Text`, + title: `proposaltitle` + } + ] + ]) + }) +}) diff --git a/test/unit/specs/components/govern/__snapshots__/PageProposalsNewText.spec.js.snap b/test/unit/specs/components/govern/__snapshots__/PageProposalsNewText.spec.js.snap new file mode 100644 index 0000000000..c822fa6d56 --- /dev/null +++ b/test/unit/specs/components/govern/__snapshots__/PageProposalsNewText.spec.js.snap @@ -0,0 +1,191 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`PageProposalsNewText has the expected HTML structure 1`] = ` +
+
+
+
+ + + +
+ +
+
+
+
+
+ + + arrow_back + + + + + arrow_back + + + + + help_outline + + + + + settings + + + + + exit_to_app + + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+ + +
+ +
+ Proposal Title is required +
+ +
+
+
+ + +
+