Browse Source

more components

* Footer moved to component
* Guest and Login components tests cleanup
* Ban expiration moved to component
* Updated templates to don’t rely on proxying
Rafał Pitoń 10 years ago
parent
commit
6422a6c2f6

+ 2 - 1
misago/emberapp/app/controllers/error-banned.js → misago/emberapp/app/components/ban-expires.js

@@ -1,6 +1,7 @@
 import Ember from 'ember';
 import Ember from 'ember';
 
 
-export default Ember.ObjectController.extend({
+export default Ember.Component.extend({
+  tagName: 'p',
   isPermanent: Ember.computed.empty('model.expires_on'),
   isPermanent: Ember.computed.empty('model.expires_on'),
 
 
   expiresMoment: function() {
   expiresMoment: function() {

+ 2 - 2
misago/emberapp/app/controllers/footer.js → misago/emberapp/app/components/forum-footer.js

@@ -1,6 +1,6 @@
 import Ember from 'ember';
 import Ember from 'ember';
 
 
-export default Ember.Controller.extend({
+export default Ember.Component.extend({
   showTermsLink: function() {
   showTermsLink: function() {
     return this.get('settings.terms_of_service') || this.get('settings.terms_of_service_link');
     return this.get('settings.terms_of_service') || this.get('settings.terms_of_service_link');
   }.property('settings'),
   }.property('settings'),
@@ -9,7 +9,7 @@ export default Ember.Controller.extend({
     return this.get('settings.privacy_policy') || this.get('settings.privacy_policy_link');
     return this.get('settings.privacy_policy') || this.get('settings.privacy_policy_link');
   }.property('settings'),
   }.property('settings'),
 
 
-  showNav: function() {
+  hasContent: function() {
     return this.get('showTermsLink') || this.get('showPrivacyLink') || this.get('settings.forum_footnote');
     return this.get('showTermsLink') || this.get('showPrivacyLink') || this.get('settings.forum_footnote');
   }.property('settings', 'showTermsLink', 'showPrivacyLink')
   }.property('settings', 'showTermsLink', 'showPrivacyLink')
 });
 });

+ 1 - 1
misago/emberapp/app/templates/application.hbs

@@ -5,5 +5,5 @@
   {{outlet}}
   {{outlet}}
 </div>
 </div>
 
 
-{{render "footer"}}
+{{forum-footer}}
 {{login-modal}}
 {{login-modal}}

+ 7 - 0
misago/emberapp/app/templates/components/ban-expires.hbs

@@ -0,0 +1,7 @@
+{{#if isPermanent}}
+{{gettext "This ban is permanent."}}
+{{else if isExpired}}
+{{gettext "This ban expired %(expires)s. Please try again." expires=(from-now expiresOn)}}
+{{else}}
+{{gettext "This ban expires %(expires)s." expires=(from-now expiresOn)}}
+{{/if}}

+ 1 - 1
misago/emberapp/app/templates/footer.hbs → misago/emberapp/app/templates/components/forum-footer.hbs

@@ -2,7 +2,7 @@
   <div class="container">
   <div class="container">
     <div class="footer-content">
     <div class="footer-content">
 
 
-    {{#if showNav}}
+    {{#if hasContent}}
       <div class="first-row">
       <div class="first-row">
         <ul class="list-inline footer-nav">
         <ul class="list-inline footer-nav">
         {{#if showTermsLink}}
         {{#if showTermsLink}}

+ 2 - 8
misago/emberapp/app/templates/error-banned.hbs

@@ -8,16 +8,10 @@
 
 
       <div class="error-message">
       <div class="error-message">
         <div class="lead">
         <div class="lead">
-          {{{message.html}}}
+          {{{model.message.html}}}
         </div>
         </div>
 
 
-        {{#if isPermanent}}
-        <p>{{gettext "This ban is permanent."}}</p>
-        {{else if isExpired}}
-        <p>{{gettext "This ban expired %(expires)s. Please try again." expires=(from-now expiresOn)}}</p>
-        {{else}}
-        <p>{{gettext "This ban expires %(expires)s." expires=(from-now expiresOn)}}</p>
-        {{/if}}
+        {{ban-expires model=model}}
       </div>
       </div>
 
 
     </div>
     </div>

+ 2 - 2
misago/emberapp/app/templates/privacy-policy.hbs

@@ -1,13 +1,13 @@
 <div class="legal-page legal-privacy-policy">
 <div class="legal-page legal-privacy-policy">
   <div class="page-header">
   <div class="page-header">
     <div class="container">
     <div class="container">
-      <h1>{{title}}</h1>
+      <h1>{{model.title}}</h1>
     </div>
     </div>
   </div>
   </div>
 
 
   <div class="legal-body container">
   <div class="legal-body container">
     <article class="misago-markup">
     <article class="misago-markup">
-      {{{body}}}
+      {{{model.body}}}
     </article>
     </article>
   </div>
   </div>
 </div>
 </div>

+ 2 - 2
misago/emberapp/app/templates/terms-of-service.hbs

@@ -1,13 +1,13 @@
 <div class="legal-page legal-terms-of-service">
 <div class="legal-page legal-terms-of-service">
   <div class="page-header">
   <div class="page-header">
     <div class="container">
     <div class="container">
-      <h1>{{title}}</h1>
+      <h1>{{model.title}}</h1>
     </div>
     </div>
   </div>
   </div>
 
 
   <div class="legal-body container">
   <div class="legal-body container">
     <article class="misago-markup">
     <article class="misago-markup">
-      {{{body}}}
+      {{{model.body}}}
     </article>
     </article>
   </div>
   </div>
 </div>
 </div>

+ 1 - 1
misago/emberapp/tests/acceptance/activate-test.js

@@ -159,7 +159,7 @@ test('request activation link with banned account', function(assert) {
     var errorMessage = find('.lead p').text();
     var errorMessage = find('.lead p').text();
     assert.equal(errorMessage, 'You are banned for trolling.');
     assert.equal(errorMessage, 'You are banned for trolling.');
 
 
-    var expirationMessage = find('.error-message>p').text();
+    var expirationMessage = Ember.$.trim(find('.error-message>p').text());
     assert.equal(expirationMessage, 'This ban is permanent.');
     assert.equal(expirationMessage, 'This ban is permanent.');
   });
   });
 });
 });

+ 1 - 1
misago/emberapp/tests/acceptance/error-test.js

@@ -131,7 +131,7 @@ test('banned', function(assert) {
     var errorMessage = find('.lead p').text();
     var errorMessage = find('.lead p').text();
     assert.equal(errorMessage, 'You are banned.');
     assert.equal(errorMessage, 'You are banned.');
 
 
-    var expirationMessage = find('.error-message>p').text();
+    var expirationMessage = Ember.$.trim(find('.error-message>p').text());
     assert.equal(expirationMessage, 'This ban is permanent.');
     assert.equal(expirationMessage, 'This ban is permanent.');
   });
   });
 });
 });

+ 1 - 1
misago/emberapp/tests/acceptance/forgotten-password-test.js

@@ -159,7 +159,7 @@ test('request password change link with banned account', function(assert) {
     var errorMessage = find('.lead p').text();
     var errorMessage = find('.lead p').text();
     assert.equal(errorMessage, 'You are banned for trolling.');
     assert.equal(errorMessage, 'You are banned for trolling.');
 
 
-    var expirationMessage = find('.error-message>p').text();
+    var expirationMessage = Ember.$.trim(find('.error-message>p').text());
     assert.equal(expirationMessage, 'This ban is permanent.');
     assert.equal(expirationMessage, 'This ban is permanent.');
   });
   });
 });
 });

