gitlab-org--gitlab-foss/spec/frontend/filtered_search/recent_searches_root_spec.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

import { nextTick } from 'vue';
import { setHTMLFixture } from 'helpers/fixtures';
2017-05-05 17:59:41 +00:00
import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
const containerId = 'test-container';
const dropdownElementId = 'test-dropdown-element';
2017-05-05 17:59:41 +00:00
describe('RecentSearchesRoot', () => {
describe('render', () => {
let recentSearchesRootMockInstance;
let vm;
let containerEl;
2017-05-05 17:59:41 +00:00
beforeEach(async () => {
setHTMLFixture(`
<div id="${containerId}">
<div id="${dropdownElementId}"></div>
</div>
`);
containerEl = document.getElementById(containerId);
recentSearchesRootMockInstance = {
2017-05-05 17:59:41 +00:00
store: {
state: {
recentSearches: ['foo', 'bar', 'qux'],
isLocalStorageAvailable: true,
allowedKeys: ['test'],
},
2017-05-05 17:59:41 +00:00
},
wrapperElement: document.getElementById(dropdownElementId),
2017-05-05 17:59:41 +00:00
};
RecentSearchesRoot.prototype.render.call(recentSearchesRootMockInstance);
vm = recentSearchesRootMockInstance.vm;
2017-05-05 17:59:41 +00:00
await nextTick();
2017-05-05 17:59:41 +00:00
});
afterEach(() => {
vm.$destroy();
});
it('should render the recent searches', () => {
const { recentSearches } = recentSearchesRootMockInstance.store.state;
recentSearches.forEach((recentSearch) => {
expect(containerEl.textContent).toContain(recentSearch);
});
2017-05-05 17:59:41 +00:00
});
});
});