error-test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. var application;
  5. module('Acceptance: Application Error Handler', {
  6. beforeEach: function() {
  7. application = startApp();
  8. },
  9. afterEach: function() {
  10. Ember.run(application, 'destroy');
  11. Ember.$.mockjax.clear();
  12. }
  13. });
  14. test('some unhandled error occured', function(assert) {
  15. assert.expect(1);
  16. Ember.$.mockjax({
  17. url: '/api/legal-pages/privacy-policy/',
  18. status: 500,
  19. responseText: {
  20. 'detail': 'Some terrible Django error'
  21. }
  22. });
  23. visit('/privacy-policy');
  24. andThen(function() {
  25. assert.equal(currentPath(), 'error');
  26. });
  27. });
  28. test('app went away', function(assert) {
  29. assert.expect(1);
  30. Ember.$.mockjax({
  31. url: '/api/legal-pages/privacy-policy/',
  32. status: 0,
  33. responseText: {
  34. 'detail': 'Connection rejected'
  35. }
  36. });
  37. visit('/privacy-policy');
  38. andThen(function() {
  39. assert.equal(currentPath(), 'error-0');
  40. });
  41. });
  42. test('not found', function(assert) {
  43. assert.expect(1);
  44. Ember.$.mockjax({
  45. url: '/api/legal-pages/privacy-policy/',
  46. status: 404,
  47. responseText: {
  48. 'detail': 'Not found'
  49. }
  50. });
  51. visit('/privacy-policy');
  52. andThen(function() {
  53. assert.equal(currentPath(), 'error-404');
  54. });
  55. });
  56. test('permission denied', function(assert) {
  57. assert.expect(1);
  58. Ember.$.mockjax({
  59. url: '/api/legal-pages/privacy-policy/',
  60. status: 403,
  61. responseText: {
  62. 'detail': 'Permission denied'
  63. }
  64. });
  65. visit('/privacy-policy');
  66. andThen(function() {
  67. assert.equal(currentPath(), 'error-403');
  68. });
  69. });
  70. test('permission denied with reason', function(assert) {
  71. assert.expect(2);
  72. Ember.$.mockjax({
  73. url: '/api/legal-pages/privacy-policy/',
  74. status: 403,
  75. responseText: {
  76. 'detail': 'Lorem ipsum dolor met.'
  77. }
  78. });
  79. visit('/privacy-policy');
  80. andThen(function() {
  81. assert.equal(currentPath(), 'error-403');
  82. var $e = find('.error-page .lead');
  83. assert.equal(Ember.$.trim($e.text()), 'Lorem ipsum dolor met.');
  84. });
  85. });
  86. test('banned', function(assert) {
  87. assert.expect(3);
  88. Ember.$.mockjax({
  89. url: '/api/legal-pages/privacy-policy/',
  90. status: 403,
  91. responseText: {
  92. 'ban': {
  93. 'expires_on': null,
  94. 'message': {
  95. 'plain': 'You are banned.',
  96. 'html': '<p>You are banned.</p>'
  97. }
  98. }
  99. }
  100. });
  101. visit('/privacy-policy');
  102. andThen(function() {
  103. assert.equal(currentPath(), 'error-banned');
  104. var errorMessage = find('.error-page .lead p').text();
  105. assert.equal(errorMessage, 'You are banned.');
  106. var expirationMessage = Ember.$.trim(find('.error-message>p').text());
  107. assert.equal(expirationMessage, 'This ban is permanent.');
  108. });
  109. });
  110. test('not found route', function(assert) {
  111. assert.expect(1);
  112. visit('/this-url-really-doesnt-exist');
  113. andThen(function() {
  114. assert.equal(currentPath(), 'error-404');
  115. });
  116. });