|
| 1 | +/** |
| 2 | + * Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +import { expect } from 'chai' |
| 19 | +import { createLocalVue, mount } from '@vue/test-utils' |
| 20 | +import Drawer from '../../../../src/components/cylc/Drawer' |
| 21 | + |
| 22 | +import Vue from 'vue' |
| 23 | +import Vuetify from 'vuetify' |
| 24 | +import Vuex from 'vuex' |
| 25 | + |
| 26 | +import sinon from 'sinon' |
| 27 | + |
| 28 | +Vue.use(Vuex) |
| 29 | +Vue.use(Vuetify) |
| 30 | + |
| 31 | +let vuetify |
| 32 | +let wrapper |
| 33 | + |
| 34 | +const mountFunction = options => { |
| 35 | + const localVue = createLocalVue() |
| 36 | + |
| 37 | + // note these are truly 'mocked' because I ran into issues with the state being tainted across multiple unit-tests |
| 38 | + const store = new Vuex.Store({ |
| 39 | + modules: { |
| 40 | + app: { |
| 41 | + namespaced: true, |
| 42 | + state: { |
| 43 | + drawer: {} |
| 44 | + }, |
| 45 | + mutations: { |
| 46 | + setDrawer (state, drawer) { |
| 47 | + state.drawer = drawer |
| 48 | + } |
| 49 | + } |
| 50 | + }, |
| 51 | + user: { |
| 52 | + namespaced: true, |
| 53 | + state: { |
| 54 | + user: { |
| 55 | + username: 'test username' |
| 56 | + } |
| 57 | + }, |
| 58 | + mutations: { |
| 59 | + SET_USER (state, user) { |
| 60 | + state.user = user |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + }) |
| 66 | + |
| 67 | + vuetify = new Vuetify() |
| 68 | + |
| 69 | + return mount(Drawer, { |
| 70 | + localVue, |
| 71 | + vuetify, |
| 72 | + store, |
| 73 | + mocks: { |
| 74 | + $t: () => { |
| 75 | + } |
| 76 | + }, |
| 77 | + stubs: { |
| 78 | + Header: true, |
| 79 | + GScan: true, |
| 80 | + RouterLink: true |
| 81 | + }, |
| 82 | + ...options |
| 83 | + }) |
| 84 | +} |
| 85 | + |
| 86 | +describe('Drawer', () => { |
| 87 | + it('should create the drawer and successfully trigger a resize', async () => { |
| 88 | + const createBubbledEvent = (type, props = {}) => { |
| 89 | + const event = new Event(type, { bubbles: true }) |
| 90 | + Object.assign(event, props) |
| 91 | + return event |
| 92 | + } |
| 93 | + const sandbox = sinon.createSandbox() |
| 94 | + wrapper = mountFunction() |
| 95 | + await wrapper.vm.$nextTick() |
| 96 | + expect(wrapper.find('div.d-flex.flex-column.h-100').exists()).to.equal(true) |
| 97 | + const spyFunction = sandbox.spy(wrapper.vm, 'resize') |
| 98 | + |
| 99 | + wrapper.find('div.v-navigation-drawer__border').element.dispatchEvent( |
| 100 | + createBubbledEvent('mousedown', { offsetX: 1 }) |
| 101 | + ) |
| 102 | + |
| 103 | + document.dispatchEvent( |
| 104 | + createBubbledEvent('mousemove', { clientX: 100, clientY: 0, offsetX: 50 }) |
| 105 | + ) |
| 106 | + |
| 107 | + document.dispatchEvent( |
| 108 | + createBubbledEvent('mouseup', { clientX: 100, clientY: 0, offsetX: 0 }) |
| 109 | + ) |
| 110 | + |
| 111 | + expect(spyFunction.called).to.equal(true) |
| 112 | + }) |
| 113 | +}) |
0 commit comments