2019-08-02 17:54:07 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import * as sinon from 'sinon';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-09-26 14:36:12 +01:00
|
|
|
import SearchComponent from '@/components/common/VSearch.vue';
|
2019-08-02 17:54:07 +01:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
|
|
|
|
2019-08-02 17:54:07 +01:00
|
|
|
describe('SearchComponent.vue', () => {
|
|
|
|
it('renders correctly', () => {
|
|
|
|
const wrapper = shallowMount(SearchComponent);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with default props', () => {
|
2019-08-09 12:19:49 +01:00
|
|
|
const wrapper = mount(SearchComponent);
|
2019-08-02 17:54:07 +01:00
|
|
|
|
2019-09-23 12:31:42 +01:00
|
|
|
expect(wrapper.vm.$props.placeholder).toMatch('');
|
2019-08-09 12:19:49 +01:00
|
|
|
expect(wrapper.vm.$props.search).toMatch('');
|
2019-08-02 17:54:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('functions onMouseEnter/onMouseLeave work correctly', () => {
|
|
|
|
const wrapper = mount(SearchComponent);
|
|
|
|
|
|
|
|
wrapper.vm.onMouseEnter();
|
|
|
|
|
2019-08-05 11:18:32 +01:00
|
|
|
expect(wrapper.vm.style.width).toMatch('602px');
|
2019-08-02 17:54:07 +01:00
|
|
|
|
|
|
|
wrapper.vm.onMouseLeave();
|
|
|
|
|
2019-08-09 12:19:49 +01:00
|
|
|
expect(wrapper.vm.searchString).toMatch('');
|
2019-08-05 11:18:32 +01:00
|
|
|
expect(wrapper.vm.style.width).toMatch('56px');
|
2019-08-02 17:54:07 +01:00
|
|
|
});
|
|
|
|
|
2019-08-09 12:19:49 +01:00
|
|
|
it('function clearSearch works correctly', () => {
|
2019-09-09 11:33:39 +01:00
|
|
|
const processSearchQuerySpy = sinon.spy();
|
2019-08-09 12:19:49 +01:00
|
|
|
|
|
|
|
const wrapper = mount(SearchComponent, {
|
|
|
|
methods: {
|
|
|
|
processSearchQuery: processSearchQuerySpy,
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2019-08-09 12:19:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.clearSearch();
|
|
|
|
|
|
|
|
expect(processSearchQuerySpy.callCount).toBe(1);
|
|
|
|
expect(wrapper.vm.$data.inputWidth).toMatch('56px');
|
|
|
|
});
|
2019-08-02 17:54:07 +01:00
|
|
|
});
|