+ 1 - 1
misago/emberapp/tests/acceptance/login-test.js

@@ -161,7 +161,7 @@ test('login to banned account', function(assert) {
     var banMessage = find('.lead p').text();
     var banMessage = find('.lead p').text();
     assert.equal(banMessage, 'You are banned for trolling.');
     assert.equal(banMessage, 'You are banned for trolling.');
 
 
-    var expirationMessage = find('.error-message>p').text();
+    var expirationMessage = Ember.$.trim(find('.error-message>p').text());
     assert.equal(expirationMessage, 'This ban is permanent.');
     assert.equal(expirationMessage, 'This ban is permanent.');
   });
   });
 });
 });

+ 64 - 0
misago/emberapp/tests/unit/components/ban-expires-test.js

@@ -0,0 +1,64 @@
+import {
+  moduleFor,
+  test
+} from 'ember-qunit';
+
+moduleFor('component:ban-expires', 'BanExpiresComponent');
+
+test('it exists', function(assert) {
+  assert.expect(1);
+
+  var component = this.subject();
+  assert.ok(component);
+});
+
+test('isPermanent works', function(assert) {
+  assert.expect(2);
+
+  var component = this.subject();
+
+  component.set('model', {'expires_on': null});
+  assert.ok(component.get('isPermanent'));
+
+  component.set('model', {'expires_on': 'nope'});
+  assert.ok(!component.get('isPermanent'));
+});
+
+test('expiresMoment works', function(assert) {
+  assert.expect(2);
+
+  var component = this.subject();
+
+  component.set('model', {'expires_on': null});
+  assert.equal(component.get('expiresMoment'), null);
+
+  component.set('model', {'expires_on': '2015-07-30T12:15:00Z'});
+  assert.ok(component.get('expiresMoment').fromNow);
+});
+
+test('expiresOn works', function(assert) {
+  assert.expect(2);
+
+  var component = this.subject();
+
+  component.set('model', {'expires_on': null});
+  assert.equal(component.get('expiresOn'), null);
+
+  component.set('model', {'expires_on': '2015-07-30T12:15:00Z'});
+  assert.ok(component.get('expiresOn').fromNow);
+});
+
+test('isExpired works', function(assert) {
+  assert.expect(3);
+
+  var component = this.subject();
+
+  component.set('model', {'expires_on': null});
+  assert.ok(!component.get('isExpired'));
+
+  component.set('model', {'expires_on': '2014-07-30T12:15:00Z'});
+  assert.ok(component.get('isExpired'));
+
+  component.set('model', {'expires_on': '2026-07-30T12:15:00Z'});
+  assert.ok(!component.get('isExpired'));
+});

