Commit 229b5e44 authored by Thomas Randolph's avatar Thomas Randolph Committed by Himanshu Kapoor

Update to GitLab-recommended finders

Of note here: `.vm` is only available on certain
types of elements, and the close button of the
alert is not one of those elements.

That's why this uses the native browser API to
trigger a click event, rather than the synthetic
Vue `$emit` like in the second test.
parent 1838b748
...@@ -11,14 +11,6 @@ const propsData = { ...@@ -11,14 +11,6 @@ const propsData = {
}; };
const limitedClasses = CENTERED_LIMITED_CONTAINER_CLASSES.split(' '); const limitedClasses = CENTERED_LIMITED_CONTAINER_CLASSES.split(' ');
function getAlertActionButton(wrapper) {
return wrapper.find('.gl-alert-actions button.gl-alert-action:first-child').element;
}
function getAlertCloseButton(wrapper) {
return wrapper.find('[data-testid="close-icon"]').element.parentNode;
}
describe('CollapsedFilesWarning', () => { describe('CollapsedFilesWarning', () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
let store; let store;
...@@ -26,6 +18,10 @@ describe('CollapsedFilesWarning', () => { ...@@ -26,6 +18,10 @@ describe('CollapsedFilesWarning', () => {
localVue.use(Vuex); localVue.use(Vuex);
const getAlertActionButton = () =>
wrapper.find(CollapsedFilesWarning).find('button.gl-alert-action:first-child');
const getAlertCloseButton = () => wrapper.find(CollapsedFilesWarning).find('button');
const createComponent = (props = {}, { full } = { full: false }) => { const createComponent = (props = {}, { full } = { full: false }) => {
const mounter = full ? mount : shallowMount; const mounter = full ? mount : shallowMount;
store = new Vuex.Store({ store = new Vuex.Store({
...@@ -73,7 +69,7 @@ describe('CollapsedFilesWarning', () => { ...@@ -73,7 +69,7 @@ describe('CollapsedFilesWarning', () => {
expect(wrapper.vm.isDismissed).toBe(false); expect(wrapper.vm.isDismissed).toBe(false);
getAlertCloseButton(wrapper).click(); getAlertCloseButton().element.click();
expect(wrapper.vm.isDismissed).toBe(true); expect(wrapper.vm.isDismissed).toBe(true);
}); });
...@@ -83,7 +79,7 @@ describe('CollapsedFilesWarning', () => { ...@@ -83,7 +79,7 @@ describe('CollapsedFilesWarning', () => {
jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(undefined); jest.spyOn(wrapper.vm.$store, 'dispatch').mockReturnValue(undefined);
getAlertActionButton(wrapper).click(); getAlertActionButton().vm.$emit('click');
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/expandAllFiles', undefined); expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('diffs/expandAllFiles', undefined);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment