diff options
Diffstat (limited to 'spec/javascripts')
3 files changed, 90 insertions, 108 deletions
diff --git a/spec/javascripts/ide/components/ide_status_bar_spec.js b/spec/javascripts/ide/components/ide_status_bar_spec.js index 69f163574fb..3facf1c266a 100644 --- a/spec/javascripts/ide/components/ide_status_bar_spec.js +++ b/spec/javascripts/ide/components/ide_status_bar_spec.js @@ -1,94 +1,129 @@ import Vue from 'vue'; +import _ from 'lodash'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; -import store from '~/ide/stores'; -import ideStatusBar from '~/ide/components/ide_status_bar.vue'; +import { TEST_HOST } from 'spec/test_constants'; +import { createStore } from '~/ide/stores'; +import IdeStatusBar from '~/ide/components/ide_status_bar.vue'; import { rightSidebarViews } from '~/ide/constants'; -import { resetStore } from '../helpers'; import { projectData } from '../mock_data'; +const TEST_PROJECT_ID = 'abcproject'; +const TEST_MERGE_REQUEST_ID = '9001'; +const TEST_MERGE_REQUEST_URL = `${TEST_HOST}merge-requests/${TEST_MERGE_REQUEST_ID}`; + describe('ideStatusBar', () => { + let store; let vm; - beforeEach(() => { - const Component = Vue.extend(ideStatusBar); + const createComponent = () => { + vm = createComponentWithStore(Vue.extend(IdeStatusBar), store).$mount(); + }; + const findMRStatus = () => vm.$el.querySelector('.js-ide-status-mr'); - store.state.currentProjectId = 'abcproject'; - store.state.projects.abcproject = projectData; + beforeEach(() => { + store = createStore(); + store.state.currentProjectId = TEST_PROJECT_ID; + store.state.projects[TEST_PROJECT_ID] = _.clone(projectData); store.state.currentBranchId = 'master'; - - vm = createComponentWithStore(Component, store).$mount(); }); afterEach(() => { vm.$destroy(); - - resetStore(vm.$store); }); - it('renders the statusbar', () => { - expect(vm.$el.className).toBe('ide-status-bar'); - }); + describe('default', () => { + beforeEach(() => { + createComponent(); + }); - describe('mounted', () => { it('triggers a setInterval', () => { expect(vm.intervalId).not.toBe(null); }); - }); - describe('commitAgeUpdate', () => { - beforeEach(function() { - jasmine.clock().install(); - spyOn(vm, 'commitAgeUpdate').and.callFake(() => {}); - vm.startTimer(); + it('renders the statusbar', () => { + expect(vm.$el.className).toBe('ide-status-bar'); }); - afterEach(function() { - jasmine.clock().uninstall(); - }); + describe('commitAgeUpdate', () => { + beforeEach(function() { + jasmine.clock().install(); + spyOn(vm, 'commitAgeUpdate').and.callFake(() => {}); + vm.startTimer(); + }); - it('gets called every second', () => { - expect(vm.commitAgeUpdate).not.toHaveBeenCalled(); + afterEach(function() { + jasmine.clock().uninstall(); + }); - jasmine.clock().tick(1100); + it('gets called every second', () => { + expect(vm.commitAgeUpdate).not.toHaveBeenCalled(); - expect(vm.commitAgeUpdate.calls.count()).toEqual(1); + jasmine.clock().tick(1100); - jasmine.clock().tick(1000); + expect(vm.commitAgeUpdate.calls.count()).toEqual(1); - expect(vm.commitAgeUpdate.calls.count()).toEqual(2); + jasmine.clock().tick(1000); + + expect(vm.commitAgeUpdate.calls.count()).toEqual(2); + }); }); - }); - describe('getCommitPath', () => { - it('returns the path to the commit details', () => { - expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de'); + describe('getCommitPath', () => { + it('returns the path to the commit details', () => { + expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de'); + }); + }); + + describe('pipeline status', () => { + it('opens right sidebar on clicking icon', done => { + spyOn(vm, 'openRightPane'); + Vue.set(vm.$store.state.pipelines, 'latestPipeline', { + details: { + status: { + text: 'success', + details_path: 'test', + icon: 'status_success', + }, + }, + commit: { + author_gravatar_url: 'www', + }, + }); + + vm.$nextTick() + .then(() => { + vm.$el.querySelector('.ide-status-pipeline button').click(); + + expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines); + }) + .then(done) + .catch(done.fail); + }); + }); + + it('does not show merge request status', () => { + expect(findMRStatus()).toBe(null); }); }); - describe('pipeline status', () => { - it('opens right sidebar on clicking icon', done => { - spyOn(vm, 'openRightPane'); - Vue.set(vm.$store.state.pipelines, 'latestPipeline', { - details: { - status: { - text: 'success', - details_path: 'test', - icon: 'status_success', + describe('with merge request in store', () => { + beforeEach(() => { + store.state.projects[TEST_PROJECT_ID].mergeRequests = { + [TEST_MERGE_REQUEST_ID]: { + web_url: TEST_MERGE_REQUEST_URL, + references: { + short: `!${TEST_MERGE_REQUEST_ID}`, }, }, - commit: { - author_gravatar_url: 'www', - }, - }); + }; + store.state.currentMergeRequestId = TEST_MERGE_REQUEST_ID; - vm.$nextTick() - .then(() => { - vm.$el.querySelector('.ide-status-pipeline button').click(); + createComponent(); + }); - expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines); - }) - .then(done) - .catch(done.fail); + it('shows merge request status', () => { + expect(findMRStatus().textContent.trim()).toEqual(`Merge request !${TEST_MERGE_REQUEST_ID}`); + expect(findMRStatus().querySelector('a').href).toEqual(TEST_MERGE_REQUEST_URL); }); }); }); diff --git a/spec/javascripts/ide/components/merge_requests/info_spec.js b/spec/javascripts/ide/components/merge_requests/info_spec.js deleted file mode 100644 index 98a29e5128b..00000000000 --- a/spec/javascripts/ide/components/merge_requests/info_spec.js +++ /dev/null @@ -1,51 +0,0 @@ -import Vue from 'vue'; -import '~/behaviors/markdown/render_gfm'; -import { createStore } from '~/ide/stores'; -import Info from '~/ide/components/merge_requests/info.vue'; -import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; - -describe('IDE merge request details', () => { - let Component; - let vm; - - beforeAll(() => { - Component = Vue.extend(Info); - }); - - beforeEach(() => { - const store = createStore(); - store.state.currentProjectId = 'gitlab-ce'; - store.state.currentMergeRequestId = 1; - store.state.projects['gitlab-ce'] = { - mergeRequests: { - 1: { - iid: 1, - title: 'Testing', - title_html: '<span class="title-html">Testing</span>', - description: 'Description', - description_html: '<p class="description-html">Description HTML</p>', - }, - }, - }; - - vm = createComponentWithStore(Component, store).$mount(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('renders merge request IID', () => { - expect(vm.$el.querySelector('.detail-page-header').textContent).toContain('!1'); - }); - - it('renders title as HTML', () => { - expect(vm.$el.querySelector('.title-html')).not.toBe(null); - expect(vm.$el.querySelector('.title').textContent).toContain('Testing'); - }); - - it('renders description as HTML', () => { - expect(vm.$el.querySelector('.description-html')).not.toBe(null); - expect(vm.$el.querySelector('.description').textContent).toContain('Description HTML'); - }); -}); diff --git a/spec/javascripts/ide/stores/actions/merge_request_spec.js b/spec/javascripts/ide/stores/actions/merge_request_spec.js index ee0e51003c5..498e5142f0c 100644 --- a/spec/javascripts/ide/stores/actions/merge_request_spec.js +++ b/spec/javascripts/ide/stores/actions/merge_request_spec.js @@ -137,9 +137,7 @@ describe('IDE store merge request actions', () => { store .dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 }) .then(() => { - expect(service.getProjectMergeRequestData).toHaveBeenCalledWith(TEST_PROJECT, 1, { - render_html: true, - }); + expect(service.getProjectMergeRequestData).toHaveBeenCalledWith(TEST_PROJECT, 1); done(); }) |