From e1c06eda1ed734edbade22a4bebfddbfecad4f52 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Sat, 31 Aug 2019 16:52:08 +0900 Subject: [PATCH] Add unit test for organisms/ProjectCreationForm --- .../organisms/ProjectCreationForm.vue | 5 ++ .../organisms/ProjecCreationForm.spec.js | 57 +++++++++++++ frontend/yarn.lock | 79 +++++++++++-------- 3 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 frontend/test/unit/components/organisms/ProjecCreationForm.spec.js diff --git a/frontend/components/organisms/ProjectCreationForm.vue b/frontend/components/organisms/ProjectCreationForm.vue index 6b83430a..a25c468e 100644 --- a/frontend/components/organisms/ProjectCreationForm.vue +++ b/frontend/components/organisms/ProjectCreationForm.vue @@ -10,6 +10,7 @@ :rules="nameRules" label="Project name" prepend-icon="mdi-account-multiple" + data-test="project-name" required autofocus /> @@ -18,6 +19,7 @@ :rules="descriptionRules" label="Description" prepend-icon="mdi-clipboard-text" + data-test="project-description" required /> @@ -35,6 +38,7 @@ class="text-capitalize" text color="primary" + data-test="cancel-button" @click="cancel" > Cancel @@ -43,6 +47,7 @@ :disabled="!valid" class="text-none" text + data-test="create-button" @click="create" > Create diff --git a/frontend/test/unit/components/organisms/ProjecCreationForm.spec.js b/frontend/test/unit/components/organisms/ProjecCreationForm.spec.js new file mode 100644 index 00000000..31d5464e --- /dev/null +++ b/frontend/test/unit/components/organisms/ProjecCreationForm.spec.js @@ -0,0 +1,57 @@ +import { shallowMount } from '@vue/test-utils' +import Vue from 'vue' +import Vuetify from 'vuetify' +import ProjectCreationForm from '@/components/organisms/ProjectCreationForm' + +Vue.use(Vuetify) + +describe('ProjectCreationForm', () => { + const factory = (propsData) => { + return shallowMount(ProjectCreationForm, { + propsData: { + ...propsData + } + }) + } + const createProject = () => { } + const projectTypes = [] + + test('can receive props', () => { + const wrapper = factory({ createProject, projectTypes }) + expect(wrapper.props()).toEqual({ createProject, projectTypes }) + }) + + test('emit close event', () => { + const wrapper = factory({ createProject, projectTypes }) + wrapper.vm.cancel() + expect(wrapper.emitted('close')).toBeTruthy() + }) + + test('emit close event when form is valid', () => { + const wrapper = factory({ createProject, projectTypes }) + wrapper.vm.$refs.form = {} // Todo: need more elegant solution + wrapper.vm.$refs.form.validate = () => (true) + wrapper.vm.$refs.form.reset = () => { } + wrapper.vm.create() + expect(wrapper.emitted('close')).toBeTruthy() + }) + + test('do not emit close event when form is invalid', () => { + const wrapper = factory({ createProject, projectTypes }) + wrapper.vm.$refs.form = {} // Todo: need more elegant solution + wrapper.vm.$refs.form.validate = () => (false) + wrapper.vm.$refs.form.reset = () => { } + wrapper.vm.create() + expect(wrapper.emitted('close')).toBeFalsy() + }) + + test('raise warning when passing no props', () => { + const spy = jest.spyOn(console, 'error') + spy.mockImplementation() + const wrapper = factory() + expect(spy).toBeCalledWith( + expect.stringContaining('[Vue warn]: Missing required prop') + ) + spy.mockRestore() + }) +}) diff --git a/frontend/yarn.lock b/frontend/yarn.lock index f7be32aa..3d768fb9 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1128,15 +1128,16 @@ http-proxy-middleware "^0.19.1" "@nuxtjs/vuetify@^1.0.2": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@nuxtjs/vuetify/-/vuetify-1.2.1.tgz#a8de3c111bea4a52488e780877da6bd068c87bb1" - integrity sha512-oDiL6O1LSyiwSDs2hVZ7rwM9KMht/yPYDMhdOL+oP3RWCfcsgk2kYZrbFNKf23U5ZVzVDVjwbDX/hFOno/F7QA== + version "1.6.1" + resolved "https://registry.yarnpkg.com/@nuxtjs/vuetify/-/vuetify-1.6.1.tgz#b80a67438331d19f5495f6beeecd571b2b5274f2" + integrity sha512-I/WgpuulIDOg6ocl5yA7ETyD3oVEYx2ZmXN97axItxgP2nqD77oJxaxb1TKaK1R2kMbpXTGgeGoLZyo1ZRajvA== dependencies: + consola "^2.10.1" deepmerge "^4.0.0" fibers "^4.0.1" - sass "^1.22.9" - sass-loader "^7.1.0" - vuetify "^2.0.5" + sass "^1.22.10" + sass-loader "^8.0.0" + vuetify "^2.0.11" vuetify-loader "^1.3.0" "@nuxtjs/youch@^4.2.3": @@ -1689,9 +1690,9 @@ anymatch@^2.0.0: normalize-path "^2.1.1" anymatch@^3.0.1: - version "3.0.3" - resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.0.3.tgz#2fb624fe0e84bccab00afee3d0006ed310f22f09" - integrity sha512-c6IvoeBECQlMVuYUjSwimnhmztImpErfxJzWZhIQinIvQWoGOnB0dLIgifbPHQt5heS6mNlaZG16f06H3C8t1g== + version "3.1.0" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.0.tgz#e609350e50a9313b472789b2f14ef35808ee14d6" + integrity sha512-Ozz7l4ixzI7Oxj2+cw+p0tVUt27BpaJ+1+q1TCeANWxHpvyn2+Un+YamBdfKu0uh8xLodGhoa1v7595NhKDAuA== dependencies: normalize-path "^3.0.0" picomatch "^2.0.4" @@ -2756,6 +2757,11 @@ connect@^3.6.6, connect@^3.7.0: parseurl "~1.3.3" utils-merge "1.0.1" +consola@^2.10.1: + version "2.10.1" + resolved "https://registry.yarnpkg.com/consola/-/consola-2.10.1.tgz#4693edba714677c878d520e4c7e4f69306b4b927" + integrity sha512-4sxpH6SGFYLADfUip4vuY65f/gEogrzJoniVhNUYkJHtng0l8ZjnDCqxxrSVRHOHwKxsy8Vm5ONZh1wOR3/l/w== + consola@^2.3.0, consola@^2.5.6, consola@^2.6.0, consola@^2.7.1, consola@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/consola/-/consola-2.9.0.tgz#57760e3a65a53ec27337f4add31505802d902278" @@ -5952,7 +5958,7 @@ loader-utils@^0.2.16: json5 "^0.5.0" object-assign "^4.0.1" -loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.0, loader-utils@^1.2.3: +loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.0, loader-utils@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.2.3.tgz#1ff5dc6911c9f0a062531a4c04b609406108c2c7" integrity sha512-fkpz8ejdnEMG3s37wGL07iSBDg99O9D5yflE9RGNH3hRdx9SOwYfnGYdZOUIZitN8E+E2vkq3MUMYMvPYl5ZZA== @@ -8098,9 +8104,9 @@ readdirp@^2.2.1: readable-stream "^2.0.2" readdirp@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.1.1.tgz#b158123ac343c8b0f31d65680269cc0fc1025db1" - integrity sha512-XXdSXZrQuvqoETj50+JAitxz1UPdt5dupjT6T5nVB+WvjMv2XKYj+s7hPeAVCXvmJrL36O4YYyWlIC3an2ePiQ== + version "3.1.2" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.1.2.tgz#fa85d2d14d4289920e4671dead96431add2ee78a" + integrity sha512-8rhl0xs2cxfVsqzreYCvs8EwBfn/DhVdqtoLmw19uI3SC5avYX9teCurlErfpPXGmYtMHReGaP2RsLnFvz/lnw== dependencies: picomatch "^2.0.4" @@ -8440,21 +8446,21 @@ sane@^4.0.3: minimist "^1.1.1" walker "~1.0.5" -sass-loader@^7.1.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-7.2.0.tgz#e34115239309d15b2527cb62b5dfefb62a96ff7f" - integrity sha512-h8yUWaWtsbuIiOCgR9fd9c2lRXZ2uG+h8Dzg/AGNj+Hg/3TO8+BBAW9mEP+mh8ei+qBKqSJ0F1FLlYjNBc61OA== +sass-loader@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-8.0.0.tgz#e7b07a3e357f965e6b03dd45b016b0a9746af797" + integrity sha512-+qeMu563PN7rPdit2+n5uuYVR0SSVwm0JsOUsaJXzgYcClWSlmX0iHDnmeOobPkf5kUglVot3QS6SyLyaQoJ4w== dependencies: clone-deep "^4.0.1" - loader-utils "^1.0.1" - neo-async "^2.5.0" - pify "^4.0.1" - semver "^5.5.0" + loader-utils "^1.2.3" + neo-async "^2.6.1" + schema-utils "^2.1.0" + semver "^6.3.0" -sass@^1.22.9: - version "1.22.9" - resolved "https://registry.yarnpkg.com/sass/-/sass-1.22.9.tgz#41a2ed6038027f58be2bd5041293452a29c2cb84" - integrity sha512-FzU1X2V8DlnqabrL4u7OBwD2vcOzNMongEJEx3xMEhWY/v26FFR3aG0hyeu2T965sfR0E9ufJwmG+Qjz78vFPQ== +sass@^1.22.10: + version "1.22.10" + resolved "https://registry.yarnpkg.com/sass/-/sass-1.22.10.tgz#b9f01440352ba0be5d99fa64a2040b035cc6e5ff" + integrity sha512-DUpS1tVMGCH6gr/N9cXCoemrjoNdOLhAHfQ37fJw2A5ZM4gSI9ej/8Xi95Xwus03RqZ2zdSnKZGULL7oS+jfMA== dependencies: chokidar ">=2.0.0 <4.0.0" @@ -8477,6 +8483,14 @@ schema-utils@^1.0.0: ajv-errors "^1.0.0" ajv-keywords "^3.1.0" +schema-utils@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.1.0.tgz#940363b6b1ec407800a22951bdcc23363c039393" + integrity sha512-g6SViEZAfGNrToD82ZPUjq52KUPDYc+fN5+g6Euo5mLokl/9Yx14z0Cu4RR1m55HtBXejO0sBt+qw79axN+Fiw== + dependencies: + ajv "^6.1.0" + ajv-keywords "^3.1.0" + scriptjs@^2.5.9: version "2.5.9" resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.9.tgz#343915cd2ec2ed9bfdde2b9875cd28f59394b35f" @@ -8504,7 +8518,7 @@ semver@^5.5.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@^6.0.0, semver@^6.1.0, semver@^6.1.1: +semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.3.0: version "6.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== @@ -9809,15 +9823,10 @@ vuetify-loader@^1.3.0: dependencies: loader-utils "^1.2.0" -vuetify@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-2.0.2.tgz#370916d7e563e84e15dff9eccf24980c61b01e09" - integrity sha512-cg7zChvouAYlRhkz3g8A5B/MAOxZYmrq9fksHnWZ1Rs4ZmRwoNs5Kgexp8qaw3dxDs6cRkY7+1NaHuFc/+U0dA== - -vuetify@^2.0.5: - version "2.0.5" - resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-2.0.5.tgz#3e9cd992bed2f4013bfcfc045ff2e301deb3272d" - integrity sha512-t2JNarqqJRzOEtNg2nP9U5EFU4jR6unA8RIiqBGb3pjSCaTxwHzu5H3wkcBh/NM3y6fd40EuIS+SkFejwGD6RQ== +vuetify@^2.0.11, vuetify@^2.0.2: + version "2.0.11" + resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-2.0.11.tgz#4679d6d37e4594daec930b28f1bc7083bcc76ca6" + integrity sha512-H5g0Wf/KHS1t29X+kh5hkj25dZNITCDtOb3UGl1YXx5Ua3xXUfXBRjKP50BJ7uZtQ3Jk9CiwoA6k3Lstv6zFow== vuex@^3.1.1: version "3.1.1"