2019-08-02 17:54:07 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
|
|
|
import * as sinon from 'sinon';
|
|
|
|
import SearchComponent from '@/components/common/SearchComponent.vue';
|
|
|
|
|
|
|
|
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-08-09 12:19:49 +01:00
|
|
|
expect(wrapper.vm.$props.placeHolder).toMatch('');
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
it('function onInput works correctly', () => {
|
|
|
|
let onMouseLeaveSpy = sinon.spy();
|
|
|
|
let processSearchQuerySpy = sinon.spy();
|
|
|
|
|
|
|
|
const wrapper = mount(SearchComponent, {
|
|
|
|
methods: {
|
|
|
|
onMouseLeave: onMouseLeaveSpy,
|
|
|
|
processSearchQuery: processSearchQuerySpy,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onInput();
|
|
|
|
|
|
|
|
expect(onMouseLeaveSpy.callCount).toBe(1);
|
|
|
|
expect(processSearchQuerySpy.callCount).toBe(1);
|
|
|
|
});
|
2019-08-09 12:19:49 +01:00
|
|
|
|
|
|
|
it('function clearSearch works correctly', () => {
|
|
|
|
let processSearchQuerySpy = sinon.spy();
|
|
|
|
|
|
|
|
const wrapper = mount(SearchComponent, {
|
|
|
|
methods: {
|
|
|
|
processSearchQuery: processSearchQuerySpy,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.clearSearch();
|
|
|
|
|
|
|
|
expect(processSearchQuerySpy.callCount).toBe(1);
|
|
|
|
expect(wrapper.vm.$data.inputWidth).toMatch('56px');
|
|
|
|
});
|
2019-08-02 17:54:07 +01:00
|
|
|
});
|