diff --git a/src/qComponents/QPopover/QPopover.test.js b/src/qComponents/QPopover/QPopover.test.js new file mode 100644 index 00000000..8dfeb4e7 --- /dev/null +++ b/src/qComponents/QPopover/QPopover.test.js @@ -0,0 +1,100 @@ +import Component from './index'; + +describe('QPopover', () => { + const options = { + slots: { + reference: '' + } + }; + + it('should match snapshot', () => { + const { element } = shallowMount(Component, options); + expect(element).toMatchSnapshot(); + }); + + it('data should match snapshot', () => { + expect(Component.data()).toMatchSnapshot(); + }); + + describe('computed', () => { + describe('popoverClasses', () => { + it('should return expected value if icon does not exist', () => { + const instance = shallowMount(Component, options); + instance.setProps({ + icon: '' + }); + const expected = { + 'q-popover_without-icon': true + }; + expect(instance.vm.popoverClasses).toEqual(expected); + }); + + it('should return expected value if icon exists', () => { + const instance = shallowMount(Component, options); + instance.setProps({ + icon: 'icon-name' + }); + const expected = { + 'q-popover_without-icon': false + }; + expect(instance.vm.popoverClasses).toEqual(expected); + }); + }); + }); + + describe('methods', () => { + describe('togglePopover', () => { + it('should set isPopoverShown to false', () => { + const instance = shallowMount(Component, options); + instance.setData({ + isPopoverShown: true + }); + instance.vm.togglePopover(); + expect(instance.vm.isPopoverShown).toBeFalsy(); + }); + + it('should set isPopoverShown to true', () => { + const instance = shallowMount(Component, options); + instance.setData({ + isPopoverShown: false + }); + instance.vm.togglePopover(); + expect(instance.vm.isPopoverShown).toBeTruthy(); + }); + }); + + describe('destroy', () => { + it('should set isPopoverShown to false', () => { + const instance = shallowMount(Component, options); + instance.setData({ + isPopoverShown: true + }); + instance.vm.destroy(); + expect(instance.vm.isPopoverShown).toBeFalsy(); + }); + + it('should call destroy', () => { + const instance = shallowMount(Component, options); + const spy = jest.fn(() => {}); + instance.setData({ + popperJS: { + destroy: spy + } + }); + instance.vm.destroy(); + expect(spy).toBeCalled(); + }); + + it('should set popperJS to null', () => { + const instance = shallowMount(Component, options); + instance.setData({ + popperJS: { + destroy: () => {} + } + }); + instance.vm.destroy(); + expect(instance.vm.popperJS).toBeNull(); + }); + }); + }); +}); diff --git a/src/qComponents/QPopover/__snapshots__/QPopover.test.js.snap b/src/qComponents/QPopover/__snapshots__/QPopover.test.js.snap new file mode 100644 index 00000000..9c1becdb --- /dev/null +++ b/src/qComponents/QPopover/__snapshots__/QPopover.test.js.snap @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`QPopover data should match snapshot 1`] = ` +Object { + "isPopoverShown": false, + "popperJS": null, + "referenceElement": null, + "zIndex": null, +} +`; + +exports[`QPopover should match snapshot 1`] = ` + + + + + + + +`; diff --git a/src/qComponents/QTable/QTable.test.js b/src/qComponents/QTable/QTable.test.js new file mode 100644 index 00000000..24a75de2 --- /dev/null +++ b/src/qComponents/QTable/QTable.test.js @@ -0,0 +1,29 @@ +import Component from './index'; + +describe('QTable', () => { + const options = { + propsData: { + groupsOfColumns: [ + { + columns: [ + { + key: 'col1', + value: 'Column 1' + } + ] + } + ], + rows: [ + { + col1: 'Columns row 1' + } + ] + } + }; + + it('QTable should match snapshot', () => { + const { element } = shallowMount(Component, options); + + expect(element).toMatchSnapshot(); + }); +}); diff --git a/tests/unit/__snapshots__/QTable.test.js.snap b/src/qComponents/QTable/__snapshots__/QTable.test.js.snap similarity index 79% rename from tests/unit/__snapshots__/QTable.test.js.snap rename to src/qComponents/QTable/__snapshots__/QTable.test.js.snap index 58977011..5fb5da02 100644 --- a/tests/unit/__snapshots__/QTable.test.js.snap +++ b/src/qComponents/QTable/__snapshots__/QTable.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`QTable.vue QTable should match snapshot 1`] = ` +exports[`QTable QTable should match snapshot 1`] = `
@@ -28,29 +28,36 @@ exports[`QTable.vue QTable should match snapshot 1`] = ` + + + + + + @@ -66,10 +73,6 @@ exports[`QTable.vue QTable should match snapshot 1`] = ` childrenkey="children" class="" columns="[object Object]" - fixed-column="" - fixed-column-width="200" - fixedcolumn="" - fixedcolumnwidth="200" indent-size="16" indentsize="16" row="[object Object]" diff --git a/tests/unit/QTable.test.js b/tests/unit/QTable.test.js deleted file mode 100644 index d749b2a2..00000000 --- a/tests/unit/QTable.test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import { QTable } from '../../src/qComponents'; - -describe('QTable.vue', () => { - const options = { - propsData: { - columns: [ - { - key: 'col1', - value: 'Column 1' - } - ], - rows: [ - { - col1: 'Columns row 1' - } - ] - } - }; - - it('QTable should match snapshot', () => { - const { element } = shallowMount(QTable, options); - - expect(element).toMatchSnapshot(); - }); -}); diff --git a/tests/unit/setup.js b/tests/unit/setup.js index 5e52b38a..adc5256e 100644 --- a/tests/unit/setup.js +++ b/tests/unit/setup.js @@ -1,4 +1,8 @@ import Vue from 'vue'; +import { mount, shallowMount } from '@vue/test-utils'; import { QScrollbar } from '../../src/qComponents'; Vue.use(QScrollbar); + +global.mount = mount; +global.shallowMount = shallowMount;
- -
- - - Column 1 - + + Column 1 +
+ +