Bug 1019454: Hide ToS when it has been seen in the standalone UI. r=Standard8
authorRomain Gauthier <romain.gauthier@monkeypatch.me>
Tue, 26 Aug 2014 09:12:00 +0100
changeset 201570 662567a5e50966aea00811d8ba46dc0318916736
parent 201569 fcafd91816f79dc347885b8f6e0de4fb77720ba4
child 201571 851898432b6fdf0facdee2a57cd13ea895b5be77
push id27374
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 18:16:27 +0000
treeherdermozilla-central@c850f3af9f2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1019454
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1019454: Hide ToS when it has been seen in the standalone UI. r=Standard8
browser/components/loop/standalone/content/js/webapp.js
browser/components/loop/standalone/content/js/webapp.jsx
browser/components/loop/test/standalone/webapp_test.js
--- a/browser/components/loop/standalone/content/js/webapp.js
+++ b/browser/components/loop/standalone/content/js/webapp.js
@@ -198,16 +198,17 @@ loop.webapp = (function($, _, OT, webL10
         var options = {year: "numeric", month: "long", day: "numeric"};
         var timestamp = date.toLocaleDateString(navigator.language, options);
         this.setState({urlCreationDateString: timestamp});
       }
     },
 
     componentWillUnmount: function() {
       window.removeEventListener("click", this.clickHandler);
+      localStorage.setItem("has-seen-tos", "true");
     },
 
     clickHandler: function(e) {
       if (!e.target.classList.contains('btn-chevron') &&
           this.state.showCallOptionsMenu) {
             this._toggleCallOptionsMenu();
       }
     },
@@ -231,16 +232,20 @@ loop.webapp = (function($, _, OT, webL10
       var btnClassStartCall = "btn btn-large btn-success " +
                               "start-audio-video-call " +
                               loop.shared.utils.getTargetPlatform();
       var dropdownMenuClasses = React.addons.classSet({
         "native-dropdown-large-parent": true,
         "standalone-dropdown-menu": true,
         "visually-hidden": !this.state.showCallOptionsMenu
       });
+      var tosClasses = React.addons.classSet({
+        "terms-service": true,
+        hide: (localStorage.getItem("has-seen-tos") === "true")
+      });
 
       return (
         /* jshint ignore:start */
         React.DOM.div({className: "container"}, 
           React.DOM.div({className: "container-box"}, 
 
             ConversationHeader({
               urlCreationDateString: this.state.urlCreationDateString}), 
@@ -283,17 +288,17 @@ loop.webapp = (function($, _, OT, webL10
                     )
                   )
 
                 )
               ), 
               React.DOM.div({className: "flex-padding-1"})
             ), 
 
-            React.DOM.p({className: "terms-service", 
+            React.DOM.p({className: tosClasses, 
                dangerouslySetInnerHTML: {__html: tosHTML}})
           ), 
 
           ConversationFooter(null)
         )
         /* jshint ignore:end */
       );
     }
--- a/browser/components/loop/standalone/content/js/webapp.jsx
+++ b/browser/components/loop/standalone/content/js/webapp.jsx
@@ -198,16 +198,17 @@ loop.webapp = (function($, _, OT, webL10
         var options = {year: "numeric", month: "long", day: "numeric"};
         var timestamp = date.toLocaleDateString(navigator.language, options);
         this.setState({urlCreationDateString: timestamp});
       }
     },
 
     componentWillUnmount: function() {
       window.removeEventListener("click", this.clickHandler);
+      localStorage.setItem("has-seen-tos", "true");
     },
 
     clickHandler: function(e) {
       if (!e.target.classList.contains('btn-chevron') &&
           this.state.showCallOptionsMenu) {
             this._toggleCallOptionsMenu();
       }
     },
