This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
search-panel.spec.js
65 lines (46 loc) · 2 KB
/
search-panel.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Vue from 'vue';
import { mount } from 'vue-test-utils';
import { createStore, RANDOM_SEARCH_TERMS } from '../../../../src/store/store';
import SearchPanel from '../../../../src/components/search-panel/search-panel.vue';
import FakeGiphyFetcher from '../../fake-giphy-fetcher';
describe('Search Panel Component', () => {
let store, fakeGiphyFetcher, component;
beforeEach(() => {
fakeGiphyFetcher = FakeGiphyFetcher.create();
store = createStore({
giphyFetcher: fakeGiphyFetcher
});
component = mount(SearchPanel, { store });
});
describe('Search input', () => {
it('should render input with empty value on init', () => {
expect(component.find('#search-panel-search-field').element.value).to.equal('');
});
it('should reflect the Store changes', async () => {
store.commit('setSearchTerm', 'wowowow');
await Vue.nextTick(); // we must wait for UI changes (note the async!)
expect(component.find('#search-panel-search-field').element.value).to.equal('wowowow');
});
describe('typing into it', () => {
it('should set the searchTerm in the store', () => {
const input = component.find('#search-panel-search-field');
input.element.value = 'my cats';
input.trigger('input');
expect(store.state.searchTerm).to.equal('my cats');
});
});
});
describe('Random search term generation button', () => {
it('should exists in the component', () => {
expect(component.find('#search-panel-random-button').exists()).to.equal(true);
});
describe('clicking on it', () => {
it('should set one of the random search term expressions to the input', async () => {
component.find('#search-panel-random-button').trigger('click');
let generatedSearchTerm = component.find('#search-panel-search-field').element.value;
expect(generatedSearchTerm).to.be.oneOf(RANDOM_SEARCH_TERMS);
expect(store.state.searchTerm).to.equal(generatedSearchTerm);
});
});
});
});