+ 89 - 0
misago/emberapp/tests/unit/components/forum-footer-test.js

@@ -0,0 +1,89 @@
+import {
+  moduleFor,
+  test
+} from 'ember-qunit';
+
+moduleFor('component:forum-footer', 'FooterComponent');
+
+test('it exists', function(assert) {
+  var component = this.subject();
+  assert.ok(component);
+});
+
+test('showTermsLink', function(assert) {
+  assert.expect(4);
+
+  var component = this.subject();
+
+  // ToS isn't defined and there isn't link to remote ToS page, don't show link
+  component.set('settings', {'terms_of_service': null, 'terms_of_service_link': ''});
+  assert.ok(!component.get('showTermsLink'));
+
+  // ToS is defined but there isn't link to remote ToS page, show link
+  component.set('settings', {'terms_of_service': true, 'terms_of_service_link': ''});
+  assert.ok(component.get('showTermsLink'));
+
+  // ToS isn't defined but there is link to remote ToS page, show link
+  component.set('settings', {'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com'});
+  assert.ok(component.get('showTermsLink'));
+
+  // ToS is defined and there is link to remote ToS page, show link
+  component.set('settings', {'terms_of_service': true, 'terms_of_service_link': 'http://somewhere.com'});
+  assert.ok(component.get('showTermsLink'));
+});
+
+test('showPrivacyLink', function(assert) {
+  assert.expect(4);
+
+  var component = this.subject();
+
+  // PrivPolicy isn't defined and there isn't link to remote PrivPolicy page, don't show link
+  component.set('settings', {'privacy_policy': null, 'privacy_policy_link': ''});
+  assert.ok(!component.get('showPrivacyLink'));
+
+  // PrivPolicy is defined but there isn't link to remote PrivPolicy page, show link
+  component.set('settings', {'privacy_policy': true, 'privacy_policy_link': ''});
+  assert.ok(component.get('showPrivacyLink'));
+
+  // PrivPolicy isn't defined but there is link to remote PrivPolicy page, show link
+  component.set('settings', {'privacy_policy': null, 'privacy_policy_link': 'http://somewhere.com'});
+  assert.ok(component.get('showPrivacyLink'));
+
+  // PrivPolicy is defined and there is link to remote PrivPolicy page, show link
+  component.set('settings', {'privacy_policy': true, 'privacy_policy_link': 'http://somewhere.com'});
+  assert.ok(component.get('showPrivacyLink'));
+});
+
+test('hasContent', function(assert) {
+  assert.expect(4);
+
+  var component = this.subject();
+
+  // no Privacy Policy or ToS, don't show footer nav
+  component.set('settings', {
+    'terms_of_service': null, 'terms_of_service_link': '',
+    'privacy_policy': null, 'privacy_policy_link': ''
+  });
+  assert.ok(!component.get('hasContent'));
+
+  // Privacy Policy but no ToS, don't show footer nav
+  component.set('settings', {
+    'terms_of_service': null, 'terms_of_service_link': '',
+    'privacy_policy': true, 'privacy_policy_link': ''
+  });
+  assert.ok(component.get('hasContent'));
+
+  // no Privacy Policy but ToS, don't show footer nav
+  component.set('settings', {
+    'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com',
+    'privacy_policy': null, 'privacy_policy_link': ''
+  });
+  assert.ok(component.get('hasContent'));
+
+  // Privacy Policy and ToS, don't show footer nav
+  component.set('settings', {
+    'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com',
+    'privacy_policy': null, 'privacy_policy_link': 'http://somewhere.com'
+  });
+  assert.ok(component.get('hasContent'));
+});

