2021-01-27 15:09:15 +00:00
|
|
|
import { setHTMLFixture } from 'helpers/fixtures';
|
2017-05-05 17:59:41 +00:00
|
|
|
import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
|
|
|
|
|
2021-01-27 15:09:15 +00:00
|
|
|
const containerId = 'test-container';
|
|
|
|
const dropdownElementId = 'test-dropdown-element';
|
2020-05-19 09:08:12 +00:00
|
|
|
|
2017-05-05 17:59:41 +00:00
|
|
|
describe('RecentSearchesRoot', () => {
|
|
|
|
describe('render', () => {
|
2021-01-27 15:09:15 +00:00
|
|
|
let recentSearchesRootMockInstance;
|
|
|
|
let vm;
|
|
|
|
let containerEl;
|
2017-05-05 17:59:41 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-27 15:09:15 +00:00
|
|
|
setHTMLFixture(`
|
|
|
|
<div id="${containerId}">
|
|
|
|
<div id="${dropdownElementId}"></div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
containerEl = document.getElementById(containerId);
|
|
|
|
|
|
|
|
recentSearchesRootMockInstance = {
|
2017-05-05 17:59:41 +00:00
|
|
|
store: {
|
2021-01-27 15:09:15 +00:00
|
|
|
state: {
|
|
|
|
recentSearches: ['foo', 'bar', 'qux'],
|
|
|
|
isLocalStorageAvailable: true,
|
|
|
|
allowedKeys: ['test'],
|
|
|
|
},
|
2017-05-05 17:59:41 +00:00
|
|
|
},
|
2021-01-27 15:09:15 +00:00
|
|
|
wrapperElement: document.getElementById(dropdownElementId),
|
2017-05-05 17:59:41 +00:00
|
|
|
};
|
|
|
|
|
2021-01-27 15:09:15 +00:00
|
|
|
RecentSearchesRoot.prototype.render.call(recentSearchesRootMockInstance);
|
|
|
|
vm = recentSearchesRootMockInstance.vm;
|
2017-05-05 17:59:41 +00:00
|
|
|
|
2021-01-27 15:09:15 +00:00
|
|
|
return vm.$nextTick();
|
2017-05-05 17:59:41 +00:00
|
|
|
});
|
|
|
|
|
2021-01-27 15:09:15 +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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|