debian-mirror-gitlab/spec/frontend/filtered_search/recent_searches_root_spec.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { setHTMLFixture } from 'helpers/fixtures';
2017-08-17 22:00:37 +05:30
import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
2021-03-11 19:13:27 +05:30
const containerId = 'test-container';
const dropdownElementId = 'test-dropdown-element';
2020-05-24 23:13:21 +05:30
2017-08-17 22:00:37 +05:30
describe('RecentSearchesRoot', () => {
describe('render', () => {
2021-03-11 19:13:27 +05:30
let recentSearchesRootMockInstance;
let vm;
let containerEl;
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2021-03-11 19:13:27 +05:30
setHTMLFixture(`
<div id="${containerId}">
<div id="${dropdownElementId}"></div>
</div>
`);
containerEl = document.getElementById(containerId);
recentSearchesRootMockInstance = {
2017-08-17 22:00:37 +05:30
store: {
2021-03-11 19:13:27 +05:30
state: {
recentSearches: ['foo', 'bar', 'qux'],
isLocalStorageAvailable: true,
allowedKeys: ['test'],
},
2017-08-17 22:00:37 +05:30
},
2021-03-11 19:13:27 +05:30
wrapperElement: document.getElementById(dropdownElementId),
2017-08-17 22:00:37 +05:30
};
2021-03-11 19:13:27 +05:30
RecentSearchesRoot.prototype.render.call(recentSearchesRootMockInstance);
vm = recentSearchesRootMockInstance.vm;
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
return vm.$nextTick();
2017-08-17 22:00:37 +05:30
});
2021-03-11 19:13:27 +05:30
afterEach(() => {
vm.$destroy();
});
it('should render the recent searches', () => {
const { recentSearches } = recentSearchesRootMockInstance.store.state;
recentSearches.forEach((recentSearch) => {
expect(containerEl.textContent).toContain(recentSearch);
});
2017-08-17 22:00:37 +05:30
});
});
});