diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 18:08:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 18:08:04 +0300 |
commit | f2151c65d5826f0609a716e185893787b6375ae3 (patch) | |
tree | aeac6ff3ac12329ddf137b80fb69064eecf7dd36 /spec/javascripts | |
parent | 553a22402b0c176b0486cac0009af085122c00f3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
4 files changed, 0 insertions, 550 deletions
diff --git a/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js b/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js deleted file mode 100644 index 1580f32cfca..00000000000 --- a/spec/javascripts/sidebar/components/time_tracking/time_tracker_spec.js +++ /dev/null @@ -1,278 +0,0 @@ -import Vue from 'vue'; - -import mountComponent from 'spec/helpers/vue_mount_component_helper'; -import TimeTracker from '~/sidebar/components/time_tracking/time_tracker.vue'; - -describe('Issuable Time Tracker', () => { - let initialData; - let vm; - - const initTimeTrackingComponent = ({ - timeEstimate, - timeSpent, - timeEstimateHumanReadable, - timeSpentHumanReadable, - limitToHours, - }) => { - setFixtures(` - <div> - <div id="mock-container"></div> - </div> - `); - - initialData = { - timeEstimate, - timeSpent, - humanTimeEstimate: timeEstimateHumanReadable, - humanTimeSpent: timeSpentHumanReadable, - limitToHours: Boolean(limitToHours), - rootPath: '/', - }; - - const TimeTrackingComponent = Vue.extend({ - ...TimeTracker, - components: { - ...TimeTracker.components, - transition: { - // disable animations - template: '<div><slot></slot></div>', - }, - }, - }); - vm = mountComponent(TimeTrackingComponent, initialData, '#mock-container'); - }; - - afterEach(() => { - vm.$destroy(); - }); - - describe('Initialization', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 10000, // 2h 46m - timeSpent: 5000, // 1h 23m - timeEstimateHumanReadable: '2h 46m', - timeSpentHumanReadable: '1h 23m', - }); - }); - - it('should return something defined', () => { - expect(vm).toBeDefined(); - }); - - it('should correctly set timeEstimate', done => { - Vue.nextTick(() => { - expect(vm.timeEstimate).toBe(initialData.timeEstimate); - done(); - }); - }); - - it('should correctly set time_spent', done => { - Vue.nextTick(() => { - expect(vm.timeSpent).toBe(initialData.timeSpent); - done(); - }); - }); - }); - - describe('Content Display', () => { - describe('Panes', () => { - describe('Comparison pane', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 100000, // 1d 3h - timeSpent: 5000, // 1h 23m - timeEstimateHumanReadable: '1d 3h', - timeSpentHumanReadable: '1h 23m', - }); - }); - - it('should show the "Comparison" pane when timeEstimate and time_spent are truthy', done => { - Vue.nextTick(() => { - expect(vm.showComparisonState).toBe(true); - const $comparisonPane = vm.$el.querySelector('.time-tracking-comparison-pane'); - - expect($comparisonPane).toBeVisible(); - done(); - }); - }); - - it('should show full times when the sidebar is collapsed', done => { - Vue.nextTick(() => { - const timeTrackingText = vm.$el.querySelector('.time-tracking-collapsed-summary span') - .innerText; - - expect(timeTrackingText).toBe('1h 23m / 1d 3h'); - done(); - }); - }); - - describe('Remaining meter', () => { - it('should display the remaining meter with the correct width', done => { - Vue.nextTick(() => { - expect( - vm.$el.querySelector('.time-tracking-comparison-pane .progress[value="5"]'), - ).not.toBeNull(); - done(); - }); - }); - - it('should display the remaining meter with the correct background color when within estimate', done => { - Vue.nextTick(() => { - expect( - vm.$el.querySelector('.time-tracking-comparison-pane .progress[variant="primary"]'), - ).not.toBeNull(); - done(); - }); - }); - - it('should display the remaining meter with the correct background color when over estimate', done => { - vm.timeEstimate = 10000; // 2h 46m - vm.timeSpent = 20000000; // 231 days - Vue.nextTick(() => { - expect( - vm.$el.querySelector('.time-tracking-comparison-pane .progress[variant="danger"]'), - ).not.toBeNull(); - done(); - }); - }); - }); - }); - - describe('Comparison pane when limitToHours is true', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 100000, // 1d 3h - timeSpent: 5000, // 1h 23m - timeEstimateHumanReadable: '', - timeSpentHumanReadable: '', - limitToHours: true, - }); - }); - - it('should show the correct tooltip text', done => { - Vue.nextTick(() => { - expect(vm.showComparisonState).toBe(true); - const $title = vm.$el.querySelector('.time-tracking-content .compare-meter').dataset - .originalTitle; - - expect($title).toBe('Time remaining: 26h 23m'); - done(); - }); - }); - }); - - describe('Estimate only pane', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 10000, // 2h 46m - timeSpent: 0, - timeEstimateHumanReadable: '2h 46m', - timeSpentHumanReadable: '', - }); - }); - - it('should display the human readable version of time estimated', done => { - Vue.nextTick(() => { - const estimateText = vm.$el.querySelector('.time-tracking-estimate-only-pane') - .innerText; - const correctText = 'Estimated: 2h 46m'; - - expect(estimateText).toBe(correctText); - done(); - }); - }); - }); - - describe('Spent only pane', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 0, - timeSpent: 5000, // 1h 23m - timeEstimateHumanReadable: '2h 46m', - timeSpentHumanReadable: '1h 23m', - }); - }); - - it('should display the human readable version of time spent', done => { - Vue.nextTick(() => { - const spentText = vm.$el.querySelector('.time-tracking-spend-only-pane').innerText; - const correctText = 'Spent: 1h 23m'; - - expect(spentText).toBe(correctText); - done(); - }); - }); - }); - - describe('No time tracking pane', () => { - beforeEach(() => { - initTimeTrackingComponent({ - timeEstimate: 0, - timeSpent: 0, - timeEstimateHumanReadable: '', - timeSpentHumanReadable: '', - }); - }); - - it('should only show the "No time tracking" pane when both timeEstimate and time_spent are falsey', done => { - Vue.nextTick(() => { - const $noTrackingPane = vm.$el.querySelector('.time-tracking-no-tracking-pane'); - const noTrackingText = $noTrackingPane.innerText; - const correctText = 'No estimate or time spent'; - - expect(vm.showNoTimeTrackingState).toBe(true); - expect($noTrackingPane).toBeVisible(); - expect(noTrackingText).toBe(correctText); - done(); - }); - }); - }); - - describe('Help pane', () => { - const helpButton = () => vm.$el.querySelector('.help-button'); - const closeHelpButton = () => vm.$el.querySelector('.close-help-button'); - const helpPane = () => vm.$el.querySelector('.time-tracking-help-state'); - - beforeEach(done => { - initTimeTrackingComponent({ timeEstimate: 0, timeSpent: 0 }); - - Vue.nextTick() - .then(done) - .catch(done.fail); - }); - - it('should not show the "Help" pane by default', () => { - expect(vm.showHelpState).toBe(false); - expect(helpPane()).toBeNull(); - }); - - it('should show the "Help" pane when help button is clicked', done => { - helpButton().click(); - - Vue.nextTick() - .then(() => { - expect(vm.showHelpState).toBe(true); - expect(helpPane()).toBeVisible(); - }) - .then(done) - .catch(done.fail); - }); - - it('should not show the "Help" pane when help button is clicked and then closed', done => { - helpButton().click(); - - Vue.nextTick() - .then(() => closeHelpButton().click()) - .then(() => Vue.nextTick()) - .then(() => { - expect(vm.showHelpState).toBe(false); - expect(helpPane()).toBeNull(); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - }); -}); diff --git a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js b/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js deleted file mode 100644 index 5296908afe2..00000000000 --- a/spec/javascripts/sidebar/lock/lock_issue_sidebar_spec.js +++ /dev/null @@ -1,99 +0,0 @@ -import Vue from 'vue'; -import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper'; -import lockIssueSidebar from '~/sidebar/components/lock/lock_issue_sidebar.vue'; - -describe('LockIssueSidebar', () => { - let vm1; - let vm2; - - beforeEach(() => { - const Component = Vue.extend(lockIssueSidebar); - - const mediator = { - service: { - update: Promise.resolve(true), - }, - - store: { - isLockDialogOpen: false, - }, - }; - - vm1 = new Component({ - propsData: { - isLocked: true, - isEditable: true, - mediator, - issuableType: 'issue', - }, - }).$mount(); - - vm2 = new Component({ - propsData: { - isLocked: false, - isEditable: false, - mediator, - issuableType: 'merge_request', - }, - }).$mount(); - }); - - it('shows if locked and/or editable', () => { - expect(vm1.$el.innerHTML.includes('Edit')).toBe(true); - - expect(vm1.$el.innerHTML.includes('Locked')).toBe(true); - - expect(vm2.$el.innerHTML.includes('Unlocked')).toBe(true); - }); - - it('displays the edit form when editable', done => { - expect(vm1.isLockDialogOpen).toBe(false); - - vm1.$el.querySelector('.lock-edit').click(); - - expect(vm1.isLockDialogOpen).toBe(true); - - vm1.$nextTick(() => { - expect(vm1.$el.innerHTML.includes('Unlock this issue?')).toBe(true); - - done(); - }); - }); - - it('tracks an event when "Edit" is clicked', () => { - const spy = mockTracking('_category_', vm1.$el, spyOn); - triggerEvent('.lock-edit'); - - expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', { - label: 'right_sidebar', - property: 'lock_issue', - }); - }); - - it('displays the edit form when opened from collapsed state', done => { - expect(vm1.isLockDialogOpen).toBe(false); - - vm1.$el.querySelector('.sidebar-collapsed-icon').click(); - - expect(vm1.isLockDialogOpen).toBe(true); - - setTimeout(() => { - expect(vm1.$el.innerHTML.includes('Unlock this issue?')).toBe(true); - - done(); - }); - }); - - it('does not display the edit form when opened from collapsed state if not editable', done => { - expect(vm2.isLockDialogOpen).toBe(false); - - vm2.$el.querySelector('.sidebar-collapsed-icon').click(); - - Vue.nextTick() - .then(() => { - expect(vm2.isLockDialogOpen).toBe(false); - }) - .then(done) - .catch(done.fail); - }); -}); diff --git a/spec/javascripts/sidebar/mock_data.js b/spec/javascripts/sidebar/mock_data.js deleted file mode 100644 index 701a97ba5a6..00000000000 --- a/spec/javascripts/sidebar/mock_data.js +++ /dev/null @@ -1,7 +0,0 @@ -// No new code should be added to this file. Instead, modify the -// file this one re-exports from. For more detail about why, see: -// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349 - -import mockData from '../../frontend/sidebar/mock_data'; - -export default mockData; diff --git a/spec/javascripts/sidebar/sidebar_move_issue_spec.js b/spec/javascripts/sidebar/sidebar_move_issue_spec.js deleted file mode 100644 index ec712450f2e..00000000000 --- a/spec/javascripts/sidebar/sidebar_move_issue_spec.js +++ /dev/null @@ -1,166 +0,0 @@ -import $ from 'jquery'; -import MockAdapter from 'axios-mock-adapter'; -import axios from '~/lib/utils/axios_utils'; -import SidebarMediator from '~/sidebar/sidebar_mediator'; -import SidebarStore from '~/sidebar/stores/sidebar_store'; -import SidebarService from '~/sidebar/services/sidebar_service'; -import SidebarMoveIssue from '~/sidebar/lib/sidebar_move_issue'; -import Mock from './mock_data'; - -describe('SidebarMoveIssue', function() { - let mock; - - beforeEach(() => { - mock = new MockAdapter(axios); - const mockData = Mock.responseMap.GET['/autocomplete/projects?project_id=15']; - mock.onGet('/autocomplete/projects?project_id=15').reply(200, mockData); - this.mediator = new SidebarMediator(Mock.mediator); - this.$content = $(` - <div class="dropdown"> - <div class="js-toggle"></div> - <div class="dropdown-menu"> - <div class="dropdown-content"></div> - </div> - <div class="js-confirm-button"></div> - </div> - `); - this.$toggleButton = this.$content.find('.js-toggle'); - this.$confirmButton = this.$content.find('.js-confirm-button'); - - this.sidebarMoveIssue = new SidebarMoveIssue( - this.mediator, - this.$toggleButton, - this.$confirmButton, - ); - this.sidebarMoveIssue.init(); - }); - - afterEach(() => { - SidebarService.singleton = null; - SidebarStore.singleton = null; - SidebarMediator.singleton = null; - - this.sidebarMoveIssue.destroy(); - mock.restore(); - }); - - describe('init', () => { - it('should initialize the dropdown and listeners', () => { - spyOn(this.sidebarMoveIssue, 'initDropdown'); - spyOn(this.sidebarMoveIssue, 'addEventListeners'); - - this.sidebarMoveIssue.init(); - - expect(this.sidebarMoveIssue.initDropdown).toHaveBeenCalled(); - expect(this.sidebarMoveIssue.addEventListeners).toHaveBeenCalled(); - }); - }); - - describe('destroy', () => { - it('should remove the listeners', () => { - spyOn(this.sidebarMoveIssue, 'removeEventListeners'); - - this.sidebarMoveIssue.destroy(); - - expect(this.sidebarMoveIssue.removeEventListeners).toHaveBeenCalled(); - }); - }); - - describe('initDropdown', () => { - it('should initialize the gl_dropdown', () => { - spyOn($.fn, 'glDropdown'); - - this.sidebarMoveIssue.initDropdown(); - - expect($.fn.glDropdown).toHaveBeenCalled(); - }); - - it('escapes html from project name', done => { - this.$toggleButton.dropdown('toggle'); - - setTimeout(() => { - expect(this.$content.find('.js-move-issue-dropdown-item')[1].innerHTML.trim()).toEqual( - '<img src=x onerror=alert(document.domain)> foo / bar', - ); - done(); - }); - }); - }); - - describe('onConfirmClicked', () => { - it('should move the issue with valid project ID', () => { - spyOn(this.mediator, 'moveIssue').and.returnValue(Promise.resolve()); - this.mediator.setMoveToProjectId(7); - - this.sidebarMoveIssue.onConfirmClicked(); - - expect(this.mediator.moveIssue).toHaveBeenCalled(); - expect(this.$confirmButton.prop('disabled')).toBeTruthy(); - expect(this.$confirmButton.hasClass('is-loading')).toBe(true); - }); - - it('should remove loading state from confirm button on failure', done => { - spyOn(window, 'Flash'); - spyOn(this.mediator, 'moveIssue').and.returnValue(Promise.reject()); - this.mediator.setMoveToProjectId(7); - - this.sidebarMoveIssue.onConfirmClicked(); - - expect(this.mediator.moveIssue).toHaveBeenCalled(); - // Wait for the move issue request to fail - setTimeout(() => { - expect(window.Flash).toHaveBeenCalled(); - expect(this.$confirmButton.prop('disabled')).toBeFalsy(); - expect(this.$confirmButton.hasClass('is-loading')).toBe(false); - done(); - }); - }); - - it('should not move the issue with id=0', () => { - spyOn(this.mediator, 'moveIssue'); - this.mediator.setMoveToProjectId(0); - - this.sidebarMoveIssue.onConfirmClicked(); - - expect(this.mediator.moveIssue).not.toHaveBeenCalled(); - }); - }); - - it('should set moveToProjectId on dropdown item "No project" click', done => { - spyOn(this.mediator, 'setMoveToProjectId'); - - // Open the dropdown - this.$toggleButton.dropdown('toggle'); - - // Wait for the autocomplete request to finish - setTimeout(() => { - this.$content - .find('.js-move-issue-dropdown-item') - .eq(0) - .trigger('click'); - - expect(this.mediator.setMoveToProjectId).toHaveBeenCalledWith(0); - expect(this.$confirmButton.prop('disabled')).toBeTruthy(); - done(); - }, 0); - }); - - it('should set moveToProjectId on dropdown item click', done => { - spyOn(this.mediator, 'setMoveToProjectId'); - - // Open the dropdown - this.$toggleButton.dropdown('toggle'); - - // Wait for the autocomplete request to finish - setTimeout(() => { - this.$content - .find('.js-move-issue-dropdown-item') - .eq(1) - .trigger('click'); - - expect(this.mediator.setMoveToProjectId).toHaveBeenCalledWith(20); - expect(this.$confirmButton.attr('disabled')).toBe(undefined); - done(); - }, 0); - }); -}); |