diff options
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/commit/pipelines/pipelines_spec.js | 27 | ||||
-rw-r--r-- | spec/javascripts/fixtures/merge_requests.rb | 13 | ||||
-rw-r--r-- | spec/javascripts/fixtures/pipelines_table.html.haml | 1 | ||||
-rw-r--r-- | spec/javascripts/issue_show/components/description_spec.js | 12 | ||||
-rw-r--r-- | spec/javascripts/merge_request_notes_spec.js | 96 | ||||
-rw-r--r-- | spec/javascripts/pipelines/async_button_spec.js | 44 | ||||
-rw-r--r-- | spec/javascripts/pipelines/pipelines_actions_spec.js | 31 | ||||
-rw-r--r-- | spec/javascripts/vue_shared/components/pipelines_table_row_spec.js (renamed from spec/javascripts/pipelines/pipelines_table_row_spec.js) | 2 | ||||
-rw-r--r-- | spec/javascripts/vue_shared/components/pipelines_table_spec.js (renamed from spec/javascripts/pipelines/pipelines_table_spec.js) | 6 |
9 files changed, 118 insertions, 114 deletions
diff --git a/spec/javascripts/commit/pipelines/pipelines_spec.js b/spec/javascripts/commit/pipelines/pipelines_spec.js index 694f94efcff..ebfd60198b2 100644 --- a/spec/javascripts/commit/pipelines/pipelines_spec.js +++ b/spec/javascripts/commit/pipelines/pipelines_spec.js @@ -1,15 +1,15 @@ import Vue from 'vue'; -import pipelinesTable from '~/commit/pipelines/pipelines_table.vue'; +import PipelinesTable from '~/commit/pipelines/pipelines_table'; describe('Pipelines table in Commits and Merge requests', () => { const jsonFixtureName = 'pipelines/pipelines.json'; let pipeline; - let PipelinesTable; + preloadFixtures('static/pipelines_table.html.raw'); preloadFixtures(jsonFixtureName); beforeEach(() => { - PipelinesTable = Vue.extend(pipelinesTable); + loadFixtures('static/pipelines_table.html.raw'); const pipelines = getJSONFixture(jsonFixtureName).pipelines; pipeline = pipelines.find(p => p.id === 1); }); @@ -26,11 +26,8 @@ describe('Pipelines table in Commits and Merge requests', () => { Vue.http.interceptors.push(pipelinesEmptyResponse); this.component = new PipelinesTable({ - propsData: { - endpoint: 'endpoint', - helpPagePath: 'foo', - }, - }).$mount(); + el: document.querySelector('#commit-pipeline-table-view'), + }); }); afterEach(function () { @@ -61,11 +58,8 @@ describe('Pipelines table in Commits and Merge requests', () => { Vue.http.interceptors.push(pipelinesResponse); this.component = new PipelinesTable({ - propsData: { - endpoint: 'endpoint', - helpPagePath: 'foo', - }, - }).$mount(); + el: document.querySelector('#commit-pipeline-table-view'), + }); }); afterEach(() => { @@ -98,11 +92,8 @@ describe('Pipelines table in Commits and Merge requests', () => { Vue.http.interceptors.push(pipelinesErrorResponse); this.component = new PipelinesTable({ - propsData: { - endpoint: 'endpoint', - helpPagePath: 'foo', - }, - }).$mount(); + el: document.querySelector('#commit-pipeline-table-view'), + }); }); afterEach(function () { diff --git a/spec/javascripts/fixtures/merge_requests.rb b/spec/javascripts/fixtures/merge_requests.rb index 0715f4d5f6b..a746a776548 100644 --- a/spec/javascripts/fixtures/merge_requests.rb +++ b/spec/javascripts/fixtures/merge_requests.rb @@ -55,20 +55,13 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont render_merge_request(example.description, merge_request) end - it 'merge_requests/changes_tab_with_comments.json' do |example| - create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request) - create(:note_on_merge_request, author: admin, project: project, noteable: merge_request) - render_merge_request(example.description, merge_request, action: :diffs, format: :json) - end - private - def render_merge_request(fixture_file_name, merge_request, action: :show, format: :html) - get action, + def render_merge_request(fixture_file_name, merge_request) + get :show, namespace_id: project.namespace.to_param, project_id: project, - id: merge_request.to_param, - format: format + id: merge_request.to_param expect(response).to be_success store_frontend_fixture(response, fixture_file_name) diff --git a/spec/javascripts/fixtures/pipelines_table.html.haml b/spec/javascripts/fixtures/pipelines_table.html.haml new file mode 100644 index 00000000000..ad1682704bb --- /dev/null +++ b/spec/javascripts/fixtures/pipelines_table.html.haml @@ -0,0 +1 @@ +#commit-pipeline-table-view{ data: { endpoint: "endpoint", "help-page-path": "foo" } } diff --git a/spec/javascripts/issue_show/components/description_spec.js b/spec/javascripts/issue_show/components/description_spec.js index f3fdbff01a6..886462c4b9a 100644 --- a/spec/javascripts/issue_show/components/description_spec.js +++ b/spec/javascripts/issue_show/components/description_spec.js @@ -95,18 +95,6 @@ describe('Description component', () => { done(); }); }); - - it('clears task status text when no tasks are present', (done) => { - vm.taskStatus = '0 of 0'; - - setTimeout(() => { - expect( - document.querySelector('.issuable-meta #task_status').textContent.trim(), - ).toBe(''); - - done(); - }); - }); }); it('applies syntax highlighting and math when description changed', (done) => { diff --git a/spec/javascripts/merge_request_notes_spec.js b/spec/javascripts/merge_request_notes_spec.js index b6d0ce02c4f..e54acfa8e44 100644 --- a/spec/javascripts/merge_request_notes_spec.js +++ b/spec/javascripts/merge_request_notes_spec.js @@ -7,92 +7,54 @@ import '~/render_gfm'; import '~/render_math'; import '~/notes'; -const upArrowKeyCode = 38; - describe('Merge request notes', () => { window.gon = window.gon || {}; window.gl = window.gl || {}; gl.utils = gl.utils || {}; - const discussionTabFixture = 'merge_requests/diff_comment.html.raw'; - const changesTabJsonFixture = 'merge_requests/changes_tab_with_comments.json'; - preloadFixtures(discussionTabFixture, changesTabJsonFixture); - - describe('Discussion tab with diff comments', () => { - beforeEach(() => { - loadFixtures(discussionTabFixture); - gl.utils.disableButtonIfEmptyField = _.noop; - window.project_uploads_path = 'http://test.host/uploads'; - $('body').data('page', 'projects:merge_requests:show'); - window.gon.current_user_id = $('.note:last').data('author-id'); - - return new Notes('', []); - }); - - describe('up arrow', () => { - it('edits last comment when triggered in main form', () => { - const upArrowEvent = $.Event('keydown'); - upArrowEvent.which = upArrowKeyCode; - - spyOnEvent('.note:last .js-note-edit', 'click'); - - $('.js-note-text').trigger(upArrowEvent); + const fixture = 'merge_requests/diff_comment.html.raw'; + preloadFixtures(fixture); - expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit'); - }); - - it('edits last comment in discussion when triggered in discussion form', (done) => { - const upArrowEvent = $.Event('keydown'); - upArrowEvent.which = upArrowKeyCode; + beforeEach(() => { + loadFixtures(fixture); + gl.utils.disableButtonIfEmptyField = _.noop; + window.project_uploads_path = 'http://test.host/uploads'; + $('body').data('page', 'projects:merge_requests:show'); + window.gon.current_user_id = $('.note:last').data('author-id'); - spyOnEvent('.note-discussion .js-note-edit', 'click'); - - $('.js-discussion-reply-button').click(); + return new Notes('', []); + }); - setTimeout(() => { - expect( - $('.note-discussion .js-note-text'), - ).toExist(); + describe('up arrow', () => { + it('edits last comment when triggered in main form', () => { + const upArrowEvent = $.Event('keydown'); + upArrowEvent.which = 38; - $('.note-discussion .js-note-text').trigger(upArrowEvent); + spyOnEvent('.note:last .js-note-edit', 'click'); - expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit'); + $('.js-note-text').trigger(upArrowEvent); - done(); - }); - }); + expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit'); }); - }); - describe('Changes tab with diff comments', () => { - beforeEach(() => { - const diffsResponse = getJSONFixture(changesTabJsonFixture); - const noteFormHtml = `<form class="js-new-note-form"> - <textarea class="js-note-text"></textarea> - </form>`; - setFixtures(diffsResponse.html + noteFormHtml); - $('body').data('page', 'projects:merge_requests:show'); - window.gon.current_user_id = $('.note:last').data('author-id'); - - return new Notes('', []); - }); + it('edits last comment in discussion when triggered in discussion form', (done) => { + const upArrowEvent = $.Event('keydown'); + upArrowEvent.which = 38; - describe('up arrow', () => { - it('edits last comment in discussion when triggered in discussion form', (done) => { - const upArrowEvent = $.Event('keydown'); - upArrowEvent.which = upArrowKeyCode; + spyOnEvent('.note-discussion .js-note-edit', 'click'); - spyOnEvent('.note:last .js-note-edit', 'click'); + $('.js-discussion-reply-button').click(); - $('.js-discussion-reply-button').trigger('click'); + setTimeout(() => { + expect( + $('.note-discussion .js-note-text'), + ).toExist(); - setTimeout(() => { - $('.js-note-text').trigger(upArrowEvent); + $('.note-discussion .js-note-text').trigger(upArrowEvent); - expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit'); + expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit'); - done(); - }); + done(); }); }); }); diff --git a/spec/javascripts/pipelines/async_button_spec.js b/spec/javascripts/pipelines/async_button_spec.js index 48620898357..28c9c7ab282 100644 --- a/spec/javascripts/pipelines/async_button_spec.js +++ b/spec/javascripts/pipelines/async_button_spec.js @@ -1,20 +1,25 @@ import Vue from 'vue'; import asyncButtonComp from '~/pipelines/components/async_button.vue'; -import eventHub from '~/pipelines/event_hub'; describe('Pipelines Async Button', () => { let component; + let spy; let AsyncButtonComponent; beforeEach(() => { AsyncButtonComponent = Vue.extend(asyncButtonComp); + spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve()); + component = new AsyncButtonComponent({ propsData: { endpoint: '/foo', title: 'Foo', icon: 'fa fa-foo', cssClass: 'bar', + service: { + postAction: spy, + }, }, }).$mount(); }); @@ -28,7 +33,7 @@ describe('Pipelines Async Button', () => { }); it('should render the provided title', () => { - expect(component.$el.getAttribute('data-original-title')).toContain('Foo'); + expect(component.$el.getAttribute('title')).toContain('Foo'); expect(component.$el.getAttribute('aria-label')).toContain('Foo'); }); @@ -36,12 +41,37 @@ describe('Pipelines Async Button', () => { expect(component.$el.getAttribute('class')).toContain('bar'); }); + it('should call the service when it is clicked with the provided endpoint', () => { + component.$el.click(); + expect(spy).toHaveBeenCalledWith('/foo'); + }); + + it('should hide loading if request fails', () => { + spy = jasmine.createSpy('spy').and.returnValue(Promise.reject()); + + component = new AsyncButtonComponent({ + propsData: { + endpoint: '/foo', + title: 'Foo', + icon: 'fa fa-foo', + cssClass: 'bar', + dataAttributes: { + 'data-foo': 'foo', + }, + service: { + postAction: spy, + }, + }, + }).$mount(); + + component.$el.click(); + expect(component.$el.querySelector('.fa-spinner')).toBe(null); + }); + describe('With confirm dialog', () => { it('should call the service when confimation is positive', () => { spyOn(window, 'confirm').and.returnValue(true); - eventHub.$on('postAction', (endpoint) => { - expect(endpoint).toEqual('/foo'); - }); + spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve()); component = new AsyncButtonComponent({ propsData: { @@ -49,11 +79,15 @@ describe('Pipelines Async Button', () => { title: 'Foo', icon: 'fa fa-foo', cssClass: 'bar', + service: { + postAction: spy, + }, confirmActionMessage: 'bar', }, }).$mount(); component.$el.click(); + expect(spy).toHaveBeenCalledWith('/foo'); }); }); }); diff --git a/spec/javascripts/pipelines/pipelines_actions_spec.js b/spec/javascripts/pipelines/pipelines_actions_spec.js index 72fb0a8f9ef..8a58b77f1e3 100644 --- a/spec/javascripts/pipelines/pipelines_actions_spec.js +++ b/spec/javascripts/pipelines/pipelines_actions_spec.js @@ -3,6 +3,7 @@ import pipelinesActionsComp from '~/pipelines/components/pipelines_actions.vue'; describe('Pipelines Actions dropdown', () => { let component; + let spy; let actions; let ActionsComponent; @@ -21,9 +22,14 @@ describe('Pipelines Actions dropdown', () => { }, ]; + spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve()); + component = new ActionsComponent({ propsData: { actions, + service: { + postAction: spy, + }, }, }).$mount(); }); @@ -34,6 +40,31 @@ describe('Pipelines Actions dropdown', () => { ).toEqual(actions.length); }); + it('should call the service when an action is clicked', () => { + component.$el.querySelector('.js-pipeline-dropdown-manual-actions').click(); + component.$el.querySelector('.js-pipeline-action-link').click(); + + expect(spy).toHaveBeenCalledWith(actions[0].path); + }); + + it('should hide loading if request fails', () => { + spy = jasmine.createSpy('spy').and.returnValue(Promise.reject()); + + component = new ActionsComponent({ + propsData: { + actions, + service: { + postAction: spy, + }, + }, + }).$mount(); + + component.$el.querySelector('.js-pipeline-dropdown-manual-actions').click(); + component.$el.querySelector('.js-pipeline-action-link').click(); + + expect(component.$el.querySelector('.fa-spinner')).toEqual(null); + }); + it('should render a disabled action when it\'s not playable', () => { expect( component.$el.querySelector('.dropdown-menu li:last-child button').getAttribute('disabled'), diff --git a/spec/javascripts/pipelines/pipelines_table_row_spec.js b/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js index 7ce39dca112..9475ee28a03 100644 --- a/spec/javascripts/pipelines/pipelines_table_row_spec.js +++ b/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js @@ -1,5 +1,5 @@ import Vue from 'vue'; -import tableRowComp from '~/pipelines/components/pipelines_table_row.vue'; +import tableRowComp from '~/vue_shared/components/pipelines_table_row.vue'; describe('Pipelines Table Row', () => { const jsonFixtureName = 'pipelines/pipelines.json'; diff --git a/spec/javascripts/pipelines/pipelines_table_spec.js b/spec/javascripts/vue_shared/components/pipelines_table_spec.js index 3afe89c8db4..4c35d702004 100644 --- a/spec/javascripts/pipelines/pipelines_table_spec.js +++ b/spec/javascripts/vue_shared/components/pipelines_table_spec.js @@ -1,5 +1,5 @@ import Vue from 'vue'; -import pipelinesTableComp from '~/pipelines/components/pipelines_table.vue'; +import pipelinesTableComp from '~/vue_shared/components/pipelines_table.vue'; import '~/lib/utils/datetime_utility'; describe('Pipelines Table', () => { @@ -22,6 +22,7 @@ describe('Pipelines Table', () => { component = new PipelinesTableComponent({ propsData: { pipelines: [], + service: {}, }, }).$mount(); }); @@ -47,6 +48,7 @@ describe('Pipelines Table', () => { const component = new PipelinesTableComponent({ propsData: { pipelines: [], + service: {}, }, }).$mount(); expect(component.$el.querySelectorAll('.commit.gl-responsive-table-row').length).toEqual(0); @@ -56,8 +58,10 @@ describe('Pipelines Table', () => { describe('with data', () => { it('should render rows', () => { const component = new PipelinesTableComponent({ + el: document.querySelector('.test-dom-element'), propsData: { pipelines: [pipeline], + service: {}, }, }).$mount(); |