diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 21:06:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-26 21:06:33 +0300 |
commit | 581c10e344d85729e77fce78513819d159289dc5 (patch) | |
tree | ea84e89fddcafe5a8abdc8a9a5f7f210b6644e77 /spec | |
parent | 68d3f33d5194c446812d09f079749ddf56f95378 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
9 files changed, 188 insertions, 93 deletions
diff --git a/spec/frontend/environments/environment_monitoring_spec.js b/spec/frontend/environments/environment_monitoring_spec.js new file mode 100644 index 00000000000..8e67f799dc0 --- /dev/null +++ b/spec/frontend/environments/environment_monitoring_spec.js @@ -0,0 +1,39 @@ +import { shallowMount } from '@vue/test-utils'; +import MonitoringComponent from '~/environments/components/environment_monitoring.vue'; +import Icon from '~/vue_shared/components/icon.vue'; + +describe('Monitoring Component', () => { + let wrapper; + + const monitoringUrl = 'https://gitlab.com'; + + const createWrapper = () => { + wrapper = shallowMount(MonitoringComponent, { + sync: false, + attachToDocument: true, + propsData: { + monitoringUrl, + }, + }); + }; + + const findIcons = () => wrapper.findAll(Icon); + const findIconsByName = name => findIcons().filter(icon => icon.props('name') === name); + + beforeEach(() => { + createWrapper(); + }); + + describe('computed', () => { + it('title', () => { + expect(wrapper.vm.title).toBe('Monitoring'); + }); + }); + + it('should render a link to environment monitoring page', () => { + expect(wrapper.attributes('href')).toEqual(monitoringUrl); + expect(findIconsByName('chart').length).toBe(1); + expect(wrapper.attributes('data-original-title')).toBe('Monitoring'); + expect(wrapper.attributes('aria-label')).toBe('Monitoring'); + }); +}); diff --git a/spec/frontend/environments/environment_stop_spec.js b/spec/frontend/environments/environment_stop_spec.js new file mode 100644 index 00000000000..ab714728311 --- /dev/null +++ b/spec/frontend/environments/environment_stop_spec.js @@ -0,0 +1,40 @@ +import $ from 'jquery'; +import { shallowMount } from '@vue/test-utils'; +import StopComponent from '~/environments/components/environment_stop.vue'; +import LoadingButton from '~/vue_shared/components/loading_button.vue'; +import eventHub from '~/environments/event_hub'; + +$.fn.tooltip = () => {}; + +describe('Stop Component', () => { + let wrapper; + + const createWrapper = () => { + wrapper = shallowMount(StopComponent, { + sync: false, + attachToDocument: true, + propsData: { + environment: {}, + }, + }); + }; + + const findButton = () => wrapper.find(LoadingButton); + + beforeEach(() => { + jest.spyOn(window, 'confirm'); + + createWrapper(); + }); + + it('should render a button to stop the environment', () => { + expect(findButton().exists()).toBe(true); + expect(wrapper.attributes('data-original-title')).toEqual('Stop environment'); + }); + + it('emits requestStopEnvironment in the event hub when button is clicked', () => { + jest.spyOn(eventHub, '$emit'); + findButton().vm.$emit('click'); + expect(eventHub.$emit).toHaveBeenCalledWith('requestStopEnvironment', wrapper.vm.environment); + }); +}); diff --git a/spec/frontend/environments/environment_terminal_button_spec.js b/spec/frontend/environments/environment_terminal_button_spec.js new file mode 100644 index 00000000000..9aa2b82736c --- /dev/null +++ b/spec/frontend/environments/environment_terminal_button_spec.js @@ -0,0 +1,36 @@ +import { shallowMount } from '@vue/test-utils'; +import TerminalComponent from '~/environments/components/environment_terminal_button.vue'; + +describe('Stop Component', () => { + let wrapper; + const terminalPath = '/path'; + + const mountWithProps = props => { + wrapper = shallowMount(TerminalComponent, { + sync: false, + attachToDocument: true, + propsData: props, + }); + }; + + beforeEach(() => { + mountWithProps({ terminalPath }); + }); + + describe('computed', () => { + it('title', () => { + expect(wrapper.vm.title).toEqual('Terminal'); + }); + }); + + it('should render a link to open a web terminal with the provided path', () => { + expect(wrapper.is('a')).toBe(true); + expect(wrapper.attributes('data-original-title')).toBe('Terminal'); + expect(wrapper.attributes('aria-label')).toBe('Terminal'); + expect(wrapper.attributes('href')).toBe(terminalPath); + }); + + it('should render a non-disabled button', () => { + expect(wrapper.classes()).not.toContain('disabled'); + }); +}); diff --git a/spec/javascripts/environments/environment_monitoring_spec.js b/spec/javascripts/environments/environment_monitoring_spec.js deleted file mode 100644 index f8d8223967a..00000000000 --- a/spec/javascripts/environments/environment_monitoring_spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import Vue from 'vue'; -import monitoringComp from '~/environments/components/environment_monitoring.vue'; - -describe('Monitoring Component', () => { - let MonitoringComponent; - let component; - - const monitoringUrl = 'https://gitlab.com'; - - beforeEach(() => { - MonitoringComponent = Vue.extend(monitoringComp); - - component = new MonitoringComponent({ - propsData: { - monitoringUrl, - }, - }).$mount(); - }); - - describe('computed', () => { - it('title', () => { - expect(component.title).toEqual('Monitoring'); - }); - }); - - it('should render a link to environment monitoring page', () => { - expect(component.$el.getAttribute('href')).toEqual(monitoringUrl); - expect(component.$el.querySelector('.fa-area-chart')).toBeDefined(); - expect(component.$el.getAttribute('data-original-title')).toEqual('Monitoring'); - expect(component.$el.getAttribute('aria-label')).toEqual('Monitoring'); - }); -}); diff --git a/spec/javascripts/environments/environment_stop_spec.js b/spec/javascripts/environments/environment_stop_spec.js deleted file mode 100644 index 4d9caa57566..00000000000 --- a/spec/javascripts/environments/environment_stop_spec.js +++ /dev/null @@ -1,23 +0,0 @@ -import Vue from 'vue'; -import stopComp from '~/environments/components/environment_stop.vue'; - -describe('Stop Component', () => { - let StopComponent; - let component; - - beforeEach(() => { - StopComponent = Vue.extend(stopComp); - spyOn(window, 'confirm').and.returnValue(true); - - component = new StopComponent({ - propsData: { - environment: {}, - }, - }).$mount(); - }); - - it('should render a button to stop the environment', () => { - expect(component.$el.tagName).toEqual('BUTTON'); - expect(component.$el.getAttribute('data-original-title')).toEqual('Stop environment'); - }); -}); diff --git a/spec/javascripts/environments/environment_terminal_button_spec.js b/spec/javascripts/environments/environment_terminal_button_spec.js deleted file mode 100644 index fc98e656efe..00000000000 --- a/spec/javascripts/environments/environment_terminal_button_spec.js +++ /dev/null @@ -1,35 +0,0 @@ -import Vue from 'vue'; -import terminalComp from '~/environments/components/environment_terminal_button.vue'; - -describe('Stop Component', () => { - let component; - const terminalPath = '/path'; - - const mountWithProps = props => { - const TerminalComponent = Vue.extend(terminalComp); - component = new TerminalComponent({ - propsData: props, - }).$mount(); - }; - - beforeEach(() => { - mountWithProps({ terminalPath }); - }); - - describe('computed', () => { - it('title', () => { - expect(component.title).toEqual('Terminal'); - }); - }); - - it('should render a link to open a web terminal with the provided path', () => { - expect(component.$el.tagName).toEqual('A'); - expect(component.$el.getAttribute('data-original-title')).toEqual('Terminal'); - expect(component.$el.getAttribute('aria-label')).toEqual('Terminal'); - expect(component.$el.getAttribute('href')).toEqual(terminalPath); - }); - - it('should render a non-disabled button', () => { - expect(component.$el.classList).not.toContain('disabled'); - }); -}); diff --git a/spec/javascripts/notes/components/note_awards_list_spec.js b/spec/javascripts/notes/components/note_awards_list_spec.js index ede541a5247..90aa1684272 100644 --- a/spec/javascripts/notes/components/note_awards_list_spec.js +++ b/spec/javascripts/notes/components/note_awards_list_spec.js @@ -61,6 +61,66 @@ describe('note_awards_list component', () => { expect(vm.$el.querySelector('.js-add-award')).toBeDefined(); }); + describe('when the user name contains special HTML characters', () => { + const createAwardEmoji = (_, index) => ({ + name: 'art', + user: { id: index, name: `&<>"\`'-${index}`, username: `user-${index}` }, + }); + + const mountComponent = () => { + const Component = Vue.extend(awardsNote); + vm = new Component({ + store, + propsData: { + awards: awardsMock, + noteAuthorId: 0, + noteId: '545', + canAwardEmoji: true, + toggleAwardPath: '/gitlab-org/gitlab-foss/notes/545/toggle_award_emoji', + }, + }).$mount(); + }; + + const findTooltip = () => + vm.$el.querySelector('[data-original-title]').getAttribute('data-original-title'); + + it('should only escape & and " characters', () => { + awardsMock = [...new Array(1)].map(createAwardEmoji); + mountComponent(); + const escapedName = awardsMock[0].user.name.replace(/&/g, '&').replace(/"/g, '"'); + + expect(vm.$el.querySelector('[data-original-title]').outerHTML).toContain(escapedName); + }); + + it('should not escape special HTML characters twice when only 1 person awarded', () => { + awardsMock = [...new Array(1)].map(createAwardEmoji); + mountComponent(); + + awardsMock.forEach(award => { + expect(findTooltip()).toContain(award.user.name); + }); + }); + + it('should not escape special HTML characters twice when 2 people awarded', () => { + awardsMock = [...new Array(2)].map(createAwardEmoji); + mountComponent(); + + awardsMock.forEach(award => { + expect(findTooltip()).toContain(award.user.name); + }); + }); + + it('should not escape special HTML characters twice when more than 10 people awarded', () => { + awardsMock = [...new Array(11)].map(createAwardEmoji); + mountComponent(); + + // Testing only the first 10 awards since 11 onward will not be displayed. + awardsMock.slice(0, 10).forEach(award => { + expect(findTooltip()).toContain(award.user.name); + }); + }); + }); + describe('when the user cannot award emoji', () => { beforeEach(() => { const Component = Vue.extend(awardsNote); diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9cb3229aeb1..bad05990965 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1530,7 +1530,7 @@ describe Repository do expect(merge_request.reload.rebase_commit_sha).to eq(new_sha) end - it 'does rollback when an error is encountered in the second step' do + it 'does rollback when a PreReceiveError is encountered in the second step' do second_response = double(pre_receive_error: 'my_error', git_error: nil) mock_gitaly(second_response) @@ -1541,6 +1541,17 @@ describe Repository do expect(merge_request.reload.rebase_commit_sha).to be_nil end + it 'does rollback when a GitError is encountered in the second step' do + second_response = double(pre_receive_error: nil, git_error: 'git error') + mock_gitaly(second_response) + + expect do + repository.rebase(user, merge_request) + end.to raise_error(Gitlab::Git::Repository::GitError) + + expect(merge_request.reload.rebase_commit_sha).to be_nil + end + def mock_gitaly(second_response) responses = [ double(rebase_sha: new_sha).as_null_object, diff --git a/spec/policies/personal_snippet_policy_spec.rb b/spec/policies/personal_snippet_policy_spec.rb index 36b4ac16cf0..0abdf7382be 100644 --- a/spec/policies/personal_snippet_policy_spec.rb +++ b/spec/policies/personal_snippet_policy_spec.rb @@ -11,8 +11,7 @@ describe PersonalSnippetPolicy do let(:author_permissions) do [ :update_personal_snippet, - :admin_personal_snippet, - :destroy_personal_snippet + :admin_personal_snippet ] end |