2018-11-27 10:51:33 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
|
|
|
import Button from '@/components/common/Button.vue';
|
2018-11-05 15:26:18 +00:00
|
|
|
import * as sinon from 'sinon';
|
|
|
|
|
|
|
|
describe('Button.vue', () => {
|
2018-11-14 14:00:01 +00:00
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
const wrapper = shallowMount(Button);
|
2018-11-14 14:00:01 +00:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with isWhite prop', () => {
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
const wrapper = shallowMount(Button, {
|
2018-11-14 14:00:01 +00:00
|
|
|
propsData: {
|
|
|
|
isWhite: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with isDisabled prop', () => {
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
const wrapper = shallowMount(Button, {
|
2018-11-14 14:00:01 +00:00
|
|
|
propsData: {
|
|
|
|
isDisabled: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
it('renders correctly with size and label props', () => {
|
2018-12-18 14:43:23 +00:00
|
|
|
let label = 'testLabel';
|
|
|
|
let width = '30px';
|
|
|
|
let height = '20px';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
const wrapper = shallowMount(Button, {
|
2018-12-18 14:43:23 +00:00
|
|
|
propsData: {label, width, height},
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.element.style.width).toMatch(width);
|
|
|
|
expect(wrapper.element.style.height).toMatch(height);
|
|
|
|
expect(wrapper.text()).toMatch(label);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with default props', () => {
|
|
|
|
|
|
|
|
const wrapper = shallowMount(Button);
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
expect(wrapper.element.style.width).toMatch('inherit');
|
|
|
|
expect(wrapper.element.style.height).toMatch('inherit');
|
|
|
|
expect(wrapper.text()).toMatch('Default');
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('trigger onPress correctly', () => {
|
|
|
|
let onPressSpy = sinon.spy();
|
|
|
|
|
|
|
|
const wrapper = mount(Button, {
|
|
|
|
propsData: {
|
2018-11-14 14:00:01 +00:00
|
|
|
onPress: onPressSpy,
|
|
|
|
isDisabled: false
|
2018-11-05 15:26:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.find('div.container').trigger('click');
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2018-11-05 15:26:18 +00:00
|
|
|
expect(onPressSpy.callCount).toBe(1);
|
|
|
|
});
|
2018-12-18 14:43:23 +00:00
|
|
|
});
|