Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QPopover] add test #32

Merged
merged 6 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;