diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/frontend/projects | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/frontend/projects')
5 files changed, 93 insertions, 4 deletions
diff --git a/spec/frontend/projects/commit_box/info/load_branches_spec.js b/spec/frontend/projects/commit_box/info/load_branches_spec.js new file mode 100644 index 00000000000..ebd4ee45dab --- /dev/null +++ b/spec/frontend/projects/commit_box/info/load_branches_spec.js @@ -0,0 +1,68 @@ +import axios from 'axios'; +import waitForPromises from 'helpers/wait_for_promises'; +import MockAdapter from 'axios-mock-adapter'; +import { loadBranches } from '~/projects/commit_box/info/load_branches'; + +const mockCommitPath = '/commit/abcd/branches'; +const mockBranchesRes = + '<a href="/-/commits/master">master</a><span><a href="/-/commits/my-branch">my-branch</a></span>'; + +describe('~/projects/commit_box/info/load_branches', () => { + let mock; + let el; + + beforeEach(() => { + mock = new MockAdapter(axios); + mock.onGet(mockCommitPath).reply(200, mockBranchesRes); + + el = document.createElement('div'); + el.dataset.commitPath = mockCommitPath; + el.innerHTML = '<div class="commit-info branches"><span class="spinner"/></div>'; + }); + + it('loads and renders branches info', async () => { + loadBranches(el); + await waitForPromises(); + + expect(el.innerHTML).toBe(`<div class="commit-info branches">${mockBranchesRes}</div>`); + }); + + it('does not load when no container is provided', async () => { + loadBranches(null); + await waitForPromises(); + + expect(mock.history.get).toHaveLength(0); + }); + + describe('when braches request returns unsafe content', () => { + beforeEach(() => { + mock + .onGet(mockCommitPath) + .reply(200, '<a onload="alert(\'xss!\');" href="/-/commits/master">master</a>'); + }); + + it('displays sanitized html', async () => { + loadBranches(el); + await waitForPromises(); + + expect(el.innerHTML).toBe( + '<div class="commit-info branches"><a href="/-/commits/master">master</a></div>', + ); + }); + }); + + describe('when braches request fails', () => { + beforeEach(() => { + mock.onGet(mockCommitPath).reply(500, 'Error!'); + }); + + it('attempts to load and renders an error', async () => { + loadBranches(el); + await waitForPromises(); + + expect(el.innerHTML).toBe( + '<div class="commit-info branches">Failed to load branches. Please try again.</div>', + ); + }); + }); +}); diff --git a/spec/frontend/projects/components/__snapshots__/project_delete_button_spec.js.snap b/spec/frontend/projects/components/__snapshots__/project_delete_button_spec.js.snap index 455467e7b29..a0fd6012546 100644 --- a/spec/frontend/projects/components/__snapshots__/project_delete_button_spec.js.snap +++ b/spec/frontend/projects/components/__snapshots__/project_delete_button_spec.js.snap @@ -17,6 +17,7 @@ exports[`Project remove modal initialized matches the snapshot 1`] = ` /> <gl-button-stub + buttontextclasses="" category="primary" icon="" role="button" diff --git a/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap b/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap index 692b8f6cf52..4630415f61c 100644 --- a/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap +++ b/spec/frontend/projects/components/shared/__snapshots__/delete_button_spec.js.snap @@ -18,6 +18,7 @@ exports[`Project remove modal intialized matches the snapshot 1`] = ` /> <gl-button-stub + buttontextclasses="" category="primary" icon="" role="button" @@ -84,6 +85,7 @@ exports[`Project remove modal intialized matches the snapshot 1`] = ` <template> <gl-button-stub + buttontextclasses="" category="primary" class="js-modal-action-cancel" icon="" @@ -98,6 +100,7 @@ exports[`Project remove modal intialized matches the snapshot 1`] = ` <!----> <gl-button-stub + buttontextclasses="" category="primary" class="js-modal-action-primary" disabled="true" diff --git a/spec/frontend/projects/settings/access_dropdown_spec.js b/spec/frontend/projects/settings/access_dropdown_spec.js index 3b375c5610f..41b9c0c3763 100644 --- a/spec/frontend/projects/settings/access_dropdown_spec.js +++ b/spec/frontend/projects/settings/access_dropdown_spec.js @@ -14,6 +14,7 @@ describe('AccessDropdown', () => { `); const $dropdown = $('#dummy-dropdown'); $dropdown.data('defaultLabel', defaultLabel); + gon.features = { deployKeysOnProtectedBranches: true }; const options = { $dropdown, accessLevelsData: { @@ -37,6 +38,9 @@ describe('AccessDropdown', () => { { type: LEVEL_TYPES.GROUP }, { type: LEVEL_TYPES.GROUP }, { type: LEVEL_TYPES.GROUP }, + { type: LEVEL_TYPES.DEPLOY_KEY }, + { type: LEVEL_TYPES.DEPLOY_KEY }, + { type: LEVEL_TYPES.DEPLOY_KEY }, ]; beforeEach(() => { @@ -49,7 +53,7 @@ describe('AccessDropdown', () => { const label = dropdown.toggleLabel(); - expect(label).toBe('1 role, 2 users, 3 groups'); + expect(label).toBe('1 role, 2 users, 3 deploy keys, 3 groups'); expect($dropdownToggleText).not.toHaveClass('is-default'); }); @@ -122,6 +126,21 @@ describe('AccessDropdown', () => { expect($dropdownToggleText).not.toHaveClass('is-default'); }); }); + + describe('with users and deploy keys', () => { + beforeEach(() => { + const selectedTypes = [LEVEL_TYPES.DEPLOY_KEY, LEVEL_TYPES.USER]; + dropdown.setSelectedItems(dummyItems.filter(item => selectedTypes.includes(item.type))); + $dropdownToggleText.addClass('is-default'); + }); + + it('displays number of deploy keys', () => { + const label = dropdown.toggleLabel(); + + expect(label).toBe('2 users, 3 deploy keys'); + expect($dropdownToggleText).not.toHaveClass('is-default'); + }); + }); }); describe('userRowHtml', () => { diff --git a/spec/frontend/projects/settings_service_desk/components/service_desk_root_spec.js b/spec/frontend/projects/settings_service_desk/components/service_desk_root_spec.js index 0f3b699f6b2..62aeb4ddee5 100644 --- a/spec/frontend/projects/settings_service_desk/components/service_desk_root_spec.js +++ b/spec/frontend/projects/settings_service_desk/components/service_desk_root_spec.js @@ -218,9 +218,7 @@ describe('ServiceDeskRoot', () => { .$nextTick() .then(waitForPromises) .then(() => { - expect(wrapper.html()).toContain( - 'An error occurred while saving the template. Please check if the template exists.', - ); + expect(wrapper.html()).toContain('An error occured while making the changes:'); }); }); }); |