From 98082de00c79e764ee489397de9ec818f51f0dba Mon Sep 17 00:00:00 2001 From: NavaL Date: Sun, 27 Dec 2015 15:58:24 +0100 Subject: refactoring: moved upload logic out of the attachment icon Issue #548 --- .../spec/mail_view/data/attachment_list.spec.js | 34 ++++++++++++++++++---- web-ui/test/spec/mail_view/ui/attachment.spec.js | 10 +++---- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'web-ui/test') diff --git a/web-ui/test/spec/mail_view/data/attachment_list.spec.js b/web-ui/test/spec/mail_view/data/attachment_list.spec.js index 74c1dea7..f1fa0e76 100644 --- a/web-ui/test/spec/mail_view/data/attachment_list.spec.js +++ b/web-ui/test/spec/mail_view/data/attachment_list.spec.js @@ -1,9 +1,11 @@ -describeMixin('mail_view/data/attachment_list', function () { - 'use strict'; +describeComponent('mail_view/data/attachment_list', function () { + 'use strict'; - describe('initialization', function() { - beforeEach(function(){ - this.setupComponent(); + describe('initialization', function () { + beforeEach(function () { + this.setupComponent('
' + + '' + + '
'); }); it('should add attachment to the list based on uploadedAttachment event', function () { @@ -16,6 +18,28 @@ describeMixin('mail_view/data/attachment_list', function () { expect(this.component.attr.attachments).toEqual([stubAttachment, anotherStubAttachment]); }); + it('should render attachment list view based on uploadedAttachment event', function () { + var stubAttachment = {attachment_id: 'faked', filename: 'haha.txt', filesize: 4500}; + + $(document).trigger(Pixelated.events.mail.uploadedAttachment, stubAttachment); + + var expected_li = 'haha.txt (4.39 Kb)'; + expect(this.component.select('attachmentListItem').html()).toEqual(expected_li); + }); + + xit('should start uploading attachments', function () { + var stubAttachment = {attachment_id: 'faked', filename: 'haha.txt', filesize: 4500}; + var mockAjax = spyOn($, 'ajax').and.callFake(function (params) {params.success(stubAttachment);}); + var uploadedAttachment = spyOnEvent(document, Pixelated.events.mail.uploadedAttachment); + var uploading = spyOnEvent(document, Pixelated.events.mail.uploadingAttachment); + + $(document).trigger(Pixelated.events.mail.startUploadAttachment); + + expect(mockAjax).toHaveBeenCalled(); + expect(uploadedAttachment).toHaveBeenTriggeredOnAndWith(document, stubAttachment); + expect(uploading).toHaveBeenTriggeredOn(document); + }); + }); }); diff --git a/web-ui/test/spec/mail_view/ui/attachment.spec.js b/web-ui/test/spec/mail_view/ui/attachment.spec.js index bbea2f55..d29660b9 100644 --- a/web-ui/test/spec/mail_view/ui/attachment.spec.js +++ b/web-ui/test/spec/mail_view/ui/attachment.spec.js @@ -1,4 +1,4 @@ -describeComponent('mail_view/ui/attachment', function () { +describeComponent('mail_view/ui/attachment_icon', function () { 'use strict'; describe('attachment', function () { @@ -7,14 +7,14 @@ describeComponent('mail_view/ui/attachment', function () { this.setupComponent(); }); - it('render attachment button if feature enabled', function () { + it('should render attachment button if feature enabled', function () { expect(this.$node.html()).toMatch(''); }); - xit('uploads attachment on click', function () { - var fileUploads = spyOn($, 'fileupload'); + it('should trigger starts of attachment upload process', function () { + var triggerUploadAttachment = spyOnEvent(document, Pixelated.events.mail.startUploadAttachment); this.$node.click(); - expect(fileUploads).toHaveBeenCalled(); + expect(triggerUploadAttachment).toHaveBeenTriggeredOn(document); }); }); -- cgit v1.2.3