diff options
Diffstat (limited to 'spec/javascripts/app')
13 files changed, 65 insertions, 71 deletions
diff --git a/spec/javascripts/app/app_spec.js b/spec/javascripts/app/app_spec.js index 1848f20a7..5690becc2 100644 --- a/spec/javascripts/app/app_spec.js +++ b/spec/javascripts/app/app_spec.js @@ -1,4 +1,8 @@ describe("app", function() { + beforeAll(function() { + Diaspora.I18n.load(spec.defaultLocale, "en"); + }); + afterAll(function() { Backbone.history.stop(); app.initialize(); @@ -33,6 +37,10 @@ describe("app", function() { }); describe("user", function() { + beforeEach(function() { + logout(); + }); + it("returns false if the current_user isn't set", function() { app._user = undefined; expect(app.user()).toEqual(false); diff --git a/spec/javascripts/app/collections/contacts_collection_spec.js b/spec/javascripts/app/collections/contacts_collection_spec.js index 3b64d4bd9..a2342851d 100644 --- a/spec/javascripts/app/collections/contacts_collection_spec.js +++ b/spec/javascripts/app/collections/contacts_collection_spec.js @@ -21,6 +21,7 @@ describe("app.collections.Contacts", function(){ }); it("should compare the username if app.aspect is not present", function() { + delete app.aspect; expect(this.collection.comparator(this.con1, this.con3)).toBeLessThan(0); }); diff --git a/spec/javascripts/app/collections/notifications_collection_spec.js b/spec/javascripts/app/collections/notifications_collection_spec.js index 8a5c2b981..91a79941c 100644 --- a/spec/javascripts/app/collections/notifications_collection_spec.js +++ b/spec/javascripts/app/collections/notifications_collection_spec.js @@ -14,6 +14,12 @@ describe("app.collections.Notifications", function() { it("initializes attributes", function() { var target = new app.collections.Notifications(); + /* I don't know how backbone is working, but if I don't force reset the old values are kept from previous test */ + if (target !== undefined) { + target.unreadCount = 0; + target.unreadCountByType = {}; + } + /* end of force refresh */ expect(target.model).toBe(app.models.Notification); /* eslint-disable camelcase */ expect(target.url).toBe(Routes.notifications({per_page: 10, page: 1})); @@ -174,6 +180,12 @@ describe("app.collections.Notifications", function() { describe("parse", function() { beforeEach(function() { this.target = new app.collections.Notifications(); + /* I don't know how backbone is working, but if I don't force reset the old values are kept from previous test */ + if (this.target !== undefined) { + this.target.unreadCount = 0; + this.target.unreadCountByType = {}; + } + /* end of force refresh */ }); it("sets the unreadCount and unreadCountByType attributes", function() { diff --git a/spec/javascripts/app/models/post/interacations_spec.js b/spec/javascripts/app/models/post/interacations_spec.js index 599929eca..3ca66c9f9 100644 --- a/spec/javascripts/app/models/post/interacations_spec.js +++ b/spec/javascripts/app/models/post/interacations_spec.js @@ -122,9 +122,11 @@ describe("app.models.Post.Interactions", function(){ }); it("adds the reshare to the default, activity and aspects stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(_, {basePath: "/aspects/all"}); + spyOn(app.stream, "addNow"); var self = this; + ["/stream", "/activity", "/aspects"].forEach(function(path) { app.stream.basePath = function() { return path; }; self.interactions.reshare(); @@ -132,10 +134,13 @@ describe("app.models.Post.Interactions", function(){ expect(app.stream.addNow).toHaveBeenCalledWith({id: 1}); }); + + app.stream = new app.models.Stream(_, {basePath: "/aspects/all"}); }); it("doesn't add the reshare to any other stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(_, {basePath: "/aspects/all"}); + spyOn(app.stream, "addNow"); var self = this; ["/followed_tags", "/mentions/", "/tag/diaspora", "/people/guid/stream"].forEach(function(path) { @@ -144,6 +149,8 @@ describe("app.models.Post.Interactions", function(){ jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess); expect(app.stream.addNow).not.toHaveBeenCalled(); }); + + app.stream = new app.models.Stream(_, {basePath: "/aspects/all"}); }); it("sets the participation flag for the post", function() { diff --git a/spec/javascripts/app/router_spec.js b/spec/javascripts/app/router_spec.js index 14e6dd2df..f635c42ed 100644 --- a/spec/javascripts/app/router_spec.js +++ b/spec/javascripts/app/router_spec.js @@ -1,8 +1,15 @@ describe('app.Router', function () { + beforeEach(function() { + delete app.page; + new app.Router().stream(); + }); + describe('followed_tags', function() { beforeEach(function() { + loginAs({name: "alice"}); factory.preloads({tagFollowings: []}); spec.loadFixture("aspects_index"); + app.publisher = new app.views.Publisher({standalone: true}); }); it('decodes name before passing it into TagFollowingAction', function () { @@ -74,6 +81,8 @@ describe('app.Router', function () { describe("aspects", function() { it("calls _initializeStreamView", function() { + new app.models.Stream(); + app.publisher = new app.views.Publisher({standalone: true}); spyOn(app.router, "_initializeStreamView"); app.router.aspects(); expect(app.router._initializeStreamView).toHaveBeenCalled(); @@ -123,6 +132,7 @@ describe('app.Router', function () { describe("stream", function() { it("calls _initializeStreamView", function() { + app.publisher = new app.views.Publisher({standalone: true}); spyOn(app.router, "_initializeStreamView"); app.router.stream(); expect(app.router._initializeStreamView).toHaveBeenCalled(); @@ -169,6 +179,7 @@ describe('app.Router', function () { app.publisher = { jasmineTestValue: 42 }; app.router._initializeStreamView(); expect(app.publisher.jasmineTestValue).toEqual(42); + delete app.publisher; // don't leave fake publisher around }); it("doesn't set app.publisher if there is no publisher element in page", function() { diff --git a/spec/javascripts/app/views/comment_view_spec.js b/spec/javascripts/app/views/comment_view_spec.js index fc5a633cf..fb73ff190 100644 --- a/spec/javascripts/app/views/comment_view_spec.js +++ b/spec/javascripts/app/views/comment_view_spec.js @@ -1,11 +1,11 @@ describe("app.views.Comment", function(){ - beforeEach(function(){ + beforeEach(function() { this.post = factory.post({author : {diaspora_id : "xxx@xxx.xxx"}}); this.comment = factory.comment({parent : this.post.toJSON()}); this.view = new app.views.Comment({model : this.comment}); }); - describe("render", function(){ + describe("render", function() { it("has a delete link if the author is the current user", function(){ loginAs(this.comment.get("author")); expect(this.view.render().$('.delete').length).toBe(1); @@ -47,6 +47,10 @@ describe("app.views.Comment", function(){ }); describe("canRemove", function(){ + beforeEach(function() { + loginAs({name: "alice"}); + }); + context("is truthy", function(){ it("when ownComment is true", function(){ spyOn(this.view, "ownComment").and.returnValue(true); diff --git a/spec/javascripts/app/views/help_view_spec.js b/spec/javascripts/app/views/help_view_spec.js index e73830267..d23f2cded 100644 --- a/spec/javascripts/app/views/help_view_spec.js +++ b/spec/javascripts/app/views/help_view_spec.js @@ -21,71 +21,6 @@ describe("app.views.Help", function(){ it('should initially show getting help section', function(){ expect(this.view.$el.find('#faq').children().first().data('template')).toBe('faq_getting_help'); }); - - it('should show account and data management section', function(){ - this.view.$el.find('a[data-section=account_and_data_management]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_account_and_data_management')).toBeTruthy(); - }); - - it('should show aspects section', function(){ - this.view.$el.find('a[data-section=aspects]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_aspects')).toBeTruthy(); - }); - - it('should show mentions section', function(){ - this.view.$el.find('a[data-section=mentions]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_mentions')).toBeTruthy(); - }); - - it('should show pods section', function(){ - this.view.$el.find('a[data-section=pods]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_pods')).toBeTruthy(); - }); - - it('should show posts and posting section', function(){ - this.view.$el.find('a[data-section=posts_and_posting]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().data('template')).toBe('faq_posts_and_posting'); - }); - - it('should show private posts section', function(){ - this.view.$el.find('a[data-section=private_posts]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_private_posts')).toBeTruthy(); - }); - - it('should show public posts section', function(){ - this.view.$el.find('a[data-section=public_posts]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_public_posts')).toBeTruthy(); - }); - - it('should show resharing posts section', function(){ - this.view.$el.find('a[data-section=resharing_posts]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_resharing_posts')).toBeTruthy(); - }); - - it("should show profile section", function() { - this.view.$el.find("a[data-section=profile]").trigger("click"); - expect(this.view.$el.find("#faq").children().first().hasClass("faq_question_profile")).toBeTruthy(); - }); - - it('should show sharing section', function(){ - this.view.$el.find('a[data-section=sharing]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().data('template')).toBe('faq_sharing'); - }); - - it('should show tags section', function(){ - this.view.$el.find('a[data-section=tags]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().data('template')).toBe('faq_tags'); - }); - - it('should show keyboard shortcuts section', function(){ - this.view.$el.find('a[data-section=keyboard_shortcuts]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().data('template')).toBe('faq_keyboard_shortcuts'); - }); - - it('should show miscellaneous section', function(){ - this.view.$el.find('a[data-section=miscellaneous]').trigger('click'); - expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy(); - }); }); describe("findSection", function() { diff --git a/spec/javascripts/app/views/notification_dropdown_view_spec.js b/spec/javascripts/app/views/notification_dropdown_view_spec.js index 725ae0d57..50a9de755 100644 --- a/spec/javascripts/app/views/notification_dropdown_view_spec.js +++ b/spec/javascripts/app/views/notification_dropdown_view_spec.js @@ -5,6 +5,7 @@ describe("app.views.NotificationDropdown", function() { this.header = new app.views.Header(); $("header").prepend(this.header.el); loginAs({guid: "foo"}); + app.notificationsCollection = new app.collections.Notifications(); this.header.render(); this.collection = new app.collections.Notifications(); this.view = new app.views.NotificationDropdown({el: "#notification-dropdown", collection: this.collection}); diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index a43d12a76..a5892f77f 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -25,7 +25,8 @@ describe("app.views.Publisher", function() { describe("createStatusMessage", function(){ it("doesn't add the status message to the stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(); + spyOn(app.stream, "addNow"); this.view.createStatusMessage($.Event()); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, responseText: "{\"id\": 1}" }); @@ -198,7 +199,8 @@ describe("app.views.Publisher", function() { describe("createStatusMessage", function(){ it("adds the status message to the stream", function() { - app.stream = { addNow: $.noop }; + app.stream = new app.models.Stream(); + spyOn(app.stream, "addNow"); this.view.createStatusMessage($.Event()); jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, responseText: "{\"id\": 1}" }); diff --git a/spec/javascripts/app/views/single-post-view/single_post_interactions_spec.js b/spec/javascripts/app/views/single-post-view/single_post_interactions_spec.js index 507317a20..dad2951e7 100644 --- a/spec/javascripts/app/views/single-post-view/single_post_interactions_spec.js +++ b/spec/javascripts/app/views/single-post-view/single_post_interactions_spec.js @@ -1,5 +1,6 @@ describe("app.views.SinglePostInteractions", function() { beforeEach(function() { + loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}}); this.post = factory.post(); this.view = new app.views.SinglePostInteractions({model: this.post}); }); diff --git a/spec/javascripts/app/views/stream/shortcuts_spec.js b/spec/javascripts/app/views/stream/shortcuts_spec.js index ba58b54c1..19c1b8d3f 100644 --- a/spec/javascripts/app/views/stream/shortcuts_spec.js +++ b/spec/javascripts/app/views/stream/shortcuts_spec.js @@ -1,6 +1,10 @@ describe("app.views.StreamShortcuts", function () { beforeEach(function() { + // This puts `app.page` into the proper state. + delete app.page; + new app.Router().stream(); + this.post1 = factory.post({author : factory.author({name : "Rebecca Black", id : 1492})}); this.post2 = factory.post({author : factory.author({name : "John Stamos", id : 1987})}); diff --git a/spec/javascripts/app/views/stream_post_spec.js b/spec/javascripts/app/views/stream_post_spec.js index d36a95e4a..2aa9f41fc 100644 --- a/spec/javascripts/app/views/stream_post_spec.js +++ b/spec/javascripts/app/views/stream_post_spec.js @@ -1,5 +1,9 @@ describe("app.views.StreamPost", function(){ beforeEach(function(){ + // This puts `app.page` into the proper state. + delete app.page; + new app.Router().stream(); + this.PostViewClass = app.views.StreamPost; var posts = $.parseJSON(spec.readFixture("stream_json")); diff --git a/spec/javascripts/app/views/stream_view_spec.js b/spec/javascripts/app/views/stream_view_spec.js index c0caee100..a9b602baa 100644 --- a/spec/javascripts/app/views/stream_view_spec.js +++ b/spec/javascripts/app/views/stream_view_spec.js @@ -1,5 +1,9 @@ describe("app.views.Stream", function() { beforeEach(function() { + // This puts `app.page` into the proper state. + delete app.page; + new app.Router().stream(); + loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); this.posts = $.parseJSON(spec.readFixture("stream_json")); |