Skip to content

Commit

Permalink
[QPopover] add test (#32)
Browse files Browse the repository at this point in the history
* fix QTable test
* add test
  • Loading branch information
shamilfrontend authored Jan 12, 2021
1 parent 49148d3 commit db3fdf4
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 39 deletions.
100 changes: 100 additions & 0 deletions src/qComponents/QPopover/QPopover.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import Component from './index';

describe('QPopover', () => {
const options = {
slots: {
reference: '<button>Open</button>'
}
};

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();
});
});
});
});
40 changes: 40 additions & 0 deletions src/qComponents/QPopover/__snapshots__/QPopover.test.js.snap
Original file line number Diff line number Diff line change
@@ -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`] = `
<span>
<transition-stub
name="fade-in-linear"
>
<div
class="q-popover q-popover_without-icon"
style="display: none;"
>
<!---->
<q-scrollbar-stub
theme="primary"
viewclass="scrollbar__list"
viewtag="div"
wrapclass="q-popover__inner"
>
<!---->
<!---->
</q-scrollbar-stub>
</div>
</transition-stub>
<button>
Open
</button>
</span>
`;
29 changes: 29 additions & 0 deletions src/qComponents/QTable/QTable.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -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`] = `
<div
class="q-table"
>
Expand Down Expand Up @@ -28,29 +28,36 @@ exports[`QTable.vue QTable should match snapshot 1`] = `
<table
cellpadding="0"
cellspacing="0"
class="q-table__table"
class="q-table__table q-table__fixed"
>
<colgroup>
<!---->
<col
style="width: 200px;"
/>
</colgroup>
<thead>
<tr>
<!---->
<th
class="q-table__header-cell "
class="q-table__header-cell"
>
<div
class="q-table__header-cell-wrapper"
>
<!---->
<div
class="q-table__header-cell-content"
>
<!---->
Column 1
Column 1
<!---->
</div>
<!---->
</div>
</th>
</tr>
Expand All @@ -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]"
Expand Down
26 changes: 0 additions & 26 deletions tests/unit/QTable.test.js

This file was deleted.

4 changes: 4 additions & 0 deletions tests/unit/setup.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit db3fdf4

Please sign in to comment.