From 09aff306486215fd9126b11ebd7c8cc31ed79a5c Mon Sep 17 00:00:00 2001
From: Steffen van Bergerem <svbergerem@online.de>
Date: Tue, 9 Aug 2016 00:55:44 +0200
Subject: [PATCH] Fix hovercards on profile edit page

---
 app/assets/javascripts/app/app.js             |  5 +++++
 app/assets/javascripts/app/router.js          | 20 ++++---------------
 features/desktop/notifications.feature        | 15 +++++++++++++-
 features/step_definitions/custom_web_steps.rb |  2 +-
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js
index 3e7e3748b6..25441a651b 100644
--- a/app/assets/javascripts/app/app.js
+++ b/app/assets/javascripts/app/app.js
@@ -47,6 +47,7 @@ var app = {
 
     this.setupDummyPreloads();
     this.setupUser();
+    this.setupAspects();
     this.setupHeader();
     this.setupBackboneLinks();
     this.setupGlobalViews();
@@ -83,6 +84,10 @@ var app = {
     app.currentUser = app.user(window.gon.user) || new app.models.User();
   },
 
+  setupAspects: function() {
+    app.aspects = new app.collections.Aspects(app.currentUser.get("aspects"));
+  },
+
   setupHeader: function() {
     if(app.currentUser.authenticated()) {
       app.header = new app.views.Header();
diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js
index 3c78a57255..e71480f0e7 100644
--- a/app/assets/javascripts/app/router.js
+++ b/app/assets/javascripts/app/router.js
@@ -62,7 +62,7 @@ app.Router = Backbone.Router.extend({
 
   contacts: function() {
     app.aspect = new app.models.Aspect(gon.preloads.aspect);
-    this._loadRelationshipsPreloads();
+    this._loadContacts();
 
     var stream = new app.views.ContactStream({
       collection: app.contacts,
@@ -73,7 +73,6 @@ app.Router = Backbone.Router.extend({
   },
 
   gettingStarted: function() {
-    this._loadAspects();
     this.renderPage(function() {
       return new app.pages.GettingStarted({inviter: new app.models.Person(app.parsePreload("inviter"))});
     });
@@ -107,14 +106,13 @@ app.Router = Backbone.Router.extend({
   },
 
   stream : function() {
-    this._loadAspects();
     app.stream = new app.models.Stream();
     app.stream.fetch();
     this._initializeStreamView();
   },
 
   photos : function(guid) {
-    this._loadRelationshipsPreloads();
+    this._loadContacts();
     this.renderPage(function() {
       return new app.pages.Profile({
         person_id: guid,
@@ -146,7 +144,6 @@ app.Router = Backbone.Router.extend({
   },
 
   aspects: function() {
-    this._loadAspects();
     app.aspectSelections = app.aspectSelections ||
       new app.collections.AspectSelections(app.currentUser.get("aspects"));
     this.aspectsList = this.aspectsList || new app.views.AspectsList({collection: app.aspectSelections});
@@ -170,7 +167,7 @@ app.Router = Backbone.Router.extend({
   },
 
   profile: function() {
-    this._loadRelationshipsPreloads();
+    this._loadContacts();
     this.renderPage(function() {
       return new app.pages.Profile({
         el: $("body > #profile_container")
@@ -179,23 +176,14 @@ app.Router = Backbone.Router.extend({
   },
 
   pageWithAspectMembershipDropdowns: function() {
-    this._loadRelationshipsPreloads();
+    this._loadContacts();
     this.renderAspectMembershipDropdowns($(document));
   },
 
-  _loadAspects: function() {
-    app.aspects = new app.collections.Aspects(app.currentUser.get("aspects"));
-  },
-
   _loadContacts: function() {
     app.contacts = new app.collections.Contacts(app.parsePreload("contacts"));
   },
 
-  _loadRelationshipsPreloads: function() {
-    this._loadContacts();
-    this._loadAspects();
-  },
-
   renderAspectMembershipDropdowns: function($context) {
     $context.find(".aspect_membership_dropdown.placeholder").each(function() {
       var personId = $(this).data("personId");
diff --git a/features/desktop/notifications.feature b/features/desktop/notifications.feature
index aedfe0f4e8..70a454d615 100644
--- a/features/desktop/notifications.feature
+++ b/features/desktop/notifications.feature
@@ -118,11 +118,24 @@ Feature: Notifications
     And I add the person to my "Besties" aspect
     And I sign out
     When I sign in as "alice@alice.alice"
+    And I go to the edit profile page
     And I follow "Notifications" in the header
-    And I active the first hovercard after loading the notifications page
+    And I activate the first hovercard after loading the notifications page
     When I press the aspect dropdown
     Then the aspect dropdown should be visible
 
+  Scenario: show hovercard in notification dropdown
+    When I sign in as "bob@bob.bob"
+    And I am on "alice@alice.alice"'s page
+    And I add the person to my "Besties" aspect
+    And I sign out
+    When I sign in as "alice@alice.alice"
+    And I follow "Notifications" in the header
+    Then the notification dropdown should be visible
+    When I activate the first hovercard after loading the notifications page
+    And I press the aspect dropdown
+    Then the aspect dropdown should be visible
+
   Scenario: scrollbar shows up when >5 notifications
     Given a user with email "bob@bob.bob" is connected with "alice@alice.alice"
     And Alice has 6 posts mentioning Bob
diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb
index 563ae51ec1..6924e53a29 100644
--- a/features/step_definitions/custom_web_steps.rb
+++ b/features/step_definitions/custom_web_steps.rb
@@ -324,7 +324,7 @@ Then(/^I should have a validation error on "(.*?)"$/) do |field_list|
   check_fields_validation_error field_list
 end
 
-And /^I active the first hovercard after loading the notifications page$/ do
+And /^I activate the first hovercard after loading the notifications page$/ do
   page.should have_css '.notifications .hovercardable'
   first('.notifications .hovercardable').hover
 end
-- 
GitLab