diff options
author | Ola Bini <ola.bini@gmail.com> | 2014-07-31 19:29:33 -0300 |
---|---|---|
committer | Ola Bini <ola.bini@gmail.com> | 2014-07-31 19:29:33 -0300 |
commit | 04cf441c5ae18400c6b4865b0b37a71718dc9d46 (patch) | |
tree | dd0b0d049ec00389e2d4561b226c46eb1682b997 /web-ui/test/spec/dispatchers | |
parent | 639a663a4c37020003586438fdcd7ac529a00f10 (diff) |
Add web-ui based on previous code
Diffstat (limited to 'web-ui/test/spec/dispatchers')
3 files changed, 196 insertions, 0 deletions
diff --git a/web-ui/test/spec/dispatchers/left_pane_dispatcher.spec.js b/web-ui/test/spec/dispatchers/left_pane_dispatcher.spec.js new file mode 100644 index 00000000..fb5b169a --- /dev/null +++ b/web-ui/test/spec/dispatchers/left_pane_dispatcher.spec.js @@ -0,0 +1,79 @@ +/*global Smail */ + +describeComponent('dispatchers/left_pane_dispatcher', function () { + 'use strict'; + + describe('initialize', function () { + it('asks for tags', function () { + var tagWantEvent = spyOnEvent(document, Smail.events.tags.want); + + setupComponent(); + + expect(tagWantEvent).toHaveBeenTriggeredOn(document); + expect(tagWantEvent.mostRecentCall.data.caller[0]).toEqual(this.$node[0]); + }); + }); + + describe('after initialization', function () { + beforeEach(function () { + setupComponent(); + }); + + it('pushes the url state when a tag is selected but not for the first tag', function () { + var pushStateEvent = spyOnEvent(document, Smail.events.router.pushState); + + $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts'}); + $(document).trigger(Smail.events.ui.tag.selected, { tag: 'inbox'}); + + expect(pushStateEvent).toHaveBeenTriggeredOn(document, { tag: 'inbox'}); + }); + + it('fetches mails by tag when a tag is selected', function () { + var fetchByTagEvent = spyOnEvent(document, Smail.events.ui.mails.fetchByTag); + + $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts'}); + + expect(fetchByTagEvent).toHaveBeenTriggeredOn(document, { tag: 'Drafts'}); + }); + + it('doesnt fetch mails by tag when skipMailListRefresh is sent on tag.selected', function () { + var fetchByTagEvent = spyOnEvent(document, Smail.events.ui.mails.fetchByTag); + + $(document).trigger(Smail.events.ui.tag.selected, { tag: 'Drafts', skipMailListRefresh: true}); + + expect(fetchByTagEvent).not.toHaveBeenTriggeredOn(document, { tag: 'Drafts'}); + }); + + it('asks for more tags when refreshTagList is fired', function () { + var tagWantEvent = spyOnEvent(document, Smail.events.tags.want); + + $(document).trigger(Smail.events.dispatchers.tags.refreshTagList); + + expect(tagWantEvent).toHaveBeenTriggeredOn(document); + }); + + it('fires tagLoad when the tags are received', function () { + var tagListLoadEvent = spyOnEvent(document, Smail.events.ui.tagList.load); + + this.$node.trigger(Smail.events.tags.received, { tags: ['tags']}); + + expect(tagListLoadEvent).toHaveBeenTriggeredOn(document, { tags: ['tags']}); + }); + + it('on tags loaded selects the inbox tag if no data is provided', function () { + var selectTagEvent = spyOnEvent(document, Smail.events.ui.tag.select); + + $(document).trigger(Smail.events.ui.tags.loaded); + + expect(selectTagEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'inbox' }); + }); + + it('on tags loaded selects the a different tag if tag is provided', function () { + var selectTagEvent = spyOnEvent(document, Smail.events.ui.tag.select); + + $(document).trigger(Smail.events.ui.tags.loaded, { tag: 'Drafts' }); + + expect(selectTagEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'Drafts' }); + }); + }); +}); diff --git a/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js b/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js new file mode 100644 index 00000000..2dd0de2e --- /dev/null +++ b/web-ui/test/spec/dispatchers/middle_pane_dispatchers.spec.js @@ -0,0 +1,27 @@ +/*global Smail */ + +describeComponent('dispatchers/middle_pane_dispatcher', function () { + 'use strict'; + + beforeEach(function() { + setupComponent('<div><div id="middle-pane" style="height: 200px; overflow-y: scroll;"><div style="height: 400px"></div></div></div>'); + }); + + it ('listens to refresh mail list event', function() { + var mailsListRefreshEventSpy = spyOnEvent(document, Smail.events.ui.mails.fetchByTag); + this.component.trigger(document, Smail.events.dispatchers.middlePane.refreshMailList); + expect(mailsListRefreshEventSpy).toHaveBeenTriggeredOn(document); + }); + + it ('listens to unselect event', function() { + var mailListUnselectEvent = spyOnEvent(document, Smail.events.ui.mails.cleanSelected); + this.component.trigger(document, Smail.events.dispatchers.middlePane.cleanSelected); + expect(mailListUnselectEvent).toHaveBeenTriggeredOn(document); + }); + + it('resets the scrollTop value when asked to', function() { + this.component.select('middlePane').scrollTop(200); + this.component.trigger(document, Smail.events.dispatchers.middlePane.resetScroll); + expect(this.component.select('middlePane').scrollTop()).toEqual(0); + }); +}); diff --git a/web-ui/test/spec/dispatchers/right_pane_dispatcher.spec.js b/web-ui/test/spec/dispatchers/right_pane_dispatcher.spec.js new file mode 100644 index 00000000..5fc7ecd7 --- /dev/null +++ b/web-ui/test/spec/dispatchers/right_pane_dispatcher.spec.js @@ -0,0 +1,90 @@ +/*global Smail */ + +describeComponent('dispatchers/right_pane_dispatcher', function () { + 'use strict'; + + describe('after initialization', function () { + beforeEach(function () { + setupComponent(); + }); + + it('listens to open compose box event and creates a compose box', function () { + var composeBox = require('mail_view/ui/compose_box'); + spyOn(composeBox, 'attachTo'); + + this.component.trigger(document, Smail.events.dispatchers.rightPane.openComposeBox); + + expect(composeBox.attachTo).toHaveBeenCalled(); + }); + + describe('no message selected', function () { + var noMessageSelectedPane; + beforeEach(function () { + noMessageSelectedPane = require('mail_view/ui/no_message_selected_pane'); + spyOn(noMessageSelectedPane, 'attachTo'); + }); + + it('listen to open no message selected event and creates a no-message-selected-pane', function () { + this.component.trigger(document, Smail.events.dispatchers.rightPane.openNoMessageSelected); + + expect(noMessageSelectedPane.attachTo).toHaveBeenCalled(); + }); + + it('sends an dispatchers.middlePane.unselect event', function () { + var unselectEvent = spyOnEvent(document, Smail.events.dispatchers.middlePane.cleanSelected); + this.component.trigger(document, Smail.events.dispatchers.rightPane.openNoMessageSelected); + + expect(unselectEvent).toHaveBeenTriggeredOn(document); + }); + + it('pushes the current state with the current tag', function () { + var pushStateEvent = spyOnEvent(document, Smail.events.router.pushState); + + this.component.attr.currentTag = 'sometag'; + this.component.trigger(document, Smail.events.dispatchers.rightPane.openNoMessageSelected); + + expect(pushStateEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({tag: this.component.attr.currentTag })); + }); + + it('pushes the current state stating that it meant to close the right pane', function () { + var pushStateEvent = spyOnEvent(document, Smail.events.router.pushState); + + this.component.attr.currentTag = 'sometag'; + this.component.trigger(document, Smail.events.dispatchers.rightPane.openNoMessageSelected); + + expect(pushStateEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({ isDisplayNoMessageSelected: true })); + }); + + + }); + + it('listens to open a draft and creates it', function () { + var draftBox = require('mail_view/ui/draft_box'); + spyOn(draftBox, 'attachTo'); + + this.component.trigger(document, Smail.events.dispatchers.rightPane.openDraft, { ident: '1' }); + + expect(draftBox.attachTo).toHaveBeenCalled(); + }); + }); + + describe('on initialization', function () { + var noMessageSelectedPane; + + beforeEach(function () { + noMessageSelectedPane = require('mail_view/ui/no_message_selected_pane'); + spyOn(noMessageSelectedPane, 'attachTo'); + }); + + it('opens the no message selected pane but doesnt push the state', function () { + var pushStateEvent = spyOnEvent(document, Smail.events.router.pushState); + + setupComponent(); + + expect(noMessageSelectedPane.attachTo).toHaveBeenCalled(); + expect(pushStateEvent).not.toHaveBeenTriggeredOn(document); + + }); + }); + +}); |