@@ -231,16 +232,20 @@ loop.webapp = (function($, _, OT, webL10
       var btnClassStartCall = "btn btn-large btn-success " +
                               "start-audio-video-call " +
                               loop.shared.utils.getTargetPlatform();
       var dropdownMenuClasses = React.addons.classSet({
         "native-dropdown-large-parent": true,
         "standalone-dropdown-menu": true,
         "visually-hidden": !this.state.showCallOptionsMenu
       });
+      var tosClasses = React.addons.classSet({
+        "terms-service": true,
+        hide: (localStorage.getItem("has-seen-tos") === "true")
+      });
 
       return (
         /* jshint ignore:start */
         <div className="container">
           <div className="container-box">
 
             <ConversationHeader
               urlCreationDateString={this.state.urlCreationDateString} />
@@ -283,17 +288,17 @@ loop.webapp = (function($, _, OT, webL10
                     </li>
                   </ul>
 
                 </div>
               </div>
               <div className="flex-padding-1"></div>
             </div>
 
-            <p className="terms-service"
+            <p className={tosClasses}
                dangerouslySetInnerHTML={{__html: tosHTML}}></p>
           </div>
 
           <ConversationFooter />
         </div>
         /* jshint ignore:end */
       );
     }
--- a/browser/components/loop/test/standalone/webapp_test.js
+++ b/browser/components/loop/test/standalone/webapp_test.js
@@ -486,24 +486,16 @@ describe("loop.webapp", function() {
               });
           });
         });
       });
     });
   });
 
   describe("StartConversationView", function() {
-    var conversation;
-
-    beforeEach(function() {
-      conversation = new sharedModels.ConversationModel({}, {
-        sdk: {},
-        pendingCallTimeout: 1000});
-    });
-
     describe("#initialize", function() {
       it("should require a conversation option", function() {
         expect(function() {
           new loop.webapp.WebappRouter();
         }).to.Throw(Error, /missing required conversation/);
       });
     });
 
@@ -643,16 +635,70 @@ describe("loop.webapp", function() {
          " received", function() {
         conversation.trigger("session:error", "tech error");
 
         sinon.assert.calledOnce(notifier.errorL10n);
         sinon.assert.calledWithExactly(notifier.errorL10n,
                                        "unable_retrieve_call_info");
       });
     });
+
+    describe("#render", function() {
+      var conversation, view, requestCallUrlInfo, oldLocalStorageValue;
+
+      beforeEach(function() {
+        oldLocalStorageValue = localStorage.getItem("has-seen-tos");
+        localStorage.removeItem("has-seen-tos");
+
+        conversation = new sharedModels.ConversationModel({
+          loopToken: "fake"
+        }, {
+          sdk: {},
+          pendingCallTimeout: 1000
+        });
+
+        requestCallUrlInfo = sandbox.stub();
+      });
+
+      afterEach(function() {
+        if (oldLocalStorageValue !== null)
+          localStorage.setItem("has-seen-tos", oldLocalStorageValue);
+      });
+
+      it("should show the TOS", function() {
+        var tos;
+
+        view = React.addons.TestUtils.renderIntoDocument(
+          loop.webapp.StartConversationView({
+            model: conversation,
+            notifier: notifier,
+            client: {requestCallUrlInfo: requestCallUrlInfo}
+          })
+        );
+        tos = view.getDOMNode().querySelector(".terms-service");
+
+        expect(tos.classList.contains("hide")).to.equal(false);
+      });
+
+      it("should not show the TOS if it has already been seen", function() {
+        var tos;
+
+        localStorage.setItem("has-seen-tos", "true");
+        view = React.addons.TestUtils.renderIntoDocument(
+          loop.webapp.StartConversationView({
+            model: conversation,
+            notifier: notifier,
+            client: {requestCallUrlInfo: requestCallUrlInfo}
+          })
+        );
+        tos = view.getDOMNode().querySelector(".terms-service");
+
+        expect(tos.classList.contains("hide")).to.equal(true);
+      });
+    });
   });
 
   describe("PromoteFirefoxView", function() {
     describe("#render", function() {
       it("should not render when using Firefox", function() {
         var comp = TestUtils.renderIntoDocument(loop.webapp.PromoteFirefoxView({
           helper: {isFirefox: function() { return true; }}
         }));
@@ -698,9 +744,10 @@ describe("loop.webapp", function() {
         expect(helper.isFirefox("Gecko/Firefox/Chuck Norris")).eql(true);
       });
 
       it("shouldn't detect Firefox with other platforms", function() {
         expect(helper.isFirefox("Opera")).eql(false);
       });
     });
   });
+
 });