+ 3 - 3
misago/emberapp/tests/unit/components/guest-nav-test.js

@@ -3,11 +3,11 @@ import {
   test
   test
 } from 'ember-qunit';
 } from 'ember-qunit';
 
 
-moduleFor('component:guest-nav', 'GuestNavController');
+moduleFor('component:guest-nav', 'GuestNavComponent');
 
 
 test('it exists', function(assert) {
 test('it exists', function(assert) {
   assert.expect(1);
   assert.expect(1);
 
 
-  var controller = this.subject();
-  assert.ok(controller);
+  var component = this.subject();
+  assert.ok(component);
 });
 });

+ 17 - 17
misago/emberapp/tests/unit/components/login-modal-test.js

@@ -4,15 +4,15 @@ import {
   test
   test
 } from 'ember-qunit';
 } from 'ember-qunit';
 
 
-moduleFor('component:login-modal', 'LoginModalController');
+moduleFor('component:login-modal', 'LoginModalComponent');
 
 
 test('it exists', function(assert) {
 test('it exists', function(assert) {
   assert.expect(1);
   assert.expect(1);
 
 
   var self = this;
   var self = this;
   Ember.run(function(){
   Ember.run(function(){
-    var controller = self.subject();
-    assert.ok(controller);
+    var component = self.subject();
+    assert.ok(component);
   });
   });
 });
 });
 
 
@@ -21,26 +21,26 @@ test('reset works', function(assert) {
 
 
   var self = this;
   var self = this;
   Ember.run(function(){
   Ember.run(function(){
-    var controller = self.subject();
+    var component = self.subject();
 
 
-    controller.set('username', 'TestUsername');
-    controller.set('password', 'secretpassword');
+    component.set('username', 'TestUsername');
+    component.set('password', 'secretpassword');
 
 
-    controller.set('isLoading', true);
-    controller.set('showActivation', true);
+    component.set('isLoading', true);
+    component.set('showActivation', true);
 
 
-    assert.equal(controller.get('username'), 'TestUsername');
-    assert.equal(controller.get('password'), 'secretpassword');
+    assert.equal(component.get('username'), 'TestUsername');
+    assert.equal(component.get('password'), 'secretpassword');
 
 
-    assert.equal(controller.get('isLoading'), true);
-    assert.equal(controller.get('showActivation'), true);
+    assert.equal(component.get('isLoading'), true);
+    assert.equal(component.get('showActivation'), true);
 
 
-    controller.reset();
+    component.reset();
 
 
-    assert.equal(controller.get('username'), '');
-    assert.equal(controller.get('password'), '');
+    assert.equal(component.get('username'), '');
+    assert.equal(component.get('password'), '');
 
 
-    assert.equal(controller.get('isLoading'), false);
-    assert.equal(controller.get('showActivation'), false);
+    assert.equal(component.get('isLoading'), false);
+    assert.equal(component.get('showActivation'), false);
   });
   });
 });
 });

+ 0 - 64
misago/emberapp/tests/unit/controllers/error-banned-test.js

@@ -1,64 +0,0 @@
-import {
-  moduleFor,
-  test
-} from 'ember-qunit';
-
-moduleFor('controller:error-banned', 'ErrorBannedController');
-
-test('it exists', function(assert) {
-  assert.expect(1);
-
-  var controller = this.subject();
-  assert.ok(controller);
-});
-
-test('isPermanent works', function(assert) {
-  assert.expect(2);
-
-  var controller = this.subject();
-
-  controller.set('model', {'expires_on': null});
-  assert.ok(controller.get('isPermanent'));
-
-  controller.set('model', {'expires_on': 'nope'});
-  assert.ok(!controller.get('isPermanent'));
-});
-
-test('expiresMoment works', function(assert) {
-  assert.expect(2);
-
-  var controller = this.subject();
-
-  controller.set('model', {'expires_on': null});
-  assert.equal(controller.get('expiresMoment'), null);
-
-  controller.set('model', {'expires_on': '2015-07-30T12:15:00Z'});
-  assert.ok(controller.get('expiresMoment').fromNow);
-});
-
-test('expiresOn works', function(assert) {
-  assert.expect(2);
-
-  var controller = this.subject();
-
-  controller.set('model', {'expires_on': null});
-  assert.equal(controller.get('expiresOn'), null);
-
-  controller.set('model', {'expires_on': '2015-07-30T12:15:00Z'});
-  assert.ok(controller.get('expiresOn').fromNow);
-});
-
-test('isExpired works', function(assert) {
-  assert.expect(3);
-
-  var controller = this.subject();
-
-  controller.set('model', {'expires_on': null});
-  assert.ok(!controller.get('isExpired'));
-
-  controller.set('model', {'expires_on': '2014-07-30T12:15:00Z'});
-  assert.ok(controller.get('isExpired'));
-
-  controller.set('model', {'expires_on': '2026-07-30T12:15:00Z'});
-  assert.ok(!controller.get('isExpired'));
-});

