From b0720edaa0d51ee9e807495fa536d890d332c50d Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Nunes Date: Tue, 6 Jan 2015 16:19:36 -0200 Subject: Update tests to refactored events behaviour --- web-ui/test/spec/tags/ui/tag.spec.js | 24 +++++++++++++++++- web-ui/test/spec/tags/ui/tag_list.spec.js | 35 +++++++-------------------- web-ui/test/spec/tags/ui/tag_shortcut.spec.js | 4 +-- 3 files changed, 34 insertions(+), 29 deletions(-) (limited to 'web-ui/test/spec/tags') diff --git a/web-ui/test/spec/tags/ui/tag.spec.js b/web-ui/test/spec/tags/ui/tag.spec.js index 3bc0c7fc..36fc83f2 100644 --- a/web-ui/test/spec/tags/ui/tag.spec.js +++ b/web-ui/test/spec/tags/ui/tag.spec.js @@ -23,7 +23,6 @@ describeComponent('tags/ui/tag', function () { this.component.$node.click(); - expect(this.component.attr.selected).toBeTruthy(); expect(this.$node.attr('class')).toMatch('selected'); expect(tagSelectEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'inbox' }); }); @@ -94,6 +93,18 @@ describeComponent('tags/ui/tag', function () { $(document).trigger(Pixelated.events.mail.read, { tags: ['inbox']}); expect(this.$node.html()).not.toMatch('"unread-count"'); }); + + it('should not be selected when a search is performed', function() { + this.component.trigger(document, Pixelated.events.search.perform); + + expect(this.component.$node).not.toHaveClass('selected'); + }); + + it('should not be selected when the search is cleared', function() { + this.component.trigger(document, Pixelated.events.search.empty); + + expect(this.component.$node).not.toHaveClass('selected'); + }); }); describe('drafts tag', function () { @@ -149,6 +160,17 @@ describeComponent('tags/ui/tag', function () { expect(this.$node.attr('class')).not.toMatch('searching'); }); + it('should be selected when a search is performed', function() { + this.component.trigger(document, Pixelated.events.search.perform); + + expect(this.component.$node).toHaveClass('selected'); + }); + + it('should be selected when the search is cleared', function() { + this.component.trigger(document, Pixelated.events.search.empty); + + expect(this.component.$node).toHaveClass('selected'); + }); }); _.each(['sent', 'trash'], function (tag_name) { diff --git a/web-ui/test/spec/tags/ui/tag_list.spec.js b/web-ui/test/spec/tags/ui/tag_list.spec.js index 72667b40..78bd84d9 100644 --- a/web-ui/test/spec/tags/ui/tag_list.spec.js +++ b/web-ui/test/spec/tags/ui/tag_list.spec.js @@ -27,7 +27,7 @@ describeComponent('tags/ui/tag_list', function () { this.component.attr.default = false; var tagList = [tag('tag1', 1), tag('tag2', 2), tag('tag3', 3)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); var items = _.map(this.$node.find('li'), function (el) { return $(el).attr('id'); @@ -39,7 +39,7 @@ describeComponent('tags/ui/tag_list', function () { it('should render the default tags when tagsList:load is received and default attribute is true', function () { var tagList = [tag('tag1', 1, false), tag('tag2', 2, true), tag('tag3', 3, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); var items = _.map(this.component.select('defaultTagList').find('li'), function (el) { return $(el).attr('id'); @@ -51,7 +51,7 @@ describeComponent('tags/ui/tag_list', function () { it('should render the custom tags when tagsList:load is received and default attribute is false', function () { var tagList = [tag('tag1', 1, false), tag('tag2', 2, true), tag('tag3', 3, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); var items = _.map(this.component.select('customTagList').find('li'), function (el) { return $(el).attr('id'); @@ -60,35 +60,18 @@ describeComponent('tags/ui/tag_list', function () { expect(items).toEqual(['tag-1']); }); - it('should trigger event to tell that tags were loaded sending the current tag', function () { - this.component.attr.currentTag = 'Drafts'; - var tagsLoadedEvent = spyOnEvent(document, Pixelated.events.ui.tags.loaded); - - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: [] }); - - expect(tagsLoadedEvent).toHaveBeenTriggeredOnAndWith(document, { tag: 'Drafts'}); - }); - - it('should send tag as undefined when tags are loaded and no tag was selected yet', function () { - var tagsLoadedEvent = spyOnEvent(document, Pixelated.events.ui.tags.loaded); - - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: [] }); - - expect(tagsLoadedEvent).toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({ tag: undefined })); - }); - it('should save the current tag when a tag is selected', function () { - $(document).trigger(Pixelated.events.ui.tag.selected, { tag: 'amazing'}); + $(document).trigger(Pixelated.events.ui.tag.select, { tag: 'amazing'}); expect(this.component.attr.currentTag).toEqual('amazing'); }); it('resets the tag lists when loading tags', function () { var tagList = [tag('tag1', 1, false), tag('tag2', 2, true), tag('tag3', 3, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); tagList = [tag('tag1', 1, false), tag('tag2', 2, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); var customTags = _.map(this.component.select('customTagList').find('li'), function (el) { return $(el).attr('id'); @@ -103,10 +86,10 @@ describeComponent('tags/ui/tag_list', function () { it('resets the tag shortcuts when loading tags', function () { var tagList = [tag('inbox', 1, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); tagList = [tag('sent', 1, true)]; - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: tagList}); + $(document).trigger(Pixelated.events.tags.received, {tags: tagList}); var shortcuts = _.map($('#tags-shortcuts').find('li'), function (el) { return $(el).text().trim(); @@ -120,7 +103,7 @@ describeComponent('tags/ui/tag_list', function () { var tagsTeardownDefault = spyOnEvent(this.component.select('defaultTagList'), Pixelated.events.tags.teardown); var tagsShortcutsTeardown = spyOnEvent(document, Pixelated.events.tags.shortcuts.teardown); - $(document).trigger(Pixelated.events.ui.tagList.load, {tags: []}); + $(document).trigger(Pixelated.events.tags.received, {tags: []}); expect(tagsTeardownCustom).toHaveBeenTriggeredOn(this.component.select('customTagList')); expect(tagsTeardownDefault).toHaveBeenTriggeredOn(this.component.select('defaultTagList')); diff --git a/web-ui/test/spec/tags/ui/tag_shortcut.spec.js b/web-ui/test/spec/tags/ui/tag_shortcut.spec.js index 7f015319..d1c7939a 100644 --- a/web-ui/test/spec/tags/ui/tag_shortcut.spec.js +++ b/web-ui/test/spec/tags/ui/tag_shortcut.spec.js @@ -12,7 +12,7 @@ describeComponent('tags/ui/tag_shortcut', function () { component = jasmine.createSpyObj('tagComponent', ['triggerSelect']); parent = $('