From 02ab65d49fc94be7c91e511899762236c122977d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 14 Jan 2020 09:08:19 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/frontend/ide/stores/actions/file_spec.js | 146 +++++++++++---------- spec/javascripts/ide/stores/actions_spec.js | 84 +++--------- spec/lib/gitlab/email/attachment_uploader_spec.rb | 2 +- .../email/handler/create_note_handler_spec.rb | 13 +- 4 files changed, 105 insertions(+), 140 deletions(-) (limited to 'spec') diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index 2d72ae770ab..e7b34aa3e7a 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -619,107 +619,113 @@ describe('IDE store file actions', () => { }); }); - describe('discardFileChanges', () => { + describe('with changed file', () => { let tmpFile; beforeEach(() => { - jest.spyOn(eventHub, '$on').mockImplementation(() => {}); - jest.spyOn(eventHub, '$emit').mockImplementation(() => {}); - tmpFile = file('tempFile'); tmpFile.content = 'testing'; tmpFile.raw = ORIGINAL_CONTENT; store.state.changedFiles.push(tmpFile); store.state.entries[tmpFile.path] = tmpFile; - - jest.spyOn(store, 'dispatch'); }); - it('resets file content', done => { - store - .dispatch('discardFileChanges', tmpFile.path) - .then(() => { + describe('restoreOriginalFile', () => { + it('resets file content', () => + store.dispatch('restoreOriginalFile', tmpFile.path).then(() => { expect(tmpFile.content).toBe(ORIGINAL_CONTENT); + })); - done(); - }) - .catch(done.fail); - }); + it('closes temp file and deletes it', () => { + tmpFile.tempFile = true; + tmpFile.opened = true; + tmpFile.parentPath = 'parentFile'; + store.state.entries.parentFile = file('parentFile'); - it('removes file from changedFiles array', done => { - store - .dispatch('discardFileChanges', tmpFile.path) - .then(() => { - expect(store.state.changedFiles.length).toBe(0); + actions.restoreOriginalFile(store, tmpFile.path); - done(); - }) - .catch(done.fail); - }); + expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile); + expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path); + }); - it('closes temp file and deletes it', () => { - tmpFile.tempFile = true; - tmpFile.opened = true; - tmpFile.parentPath = 'parentFile'; - store.state.entries.parentFile = file('parentFile'); + describe('with renamed file', () => { + beforeEach(() => { + Object.assign(tmpFile, { + prevPath: 'parentPath/old_name', + prevName: 'old_name', + prevParentPath: 'parentPath', + }); - actions.discardFileChanges(store, tmpFile.path); + store.state.entries.parentPath = file('parentPath'); - expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile); - expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path); - }); + actions.restoreOriginalFile(store, tmpFile.path); + }); - describe('with renamed file', () => { - beforeEach(() => { - Object.assign(tmpFile, { - prevPath: 'parentPath/old_name', - prevName: 'old_name', - prevParentPath: 'parentPath', + it('renames the file to its original name and closes it if it was open', () => { + expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile); + expect(store.dispatch).toHaveBeenCalledWith('renameEntry', { + path: 'tempFile', + name: 'old_name', + parentPath: 'parentPath', + }); }); - store.state.entries.parentPath = file('parentPath'); + it('resets file content', () => { + expect(tmpFile.content).toBe(ORIGINAL_CONTENT); + }); + }); + }); - actions.discardFileChanges(store, tmpFile.path); + describe('discardFileChanges', () => { + beforeEach(() => { + jest.spyOn(eventHub, '$on').mockImplementation(() => {}); + jest.spyOn(eventHub, '$emit').mockImplementation(() => {}); }); - it('renames the file to its original name and closes it if it was open', () => { - expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile); - expect(store.dispatch).toHaveBeenCalledWith('renameEntry', { - path: 'tempFile', - name: 'old_name', - parentPath: 'parentPath', + describe('with regular file', () => { + beforeEach(() => { + actions.discardFileChanges(store, tmpFile.path); }); - }); - it('resets file content', () => { - expect(tmpFile.content).toBe(ORIGINAL_CONTENT); - }); - }); + it('restores original file', () => { + expect(store.dispatch).toHaveBeenCalledWith('restoreOriginalFile', tmpFile.path); + }); - it('pushes route for active file', done => { - tmpFile.active = true; - store.state.openFiles.push(tmpFile); + it('removes file from changedFiles array', () => { + expect(store.state.changedFiles.length).toBe(0); + }); - store - .dispatch('discardFileChanges', tmpFile.path) - .then(() => { - expect(router.push).toHaveBeenCalledWith(`/project${tmpFile.url}`); + it('does not push a new route', () => { + expect(router.push).not.toHaveBeenCalled(); + }); - done(); - }) - .catch(done.fail); - }); + it('emits eventHub event to dispose cached model', () => { + actions.discardFileChanges(store, tmpFile.path); + + expect(eventHub.$emit).toHaveBeenCalledWith( + `editor.update.model.new.content.${tmpFile.key}`, + ORIGINAL_CONTENT, + ); + expect(eventHub.$emit).toHaveBeenCalledWith( + `editor.update.model.dispose.unstaged-${tmpFile.key}`, + ORIGINAL_CONTENT, + ); + }); + }); - it('emits eventHub event to dispose cached model', done => { - store - .dispatch('discardFileChanges', tmpFile.path) - .then(() => { - expect(eventHub.$emit).toHaveBeenCalled(); + describe('with active file', () => { + beforeEach(() => { + tmpFile.active = true; + store.state.openFiles.push(tmpFile); - done(); - }) - .catch(done.fail); + actions.discardFileChanges(store, tmpFile.path); + }); + + it('pushes route for active file', () => { + expect(router.push).toHaveBeenCalledWith(`/project${tmpFile.url}`); + }); + }); }); }); diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js index a9fc3bf65a6..8abd9c38514 100644 --- a/spec/javascripts/ide/stores/actions_spec.js +++ b/spec/javascripts/ide/stores/actions_spec.js @@ -61,24 +61,25 @@ describe('Multi-file store actions', () => { }); describe('discardAllChanges', () => { - let f; + const paths = ['to_discard', 'another_one_to_discard']; + beforeEach(() => { - f = file('discardAll'); - f.changed = true; + paths.forEach(path => { + const f = file(path); + f.changed = true; - store.state.openFiles.push(f); - store.state.changedFiles.push(f); - store.state.entries[f.path] = f; + store.state.openFiles.push(f); + store.state.changedFiles.push(f); + store.state.entries[f.path] = f; + }); }); - it('discards changes in file', done => { - store - .dispatch('discardAllChanges') - .then(() => { - expect(store.state.openFiles.changed).toBeFalsy(); - }) - .then(done) - .catch(done.fail); + it('discards all changes in file', () => { + const expectedCalls = paths.map(path => ['restoreOriginalFile', path]); + + discardAllChanges(store); + + expect(store.dispatch.calls.allArgs()).toEqual(jasmine.arrayContaining(expectedCalls)); }); it('removes all files from changedFiles state', done => { @@ -86,64 +87,11 @@ describe('Multi-file store actions', () => { .dispatch('discardAllChanges') .then(() => { expect(store.state.changedFiles.length).toBe(0); - expect(store.state.openFiles.length).toBe(1); + expect(store.state.openFiles.length).toBe(2); }) .then(done) .catch(done.fail); }); - - it('closes the temp file and deletes it if it was open', done => { - f.tempFile = true; - - testAction( - discardAllChanges, - undefined, - store.state, - [{ type: types.REMOVE_ALL_CHANGES_FILES }], - [ - { type: 'closeFile', payload: jasmine.objectContaining({ path: 'discardAll' }) }, - { type: 'deleteEntry', payload: 'discardAll' }, - ], - done, - ); - }); - - it('renames the file to its original name and closes it if it was open', done => { - Object.assign(f, { - prevPath: 'parent/path/old_name', - prevName: 'old_name', - prevParentPath: 'parent/path', - }); - - testAction( - discardAllChanges, - undefined, - store.state, - [{ type: types.REMOVE_ALL_CHANGES_FILES }], - [ - { type: 'closeFile', payload: jasmine.objectContaining({ path: 'discardAll' }) }, - { - type: 'renameEntry', - payload: { path: 'discardAll', name: 'old_name', parentPath: 'parent/path' }, - }, - ], - done, - ); - }); - - it('discards file changes on all other files', done => { - testAction( - discardAllChanges, - undefined, - store.state, - [ - { type: types.DISCARD_FILE_CHANGES, payload: 'discardAll' }, - { type: types.REMOVE_ALL_CHANGES_FILES }, - ], - [], - done, - ); - }); }); describe('closeAllFiles', () => { diff --git a/spec/lib/gitlab/email/attachment_uploader_spec.rb b/spec/lib/gitlab/email/attachment_uploader_spec.rb index d66a746284d..c69b2f1eabc 100644 --- a/spec/lib/gitlab/email/attachment_uploader_spec.rb +++ b/spec/lib/gitlab/email/attachment_uploader_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::Email::AttachmentUploader do let(:message) { Mail::Message.new(message_raw) } it "uploads all attachments and returns their links" do - links = described_class.new(message).execute(project) + links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader) link = links.first expect(link).not_to be_nil diff --git a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb index 50e473c459e..909a7618df4 100644 --- a/spec/lib/gitlab/email/handler/create_note_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/create_note_handler_spec.rb @@ -181,10 +181,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do it_behaves_like 'a reply to existing comment' it "adds all attachments" do + expect_next_instance_of(Gitlab::Email::AttachmentUploader) do |uploader| + expect(uploader).to receive(:execute).with(upload_parent: project, uploader_class: FileUploader).and_return( + [ + { + url: "uploads/image.png", + alt: "image", + markdown: markdown + } + ] + ) + end + receiver.execute note = noteable.notes.last - expect(note.note).to include(markdown) end -- cgit v1.2.1