diff options
Diffstat (limited to 'web-ui/test/spec/page/router.spec.js')
-rw-r--r-- | web-ui/test/spec/page/router.spec.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/web-ui/test/spec/page/router.spec.js b/web-ui/test/spec/page/router.spec.js new file mode 100644 index 00000000..0b5b6b32 --- /dev/null +++ b/web-ui/test/spec/page/router.spec.js @@ -0,0 +1,70 @@ +/*global Smail */ +/*global jasmine */ +describeComponent('page/router', function () { + 'use strict'; + + var fakeHistory; + + describe('on router:pushState coming from a tag selection', function () { + beforeEach(function () { + fakeHistory = jasmine.createSpyObj('history', ['pushState']); + setupComponent({history: fakeHistory}); + }); + + it('pushes the state with the tag and the url', function () { + $(document).trigger(Smail.events.router.pushState, { tag: 'inbox'}); + + expect(fakeHistory.pushState).toHaveBeenCalledWith(jasmine.objectContaining({ tag: 'inbox' }), '', '/#/inbox'); + }); + + it('pushes the state with mailIdent', function () { + $(document).trigger(Smail.events.router.pushState, { tag: 'inbox', mailIdent: 1}); + + expect(fakeHistory.pushState).toHaveBeenCalledWith(jasmine.objectContaining({ tag: 'inbox', mailIdent: 1 }), '', '/#/inbox/mail/1'); + }); + + it('pushes the state with mailIdent even if mail ident is 0 (that happens for drafts)', function () { + $(document).trigger(Smail.events.router.pushState, { tag: 'inbox', mailIdent: 0}); + + expect(fakeHistory.pushState).toHaveBeenCalledWith(jasmine.objectContaining({ tag: 'inbox', mailIdent: 0 }), '', '/#/inbox/mail/0'); + }); + + it('pushes the state with the displayNoMessage boolean forwarded from the event', function () { + $(document).trigger(Smail.events.router.pushState, { tag: 'inbox', mailIdent: 0}); + + expect(fakeHistory.pushState).toHaveBeenCalledWith(jasmine.objectContaining({ isDisplayNoMessageSelected: false}), '', '/#/inbox/mail/0'); + + $(document).trigger(Smail.events.router.pushState, { tag: 'inbox', mailIdent: 0, isDisplayNoMessageSelected: true}); + + expect(fakeHistory.pushState).toHaveBeenCalledWith(jasmine.objectContaining({ isDisplayNoMessageSelected: true}), '', '/#/inbox/mail/0'); + }); + + it('when popping a state with no tag should select tag from url', function () { + var urlParams = require("page/router/url_params"); + spyOn(urlParams, 'getTag').andReturn('tag'); + + var selectTagEvent = spyOnEvent(document, Smail.events.ui.tag.select); + + this.component.smailPopState({ state: {tag: undefined} }); + + expect(selectTagEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({ tag: "tag"})) + }); + + it('when popping a state triggers the displayNoMessage pane if required', function () { + var urlParams = require("page/router/url_params"); + spyOn(urlParams, 'getTag').andReturn('tag'); + + var displayNoMessageEvent = spyOnEvent(document, Smail.events.dispatchers.rightPane.openNoMessageSelectedWithoutPushState); + + this.component.smailPopState({ state: {tag: undefined, isDisplayNoMessageSelected: false} }); + + expect(displayNoMessageEvent).not.toHaveBeenTriggeredOn(document) + + this.component.smailPopState({ state: {tag: undefined, isDisplayNoMessageSelected: true} }); + + expect(displayNoMessageEvent).toHaveBeenTriggeredOn(document) + }); + + }); + +}); |