Commit 58f99a75 authored by Illya Klymov's avatar Illya Klymov

Refactor pipelines_spec

- remove deprecated `methods`
- nextTick
parent 5dc5bd3b
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
...@@ -72,7 +73,7 @@ describe('Pipelines', () => { ...@@ -72,7 +73,7 @@ describe('Pipelines', () => {
const findTablePagination = () => wrapper.find(TablePagination); const findTablePagination = () => wrapper.find(TablePagination);
const createComponent = (props = defaultProps, methods) => { const createComponent = (props = defaultProps) => {
wrapper = mount(PipelinesComponent, { wrapper = mount(PipelinesComponent, {
propsData: { propsData: {
store: new Store(), store: new Store(),
...@@ -80,13 +81,15 @@ describe('Pipelines', () => { ...@@ -80,13 +81,15 @@ describe('Pipelines', () => {
params: {}, params: {},
...props, ...props,
}, },
methods: {
...methods,
},
}); });
}; };
beforeAll(() => {
delete window.location;
});
beforeEach(() => { beforeEach(() => {
window.location = { search: '' };
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
pipelines = getJSONFixture(jsonFixtureName); pipelines = getJSONFixture(jsonFixtureName);
...@@ -94,7 +97,7 @@ describe('Pipelines', () => { ...@@ -94,7 +97,7 @@ describe('Pipelines', () => {
jest.spyOn(Api, 'branches').mockResolvedValue({ data: branches }); jest.spyOn(Api, 'branches').mockResolvedValue({ data: branches });
}); });
afterEach(() => { afterEach(async () => {
wrapper.destroy(); wrapper.destroy();
mock.restore(); mock.restore();
}); });
...@@ -170,7 +173,7 @@ describe('Pipelines', () => { ...@@ -170,7 +173,7 @@ describe('Pipelines', () => {
it('renders tab empty state finished scope', () => { it('renders tab empty state finished scope', () => {
wrapper.vm.scope = 'finished'; wrapper.vm.scope = 'finished';
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findBlankState().text()).toBe('There are currently no finished pipelines.'); expect(findBlankState().text()).toBe('There are currently no finished pipelines.');
}); });
}); });
...@@ -382,30 +385,23 @@ describe('Pipelines', () => { ...@@ -382,30 +385,23 @@ describe('Pipelines', () => {
}); });
it('should make an API request when using tabs', () => { it('should make an API request when using tabs', () => {
const updateContentMock = jest.fn(() => {}); createComponent({ hasGitlabCi: true, canCreatePipeline: true, ...paths });
createComponent( jest.spyOn(wrapper.vm.service, 'getPipelines');
{ hasGitlabCi: true, canCreatePipeline: true, ...paths },
{
updateContent: updateContentMock,
},
);
return waitForPromises().then(() => { return waitForPromises().then(() => {
findTab('finished').trigger('click'); findTab('finished').trigger('click');
expect(updateContentMock).toHaveBeenCalledWith({ scope: 'finished', page: '1' }); expect(wrapper.vm.service.getPipelines).toHaveBeenCalledWith({
scope: 'finished',
page: '1',
});
}); });
}); });
describe('with pagination', () => { describe('with pagination', () => {
it('should make an API request when using pagination', () => { it('should make an API request when using pagination', () => {
const updateContentMock = jest.fn(() => {}); createComponent({ hasGitlabCi: true, canCreatePipeline: true, ...paths });
createComponent( jest.spyOn(wrapper.vm.service, 'getPipelines');
{ hasGitlabCi: true, canCreatePipeline: true, ...paths },
{
updateContent: updateContentMock,
},
);
return waitForPromises() return waitForPromises()
.then(() => { .then(() => {
...@@ -418,12 +414,14 @@ describe('Pipelines', () => { ...@@ -418,12 +414,14 @@ describe('Pipelines', () => {
totalPages: 5, totalPages: 5,
}; };
return wrapper.vm.$nextTick(); return nextTick();
}) })
.then(() => { .then(() => {
wrapper.find('.next-page-item').trigger('click'); wrapper.find('.next-page-item').trigger('click');
expect(wrapper.vm.service.getPipelines).toHaveBeenCalledWith({
expect(updateContentMock).toHaveBeenCalledWith({ scope: 'all', page: '2' }); scope: 'all',
page: '2',
});
}); });
}); });
}); });
...@@ -542,7 +540,7 @@ describe('Pipelines', () => { ...@@ -542,7 +540,7 @@ describe('Pipelines', () => {
wrapper.vm.hasError = true; wrapper.vm.hasError = true;
wrapper.vm.isLoading = false; wrapper.vm.isLoading = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findBlankState().props('message')).toBe( expect(findBlankState().props('message')).toBe(
'There was an error fetching the pipelines. Try again in a few moments or contact your support team.', 'There was an error fetching the pipelines. Try again in a few moments or contact your support team.',
); );
...@@ -554,7 +552,7 @@ describe('Pipelines', () => { ...@@ -554,7 +552,7 @@ describe('Pipelines', () => {
wrapper.vm.hasError = false; wrapper.vm.hasError = false;
wrapper.vm.state.pipelines = pipelines.pipelines; wrapper.vm.state.pipelines = pipelines.pipelines;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.find(PipelinesTableComponent).exists()).toBe(true); expect(wrapper.find(PipelinesTableComponent).exists()).toBe(true);
}); });
}); });
...@@ -563,7 +561,7 @@ describe('Pipelines', () => { ...@@ -563,7 +561,7 @@ describe('Pipelines', () => {
wrapper.vm.state.count.all = 10; wrapper.vm.state.count.all = 10;
wrapper.vm.isLoading = false; wrapper.vm.isLoading = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findBlankState().exists()).toBe(true); expect(findBlankState().exists()).toBe(true);
expect(findBlankState().props('message')).toBe('There are currently no pipelines.'); expect(findBlankState().props('message')).toBe('There are currently no pipelines.');
}); });
...@@ -572,7 +570,7 @@ describe('Pipelines', () => { ...@@ -572,7 +570,7 @@ describe('Pipelines', () => {
it('shows empty tab when project has CI', () => { it('shows empty tab when project has CI', () => {
wrapper.vm.isLoading = false; wrapper.vm.isLoading = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findBlankState().exists()).toBe(true); expect(findBlankState().exists()).toBe(true);
expect(findBlankState().props('message')).toBe('There are currently no pipelines.'); expect(findBlankState().props('message')).toBe('There are currently no pipelines.');
}); });
...@@ -583,7 +581,7 @@ describe('Pipelines', () => { ...@@ -583,7 +581,7 @@ describe('Pipelines', () => {
wrapper.vm.isLoading = false; wrapper.vm.isLoading = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.find(EmptyState).exists()).toBe(true); expect(wrapper.find(EmptyState).exists()).toBe(true);
}); });
}); });
...@@ -594,7 +592,7 @@ describe('Pipelines', () => { ...@@ -594,7 +592,7 @@ describe('Pipelines', () => {
wrapper.vm.isLoading = true; wrapper.vm.isLoading = true;
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(true); expect(findNavigationTabs().exists()).toBe(true);
}); });
}); });
...@@ -604,7 +602,7 @@ describe('Pipelines', () => { ...@@ -604,7 +602,7 @@ describe('Pipelines', () => {
wrapper.vm.state.pipelines = pipelines.pipelines; wrapper.vm.state.pipelines = pipelines.pipelines;
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(true); expect(findNavigationTabs().exists()).toBe(true);
}); });
}); });
...@@ -614,7 +612,7 @@ describe('Pipelines', () => { ...@@ -614,7 +612,7 @@ describe('Pipelines', () => {
wrapper.vm.hasError = true; wrapper.vm.hasError = true;
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(true); expect(findNavigationTabs().exists()).toBe(true);
}); });
}); });
...@@ -624,7 +622,7 @@ describe('Pipelines', () => { ...@@ -624,7 +622,7 @@ describe('Pipelines', () => {
wrapper.vm.state.count.all = 10; wrapper.vm.state.count.all = 10;
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(true); expect(findNavigationTabs().exists()).toBe(true);
}); });
}); });
...@@ -632,7 +630,7 @@ describe('Pipelines', () => { ...@@ -632,7 +630,7 @@ describe('Pipelines', () => {
it('returns false when has not made first request', () => { it('returns false when has not made first request', () => {
wrapper.vm.hasMadeRequest = false; wrapper.vm.hasMadeRequest = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(false); expect(findNavigationTabs().exists()).toBe(false);
}); });
}); });
...@@ -643,7 +641,7 @@ describe('Pipelines', () => { ...@@ -643,7 +641,7 @@ describe('Pipelines', () => {
wrapper.vm.isLoading = false; wrapper.vm.isLoading = false;
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationTabs().exists()).toBe(false); expect(findNavigationTabs().exists()).toBe(false);
}); });
}); });
...@@ -653,7 +651,7 @@ describe('Pipelines', () => { ...@@ -653,7 +651,7 @@ describe('Pipelines', () => {
it('returns true when it has paths & has made the first request', () => { it('returns true when it has paths & has made the first request', () => {
wrapper.vm.hasMadeRequest = true; wrapper.vm.hasMadeRequest = true;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationControls().exists()).toBe(true); expect(findNavigationControls().exists()).toBe(true);
}); });
}); });
...@@ -661,7 +659,7 @@ describe('Pipelines', () => { ...@@ -661,7 +659,7 @@ describe('Pipelines', () => {
it('returns false when it has not made the first request', () => { it('returns false when it has not made the first request', () => {
wrapper.vm.hasMadeRequest = false; wrapper.vm.hasMadeRequest = false;
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(findNavigationControls().exists()).toBe(false); expect(findNavigationControls().exists()).toBe(false);
}); });
}); });
...@@ -680,7 +678,7 @@ describe('Pipelines', () => { ...@@ -680,7 +678,7 @@ describe('Pipelines', () => {
return waitForPromises(); return waitForPromises();
}); });
it('updates request data and query params on filter submit', () => { it('updates request data and query params on filter submit', async () => {
const expectedQueryParams = { const expectedQueryParams = {
page: '1', page: '1',
scope: 'all', scope: 'all',
...@@ -690,15 +688,17 @@ describe('Pipelines', () => { ...@@ -690,15 +688,17 @@ describe('Pipelines', () => {
}; };
findFilteredSearch().vm.$emit('submit', mockSearch); findFilteredSearch().vm.$emit('submit', mockSearch);
await nextTick();
expect(wrapper.vm.requestData).toEqual(expectedQueryParams); expect(wrapper.vm.requestData).toEqual(expectedQueryParams);
expect(updateContentMock).toHaveBeenCalledWith(expectedQueryParams); expect(updateContentMock).toHaveBeenCalledWith(expectedQueryParams);
}); });
it('does not add query params if raw text search is used', () => { it('does not add query params if raw text search is used', async () => {
const expectedQueryParams = { page: '1', scope: 'all' }; const expectedQueryParams = { page: '1', scope: 'all' };
findFilteredSearch().vm.$emit('submit', ['rawText']); findFilteredSearch().vm.$emit('submit', ['rawText']);
await nextTick();
expect(wrapper.vm.requestData).toEqual(expectedQueryParams); expect(wrapper.vm.requestData).toEqual(expectedQueryParams);
expect(updateContentMock).toHaveBeenCalledWith(expectedQueryParams); expect(updateContentMock).toHaveBeenCalledWith(expectedQueryParams);
......
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