+ 0 - 89
misago/emberapp/tests/unit/controllers/footer-test.js

@@ -1,89 +0,0 @@
-import {
-  moduleFor,
-  test
-} from 'ember-qunit';
-
-moduleFor('controller:footer', 'FooterController');
-
-test('it exists', function(assert) {
-  var controller = this.subject();
-  assert.ok(controller);
-});
-
-test('showTermsLink', function(assert) {
-  assert.expect(4);
-
-  var controller = this.subject();
-
-  // ToS isn't defined and there isn't link to remote ToS page, don't show link
-  controller.set('settings', {'terms_of_service': null, 'terms_of_service_link': ''});
-  assert.ok(!controller.get('showTermsLink'));
-
-  // ToS is defined but there isn't link to remote ToS page, show link
-  controller.set('settings', {'terms_of_service': true, 'terms_of_service_link': ''});
-  assert.ok(controller.get('showTermsLink'));
-
-  // ToS isn't defined but there is link to remote ToS page, show link
-  controller.set('settings', {'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com'});
-  assert.ok(controller.get('showTermsLink'));
-
-  // ToS is defined and there is link to remote ToS page, show link
-  controller.set('settings', {'terms_of_service': true, 'terms_of_service_link': 'http://somewhere.com'});
-  assert.ok(controller.get('showTermsLink'));
-});
-
-test('showPrivacyLink', function(assert) {
-  assert.expect(4);
-
-  var controller = this.subject();
-
-  // PrivPolicy isn't defined and there isn't link to remote PrivPolicy page, don't show link
-  controller.set('settings', {'privacy_policy': null, 'privacy_policy_link': ''});
-  assert.ok(!controller.get('showPrivacyLink'));
-
-  // PrivPolicy is defined but there isn't link to remote PrivPolicy page, show link
-  controller.set('settings', {'privacy_policy': true, 'privacy_policy_link': ''});
-  assert.ok(controller.get('showPrivacyLink'));
-
-  // PrivPolicy isn't defined but there is link to remote PrivPolicy page, show link
-  controller.set('settings', {'privacy_policy': null, 'privacy_policy_link': 'http://somewhere.com'});
-  assert.ok(controller.get('showPrivacyLink'));
-
-  // PrivPolicy is defined and there is link to remote PrivPolicy page, show link
-  controller.set('settings', {'privacy_policy': true, 'privacy_policy_link': 'http://somewhere.com'});
-  assert.ok(controller.get('showPrivacyLink'));
-});
-
-test('showNav', function(assert) {
-  assert.expect(4);
-
-  var controller = this.subject();
-
-  // no Privacy Policy or ToS, don't show footer nav
-  controller.set('settings', {
-    'terms_of_service': null, 'terms_of_service_link': '',
-    'privacy_policy': null, 'privacy_policy_link': ''
-  });
-  assert.ok(!controller.get('showNav'));
-
-  // Privacy Policy but no ToS, don't show footer nav
-  controller.set('settings', {
-    'terms_of_service': null, 'terms_of_service_link': '',
-    'privacy_policy': true, 'privacy_policy_link': ''
-  });
-  assert.ok(controller.get('showNav'));
-
-  // no Privacy Policy but ToS, don't show footer nav
-  controller.set('settings', {
-    'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com',
-    'privacy_policy': null, 'privacy_policy_link': ''
-  });
-  assert.ok(controller.get('showNav'));
-
-  // Privacy Policy and ToS, don't show footer nav
-  controller.set('settings', {
-    'terms_of_service': null, 'terms_of_service_link': 'http://somewhere.com',
-    'privacy_policy': null, 'privacy_policy_link': 'http://somewhere.com'
-  });
-  assert.ok(controller.get('showNav'));
-});