Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-20 15:09:31 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-20 15:09:31 +0300
commitb70394d26f7349ecfa4a740d7d7b115d738eff8e (patch)
tree635c243acaa07e06f43cd3bfc628a24c5a572a8a /spec/frontend
parent55e6eebd6fc60bd98d94303983468b3020d2a211 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/pipeline_editor/components/commit/commit_section_spec.js11
-rw-r--r--spec/frontend/pipeline_editor/components/editor/text_editor_spec.js9
-rw-r--r--spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js9
-rw-r--r--spec/frontend/pipeline_editor/components/header/pipeline_status_spec.js8
-rw-r--r--spec/frontend/pipeline_editor/mock_data.js26
-rw-r--r--spec/frontend/pipeline_editor/pipeline_editor_app_spec.js120
6 files changed, 85 insertions, 98 deletions
diff --git a/spec/frontend/pipeline_editor/components/commit/commit_section_spec.js b/spec/frontend/pipeline_editor/components/commit/commit_section_spec.js
index 39081e07e52..20c4a0fbf6a 100644
--- a/spec/frontend/pipeline_editor/components/commit/commit_section_spec.js
+++ b/spec/frontend/pipeline_editor/components/commit/commit_section_spec.js
@@ -1,5 +1,6 @@
import { GlFormTextarea, GlFormInput, GlLoadingIcon } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
+import waitForPromises from 'helpers/wait_for_promises';
import { objectToQuery, redirectTo } from '~/lib/utils/url_utility';
import CommitForm from '~/pipeline_editor/components/commit/commit_form.vue';
import CommitSection from '~/pipeline_editor/components/commit/commit_section.vue';
@@ -48,7 +49,10 @@ describe('Pipeline Editor | Commit section', () => {
let wrapper;
let mockMutate;
- const defaultProps = { ciFileContent: mockCiYml };
+ const defaultProps = {
+ ciFileContent: mockCiYml,
+ commitSha: mockCommitSha,
+ };
const createComponent = ({ props = {}, options = {}, provide = {} } = {}) => {
mockMutate = jest.fn().mockResolvedValue({
@@ -67,7 +71,6 @@ describe('Pipeline Editor | Commit section', () => {
provide: { ...mockProvide, ...provide },
data() {
return {
- commitSha: mockCommitSha,
currentBranch: mockDefaultBranch,
isNewCiConfigFile: Boolean(options?.isNewCiConfigfile),
};
@@ -97,8 +100,7 @@ describe('Pipeline Editor | Commit section', () => {
await findCommitForm().find('[data-testid="new-mr-checkbox"]').setChecked(openMergeRequest);
}
await findCommitForm().find('[type="submit"]').trigger('click');
- // Simulate the write to local cache that occurs after a commit
- await wrapper.setData({ commitSha: mockCommitNextSha });
+ await waitForPromises();
};
const cancelCommitForm = async () => {
@@ -188,7 +190,6 @@ describe('Pipeline Editor | Commit section', () => {
update: expect.any(Function),
variables: {
...mockVariables,
- lastCommitId: mockCommitNextSha,
branch: mockDefaultBranch,
},
});
diff --git a/spec/frontend/pipeline_editor/components/editor/text_editor_spec.js b/spec/frontend/pipeline_editor/components/editor/text_editor_spec.js
index c6c7f593cc5..85222f2ecbb 100644
--- a/spec/frontend/pipeline_editor/components/editor/text_editor_spec.js
+++ b/spec/frontend/pipeline_editor/components/editor/text_editor_spec.js
@@ -42,15 +42,12 @@ describe('Pipeline Editor | Text editor component', () => {
defaultBranch: mockDefaultBranch,
glFeatures,
},
+ propsData: {
+ commitSha: mockCommitSha,
+ },
attrs: {
value: mockCiYml,
},
- // Simulate graphQL client query result
- data() {
- return {
- commitSha: mockCommitSha,
- };
- },
listeners: {
[EDITOR_READY_EVENT]: editorReadyListener,
},
diff --git a/spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js b/spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
index 85b51d08f88..b5881790b0b 100644
--- a/spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
+++ b/spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
@@ -247,15 +247,6 @@ describe('Pipeline editor branch switcher', () => {
expect(wrapper.emitted('refetchContent')).toBeUndefined();
});
-
- it('emits the updateCommitSha event when selecting a different branch', async () => {
- expect(wrapper.emitted('updateCommitSha')).toBeUndefined();
-
- const branch = findDropdownItems().at(1);
- branch.vm.$emit('click');
-
- expect(wrapper.emitted('updateCommitSha')).toHaveLength(1);
- });
});
describe('when searching', () => {
diff --git a/spec/frontend/pipeline_editor/components/header/pipeline_status_spec.js b/spec/frontend/pipeline_editor/components/header/pipeline_status_spec.js
index a95921359cc..753682d438b 100644
--- a/spec/frontend/pipeline_editor/components/header/pipeline_status_spec.js
+++ b/spec/frontend/pipeline_editor/components/header/pipeline_status_spec.js
@@ -27,13 +27,11 @@ describe('Pipeline Status', () => {
wrapper = shallowMount(PipelineStatus, {
localVue,
apolloProvider: mockApollo,
+ propsData: {
+ commitSha: mockCommitSha,
+ },
provide: mockProvide,
stubs: { GlLink, GlSprintf },
- data() {
- return {
- commitSha: mockCommitSha,
- };
- },
});
};
diff --git a/spec/frontend/pipeline_editor/mock_data.js b/spec/frontend/pipeline_editor/mock_data.js
index 4d4a8c21d78..19ad4f051ba 100644
--- a/spec/frontend/pipeline_editor/mock_data.js
+++ b/spec/frontend/pipeline_editor/mock_data.js
@@ -156,35 +156,33 @@ export const mergeUnwrappedCiConfig = (mergedConfig) => {
};
};
-export const mockNewCommitShaResults = {
+export const mockCommitShaResults = {
data: {
project: {
pipelines: {
nodes: [
{
id: 'gid://gitlab/Ci::Pipeline/1',
- sha: 'd0d56d363d8a3f67a8ab9fc00207d468f30032ca',
+ sha: mockCommitSha,
path: `/${mockProjectFullPath}/-/pipelines/488`,
commitPath: `/${mockProjectFullPath}/-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca`,
},
- {
- id: 'gid://gitlab/Ci::Pipeline/2',
- sha: 'fcab2ece40b26f428dfa3aa288b12c3c5bdb06aa',
- path: `/${mockProjectFullPath}/-/pipelines/487`,
- commitPath: `/${mockProjectFullPath}/-/commit/fcab2ece40b26f428dfa3aa288b12c3c5bdb06aa`,
- },
- {
- id: 'gid://gitlab/Ci::Pipeline/3',
- sha: '6c16b17c7f94a438ae19a96c285bb49e3c632cf4',
- path: `/${mockProjectFullPath}/-/pipelines/433`,
- commitPath: `/${mockProjectFullPath}/-/commit/6c16b17c7f94a438ae19a96c285bb49e3c632cf4`,
- },
],
},
},
},
};
+export const mockEmptyCommitShaResults = {
+ data: {
+ project: {
+ pipelines: {
+ nodes: [],
+ },
+ },
+ },
+};
+
export const mockProjectBranches = {
data: {
project: {
diff --git a/spec/frontend/pipeline_editor/pipeline_editor_app_spec.js b/spec/frontend/pipeline_editor/pipeline_editor_app_spec.js
index 0c5c08d7190..affe45f1b1d 100644
--- a/spec/frontend/pipeline_editor/pipeline_editor_app_spec.js
+++ b/spec/frontend/pipeline_editor/pipeline_editor_app_spec.js
@@ -26,9 +26,10 @@ import {
mockBlobContentQueryResponseNoCiFile,
mockCiYml,
mockCommitSha,
+ mockCommitShaResults,
mockDefaultBranch,
+ mockEmptyCommitShaResults,
mockProjectFullPath,
- mockNewCommitShaResults,
} from './mock_data';
const localVue = createLocalVue();
@@ -54,7 +55,6 @@ describe('Pipeline editor app component', () => {
let mockBlobContentData;
let mockCiConfigData;
let mockGetTemplate;
- let mockUpdateCommitSha;
let mockLatestCommitShaQuery;
let mockPipelineQuery;
@@ -71,6 +71,11 @@ describe('Pipeline editor app component', () => {
SourceEditor: MockSourceEditor,
PipelineEditorEmptyState,
},
+ data() {
+ return {
+ commitSha: '',
+ };
+ },
mocks: {
$apollo: {
queries: {
@@ -96,18 +101,7 @@ describe('Pipeline editor app component', () => {
[getPipelineQuery, mockPipelineQuery],
];
- const resolvers = {
- Query: {
- commitSha() {
- return mockCommitSha;
- },
- },
- Mutation: {
- updateCommitSha: mockUpdateCommitSha,
- },
- };
-
- mockApollo = createMockApollo(handlers, resolvers);
+ mockApollo = createMockApollo(handlers);
const options = {
localVue,
@@ -137,7 +131,6 @@ describe('Pipeline editor app component', () => {
mockBlobContentData = jest.fn();
mockCiConfigData = jest.fn();
mockGetTemplate = jest.fn();
- mockUpdateCommitSha = jest.fn();
mockLatestCommitShaQuery = jest.fn();
mockPipelineQuery = jest.fn();
});
@@ -159,11 +152,16 @@ describe('Pipeline editor app component', () => {
beforeEach(() => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponse);
mockCiConfigData.mockResolvedValue(mockCiConfigQueryResponse);
+ mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
});
describe('when file exists', () => {
beforeEach(async () => {
await createComponentWithApollo();
+
+ jest
+ .spyOn(wrapper.vm.$apollo.queries.commitSha, 'startPolling')
+ .mockImplementation(jest.fn());
});
it('shows pipeline editor home component', () => {
@@ -181,18 +179,32 @@ describe('Pipeline editor app component', () => {
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', () => {
- it('shows an empty state and does not show editor home component', async () => {
+ beforeEach(async () => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponseNoCiFile);
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(findAlert().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', () => {
it('shows a unkown error message', async () => {
const loadUnknownFailureText = 'The CI configuration was not loaded, please try again.';
@@ -230,6 +242,7 @@ describe('Pipeline editor app component', () => {
describe('when landing on the empty state with feature flag on', () => {
it('user can click on CTA button and see an empty editor', async () => {
mockBlobContentData.mockResolvedValue(mockBlobContentQueryResponseNoCiFile);
+ mockLatestCommitShaQuery.mockResolvedValue(mockEmptyCommitShaResults);
await createComponentWithApollo({
provide: {
@@ -254,9 +267,9 @@ describe('Pipeline editor app component', () => {
const updateSuccessMessage = 'Your changes have been successfully committed.';
describe('and the commit mutation succeeds', () => {
- beforeEach(() => {
+ beforeEach(async () => {
window.scrollTo = jest.fn();
- createComponent();
+ await createComponentWithApollo();
findEditorHome().vm.$emit('commit', { type: COMMIT_SUCCESS });
});
@@ -268,7 +281,32 @@ describe('Pipeline editor app component', () => {
it('scrolls to the top of the page to bring attention to the confirmation message', () => {
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', () => {
const commitFailedReasons = ['Commit failed'];
@@ -320,6 +358,10 @@ describe('Pipeline editor app component', () => {
});
describe('when refetching content', () => {
+ beforeEach(() => {
+ mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
+ });
+
it('refetches blob content', async () => {
await createComponentWithApollo();
jest
@@ -352,6 +394,7 @@ describe('Pipeline editor app component', () => {
const originalLocation = window.location.href;
beforeEach(() => {
+ mockLatestCommitShaQuery.mockResolvedValue(mockCommitShaResults);
setWindowLocation('?template=Android');
});
@@ -371,45 +414,4 @@ describe('Pipeline editor app component', () => {
expect(findTextEditor().exists()).toBe(true);
});
});
-
- describe('when updating commit sha', () => {
- const newCommitSha = mockNewCommitShaResults.data.project.pipelines.nodes[0].sha;
-
- beforeEach(async () => {
- mockUpdateCommitSha.mockResolvedValue(newCommitSha);
- mockLatestCommitShaQuery.mockResolvedValue(mockNewCommitShaResults);
- await createComponentWithApollo();
- });
-
- it('fetches updated commit sha for the new branch', async () => {
- expect(mockLatestCommitShaQuery).not.toHaveBeenCalled();
-
- wrapper
- .findComponent(PipelineEditorHome)
- .vm.$emit('updateCommitSha', { newBranch: 'new-branch' });
- await waitForPromises();
-
- expect(mockLatestCommitShaQuery).toHaveBeenCalledWith({
- projectPath: mockProjectFullPath,
- ref: 'new-branch',
- });
- });
-
- it('updates commit sha with the newly fetched commit sha', async () => {
- expect(mockUpdateCommitSha).not.toHaveBeenCalled();
-
- wrapper
- .findComponent(PipelineEditorHome)
- .vm.$emit('updateCommitSha', { newBranch: 'new-branch' });
- await waitForPromises();
-
- expect(mockUpdateCommitSha).toHaveBeenCalled();
- expect(mockUpdateCommitSha).toHaveBeenCalledWith(
- expect.any(Object),
- { commitSha: mockNewCommitShaResults.data.project.pipelines.nodes[0].sha },
- expect.any(Object),
- expect.any(Object),
- );
- });
- });
});