From f80d2ab3c603fd8dd90b2ca3ed1fa92202916b00 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 15 May 2017 13:51:25 +0100 Subject: Added specs for description field [ci skip] --- .../components/fields/description_spec.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/javascripts/issue_show/components/fields/description_spec.js (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js new file mode 100644 index 00000000000..d13362ef8e6 --- /dev/null +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -0,0 +1,34 @@ +import Vue from 'vue'; +import Store from '~/issue_show/stores'; +import descriptionField from '~/issue_show/components/fields/description.vue'; + +describe('Description field component', () => { + let vm; + let store; + + beforeEach((done) => { + const Component = Vue.extend(descriptionField); + store = new Store({ + titleHtml: '', + descriptionHtml: '', + issuableRef: '', + }); + store.formState.description = 'test'; + + vm = new Component({ + propsData: { + markdownPreviewUrl: '/', + markdownDocs: '/', + store, + }, + }).$mount(); + + Vue.nextTick(done); + }); + + it('renders markdown field with description', () => { + expect( + vm.$el.querySelector('.md-area textarea').value, + ).toBe('test'); + }); +}); -- cgit v1.2.1 From 907dd68e0a18e995dc5772c9bc8117aa150edc25 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 13:01:24 +0100 Subject: Added move to project in issue inline edit form [ci skip] --- spec/javascripts/issue_show/components/app_spec.js | 45 +++++++++++++++++++++- .../components/fields/project_move_spec.js | 38 ++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 spec/javascripts/issue_show/components/fields/project_move_spec.js (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/app_spec.js b/spec/javascripts/issue_show/components/app_spec.js index 22b0a0f7046..700910c241a 100644 --- a/spec/javascripts/issue_show/components/app_spec.js +++ b/spec/javascripts/issue_show/components/app_spec.js @@ -29,12 +29,15 @@ describe('Issuable output', () => { propsData: { canUpdate: true, canDestroy: true, + canMove: true, endpoint: '/gitlab-org/gitlab-shell/issues/9/realtime_changes', issuableRef: '#1', initialTitle: '', initialDescriptionHtml: '', initialDescriptionText: '', - showForm: false, + markdownPreviewUrl: '/', + markdownDocs: '/', + projectsAutocompleteUrl: '/', }, }).$mount(); }); @@ -108,6 +111,46 @@ describe('Issuable output', () => { }); }); + it('does not redirect if issue has not moved', (done) => { + spyOn(gl.utils, 'visitUrl'); + spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { + resolve(); + })); + + vm.updateIssuable(); + + setTimeout(() => { + expect( + gl.utils.visitUrl, + ).not.toHaveBeenCalled(); + + done(); + }); + }); + + it('redirects if issue is moved', (done) => { + spyOn(gl.utils, 'visitUrl'); + spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { + resolve({ + json() { + return { + path: '/testing-issue-move', + }; + }, + }); + })); + + vm.updateIssuable(); + + setTimeout(() => { + expect( + gl.utils.visitUrl, + ).toHaveBeenCalledWith('/testing-issue-move'); + + done(); + }); + }); + it('closes form on error', (done) => { spyOn(window, 'Flash').and.callThrough(); spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve, reject) => { diff --git a/spec/javascripts/issue_show/components/fields/project_move_spec.js b/spec/javascripts/issue_show/components/fields/project_move_spec.js new file mode 100644 index 00000000000..86d35c33ff4 --- /dev/null +++ b/spec/javascripts/issue_show/components/fields/project_move_spec.js @@ -0,0 +1,38 @@ +import Vue from 'vue'; +import projectMove from '~/issue_show/components/fields/project_move.vue'; + +describe('Project move field component', () => { + let vm; + let formState; + + beforeEach((done) => { + const Component = Vue.extend(projectMove); + + formState = { + move_to_project_id: 0, + }; + + vm = new Component({ + propsData: { + formState, + projectsAutocompleteUrl: '/autocomplete', + }, + }).$mount(); + + Vue.nextTick(done); + }); + + it('mounts select2 element', () => { + expect( + vm.$el.querySelector('.select2-container'), + ).not.toBeNull(); + }); + + it('updates formState on change', () => { + $(vm.$refs['move-dropdown']).val(2).trigger('change'); + + expect( + formState.move_to_project_id, + ).toBe(2); + }); +}); -- cgit v1.2.1 From 292780272e41740102eca2630a681887d137e67e Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 14:35:02 +0100 Subject: Focus the description field in the inline form when mounted [ci skip] --- .../components/fields/description_spec.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/javascripts/issue_show/components/fields/description_spec.js (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js new file mode 100644 index 00000000000..6ea52feb84f --- /dev/null +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -0,0 +1,34 @@ +import Vue from 'vue'; +import descriptionField from '~/issue_show/components/fields/description.vue'; + +describe('Description field component', () => { + let vm; + + beforeEach((done) => { + const Component = Vue.extend(descriptionField); + + // Needs an el in the DOM to be able to text the element is focused + const el = document.createElement('div'); + + document.body.appendChild(el); + + vm = new Component({ + el, + propsData: { + formState: { + description: '', + }, + markdownDocs: '/', + markdownPreviewUrl: '/', + }, + }).$mount(); + + Vue.nextTick(done); + }); + + it('focuses field when mounted', () => { + expect( + document.activeElement, + ).toBe(vm.$refs.textarea); + }); +}); -- cgit v1.2.1 From 6c34f5a212c04a5f384999146c1957cf983dcbf3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 15:24:39 +0100 Subject: Added a test with markdown [ci skip] --- .../issue_show/components/fields/description_spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js index d13362ef8e6..05e628ca34c 100644 --- a/spec/javascripts/issue_show/components/fields/description_spec.js +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -19,7 +19,7 @@ describe('Description field component', () => { propsData: { markdownPreviewUrl: '/', markdownDocs: '/', - store, + formState: store.formState, }, }).$mount(); @@ -31,4 +31,16 @@ describe('Description field component', () => { vm.$el.querySelector('.md-area textarea').value, ).toBe('test'); }); + + it('renders markdown field with a markdown description', (done) => { + store.formState.description = '**test**'; + + Vue.nextTick(() => { + expect( + vm.$el.querySelector('.md-area textarea').value, + ).toBe('**test**'); + + done(); + }); + }); }); -- cgit v1.2.1 From cf0cc9726d26212e79d915339acb06edda726ec3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 17 May 2017 16:06:17 +0100 Subject: Stops formState from updating if the form is already open [ci skip] --- spec/javascripts/issue_show/components/app_spec.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/app_spec.js b/spec/javascripts/issue_show/components/app_spec.js index 36cd174d341..646fb455d7c 100644 --- a/spec/javascripts/issue_show/components/app_spec.js +++ b/spec/javascripts/issue_show/components/app_spec.js @@ -23,7 +23,7 @@ describe('Issuable output', () => { const IssuableDescriptionComponent = Vue.extend(issuableApp); Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest)); - spyOn(eventHub, '$emit'); + spyOn(eventHub, '$emit').and.callThrough(); vm = new IssuableDescriptionComponent({ propsData: { @@ -34,8 +34,9 @@ describe('Issuable output', () => { initialTitle: '', initialDescriptionHtml: '', initialDescriptionText: '', - showForm: false, isConfidential: false, + markdownPreviewUrl: '/', + markdownDocs: '/', }, }).$mount(); }); @@ -89,6 +90,22 @@ describe('Issuable output', () => { }); }); + it('does not update formState if form is already open', (done) => { + vm.openForm(); + + vm.state.titleText = 'testing 123'; + + vm.openForm(); + + Vue.nextTick(() => { + expect( + vm.store.formState.title, + ).not.toBe('testing 123'); + + done(); + }); + }); + describe('updateIssuable', () => { it('correctly updates issuable data', (done) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { -- cgit v1.2.1 From 9c9a24cee8d961fa33675b857f2ad980e20e0a4b Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 18 May 2017 09:12:44 +0100 Subject: Fixed typo --- spec/javascripts/issue_show/components/fields/description_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/fields/description_spec.js b/spec/javascripts/issue_show/components/fields/description_spec.js index 6ea52feb84f..cdb5c9ab862 100644 --- a/spec/javascripts/issue_show/components/fields/description_spec.js +++ b/spec/javascripts/issue_show/components/fields/description_spec.js @@ -7,7 +7,7 @@ describe('Description field component', () => { beforeEach((done) => { const Component = Vue.extend(descriptionField); - // Needs an el in the DOM to be able to text the element is focused + // Needs an el in the DOM to be able to test the element is focused const el = document.createElement('div'); document.body.appendChild(el); -- cgit v1.2.1 From c225007a7238d8ed18a1b344a2bc354672b25408 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 18 May 2017 15:50:25 +0100 Subject: Added back a removed test [ci skip] --- spec/javascripts/issue_show/components/app_spec.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/app_spec.js b/spec/javascripts/issue_show/components/app_spec.js index 8848ca4e078..e1643f56d5d 100644 --- a/spec/javascripts/issue_show/components/app_spec.js +++ b/spec/javascripts/issue_show/components/app_spec.js @@ -14,7 +14,7 @@ const issueShowInterceptor = data => (request, next) => { })); }; -fdescribe('Issuable output', () => { +describe('Issuable output', () => { document.body.innerHTML = ''; let vm; @@ -92,6 +92,22 @@ fdescribe('Issuable output', () => { }); }); + it('does not update formState if form is already open', (done) => { + vm.openForm(); + + vm.state.titleText = 'testing 123'; + + vm.openForm(); + + Vue.nextTick(() => { + expect( + vm.store.formState.title, + ).not.toBe('testing 123'); + + done(); + }); + }); + describe('updateIssuable', () => { it('reloads the page if the confidential status has changed', (done) => { spyOn(gl.utils, 'visitUrl'); -- cgit v1.2.1 From 1c463586c4b1aa39f8c55ec7de684faa13aa5d8b Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 18 May 2017 22:35:38 +0100 Subject: Removed un-used CSS Fixed random if statement [ci skip] --- spec/javascripts/issue_show/components/app_spec.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'spec/javascripts/issue_show') diff --git a/spec/javascripts/issue_show/components/app_spec.js b/spec/javascripts/issue_show/components/app_spec.js index e1643f56d5d..91ae3cfd97c 100644 --- a/spec/javascripts/issue_show/components/app_spec.js +++ b/spec/javascripts/issue_show/components/app_spec.js @@ -116,6 +116,7 @@ describe('Issuable output', () => { json() { return { confidential: true, + path: location.pathname, }; }, }); @@ -126,7 +127,7 @@ describe('Issuable output', () => { setTimeout(() => { expect( gl.utils.visitUrl, - ).toHaveBeenCalledWith(location.href); + ).toHaveBeenCalledWith(location.pathname); done(); }); @@ -154,7 +155,14 @@ describe('Issuable output', () => { it('does not redirect if issue has not moved', (done) => { spyOn(gl.utils, 'visitUrl'); spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { - resolve(); + resolve({ + json() { + return { + path: location.pathname, + confidential: vm.isConfidential, + }; + }, + }); })); vm.updateIssuable(); @@ -175,6 +183,7 @@ describe('Issuable output', () => { json() { return { path: '/testing-issue-move', + confidential: vm.isConfidential, }; }, }); -- cgit v1.2.1