Commit 1a52dd7e authored by mgandres's avatar mgandres

Add tests for commit sha polling

parent a0ef8639
import waitForPromises from 'helpers/wait_for_promises';
import { GlFormTextarea, GlFormInput, GlLoadingIcon } from '@gitlab/ui'; import { GlFormTextarea, GlFormInput, GlLoadingIcon } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { objectToQuery, redirectTo } from '~/lib/utils/url_utility'; import { objectToQuery, redirectTo } from '~/lib/utils/url_utility';
import CommitForm from '~/pipeline_editor/components/commit/commit_form.vue'; import CommitForm from '~/pipeline_editor/components/commit/commit_form.vue';
import CommitSection from '~/pipeline_editor/components/commit/commit_section.vue'; import CommitSection from '~/pipeline_editor/components/commit/commit_section.vue';
...@@ -100,6 +100,7 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -100,6 +100,7 @@ describe('Pipeline Editor | Commit section', () => {
await findCommitForm().find('[data-testid="new-mr-checkbox"]').setChecked(openMergeRequest); await findCommitForm().find('[data-testid="new-mr-checkbox"]').setChecked(openMergeRequest);
} }
await findCommitForm().find('[type="submit"]').trigger('click'); await findCommitForm().find('[type="submit"]').trigger('click');
await waitForPromises();
}; };
const cancelCommitForm = async () => { const cancelCommitForm = async () => {
...@@ -157,7 +158,6 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -157,7 +158,6 @@ describe('Pipeline Editor | Commit section', () => {
beforeEach(async () => { beforeEach(async () => {
createComponent(); createComponent();
await submitCommit(); await submitCommit();
await nextTick();
}); });
it('calls the mutation with the current branch', () => { it('calls the mutation with the current branch', () => {
...@@ -183,7 +183,6 @@ describe('Pipeline Editor | Commit section', () => { ...@@ -183,7 +183,6 @@ describe('Pipeline Editor | Commit section', () => {
it('a second commit submits the latest sha, keeping the form updated', async () => { it('a second commit submits the latest sha, keeping the form updated', async () => {
await submitCommit(); await submitCommit();
await nextTick();
expect(mockMutate).toHaveBeenCalledTimes(6); expect(mockMutate).toHaveBeenCalledTimes(6);
expect(mockMutate).toHaveBeenCalledWith({ expect(mockMutate).toHaveBeenCalledWith({
......
...@@ -158,6 +158,10 @@ describe('Pipeline editor app component', () => { ...@@ -158,6 +158,10 @@ describe('Pipeline editor app component', () => {
describe('when file exists', () => { describe('when file exists', () => {
beforeEach(async () => { beforeEach(async () => {
await createComponentWithApollo(); await createComponentWithApollo();
jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
.mockImplementation(jest.fn());
}); });
it('shows pipeline editor home component', () => { it('shows pipeline editor home component', () => {
...@@ -175,18 +179,32 @@ describe('Pipeline editor app component', () => { ...@@ -175,18 +179,32 @@ describe('Pipeline editor app component', () => {
sha: mockCommitSha, sha: mockCommitSha,
}); });
}); });
it('does not poll for the commit sha', () => {
expect(wrapper.vm.$apollo.queries.commitSha.startPolling).toHaveBeenCalledTimes(0);
});
}); });
describe('when no CI config file exists', () => { describe('when no CI config file exists', () => {
it('shows an empty state and does not show editor home component', async () => { beforeEach(async () => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponseNoCiFile); mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponseNoCiFile);
await createComponentWithApollo(); await createComponentWithApollo();
jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
.mockImplementation(jest.fn());
});
it('shows an empty state and does not show editor home component', async () => {
expect(findEmptyState().exists()).toBe(true); expect(findEmptyState().exists()).toBe(true);
expect(findAlert().exists()).toBe(false); expect(findAlert().exists()).toBe(false);
expect(findEditorHome().exists()).toBe(false); expect(findEditorHome().exists()).toBe(false);
}); });
it('does not poll for the commit sha', () => {
expect(wrapper.vm.$apollo.queries.commitSha.startPolling).toHaveBeenCalledTimes(0);
});
describe('because of a fetching error', () => { describe('because of a fetching error', () => {
it('shows a unkown error message', async () => { it('shows a unkown error message', async () => {
const loadUnknownFailureText = 'The CI configuration was not loaded, please try again.'; const loadUnknownFailureText = 'The CI configuration was not loaded, please try again.';
...@@ -249,9 +267,9 @@ describe('Pipeline editor app component', () => { ...@@ -249,9 +267,9 @@ describe('Pipeline editor app component', () => {
const updateSuccessMessage = 'Your changes have been successfully committed.'; const updateSuccessMessage = 'Your changes have been successfully committed.';
describe('and the commit mutation succeeds', () => { describe('and the commit mutation succeeds', () => {
beforeEach(() => { beforeEach(async () => {
window.scrollTo = jest.fn(); window.scrollTo = jest.fn();
createComponent(); await createComponentWithApollo();
findEditorHome().vm.$emit('commit', { type: COMMIT_SUCCESS }); findEditorHome().vm.$emit('commit', { type: COMMIT_SUCCESS });
}); });
...@@ -263,6 +281,30 @@ describe('Pipeline editor app component', () => { ...@@ -263,6 +281,30 @@ describe('Pipeline editor app component', () => {
it('scrolls to the top of the page to bring attention to the confirmation message', () => { it('scrolls to the top of the page to bring attention to the confirmation message', () => {
expect(window.scrollTo).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' }); expect(window.scrollTo).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' });
}); });
it('polls for commit sha while pipeline data is not yet available', async () => {
jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
.mockImplementation(jest.fn());
// simulate updating current branch (which triggers commitSha refetch)
// while pipeline data is not yet available
mockLatestCommitShaQuery.mockResolvedValue(mockEmptyCommitShaResults);
await wrapper.vm.$apollo.queries.commitSha.refetch();
expect(wrapper.vm.$apollo.queries.commitSha.startPolling).toHaveBeenCalledTimes(1);
});
it('stops polling for commit sha when pipeline data is available', async () => {
jest
.spyOn(wrapper.vm.$apollo.queries.commitSha, 'stopPolling')
.mockImplementation(jest.fn());
mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
await wrapper.vm.$apollo.queries.commitSha.refetch();
expect(wrapper.vm.$apollo.queries.commitSha.stopPolling).toHaveBeenCalledTimes(1);
});
}); });
describe('and the commit mutation fails', () => { describe('and the commit mutation fails', () => {
......
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