document-title-mixin-test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. import DocumentTitle from 'misago/mixins/document-title';
  5. var application, container, store, title, forum_name;
  6. module('Acceptance: Page Title Mixin', {
  7. beforeEach: function() {
  8. title = document.title;
  9. application = startApp();
  10. container = application.__container__;
  11. forum_name = container.lookup('misago:settings').forum_name;
  12. },
  13. afterEach: function() {
  14. document.title = title;
  15. container.lookup('misago:settings').forum_name = forum_name;
  16. Ember.run(application, 'destroy');
  17. }
  18. });
  19. test('setTitle changes document title', function(assert) {
  20. assert.expect(5);
  21. var TestRoute = Ember.Object.extend(DocumentTitle, {
  22. settings: container.lookup('misago:settings')
  23. });
  24. container.lookup('misago:settings').forum_name = 'Test Forum';
  25. var mixin = TestRoute.create();
  26. // string argument
  27. mixin.set('title', 'Welcome!');
  28. assert.equal(document.title, 'Welcome! | Test Forum');
  29. // object argument
  30. mixin.set('title', {title: 'Thread'});
  31. assert.equal(document.title, 'Thread | Test Forum');
  32. // object argument with parent
  33. mixin.set('title', {title: 'Test Thread', parent: 'Support'});
  34. assert.equal(document.title, 'Test Thread | Support | Test Forum');
  35. // object argument with page
  36. mixin.set('title', {title: 'Test Thread', page: 12});
  37. assert.equal(document.title, 'Test Thread (page 12) | Test Forum');
  38. // object argument with page and parent
  39. mixin.set('title', {title: 'Test Thread', page: 12, parent: 'Support'});
  40. assert.equal(document.title, 'Test Thread (page 12) | Support | Test Forum');
  41. });