error-handling-test.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. Ember.$.mockjax({
  16. url: "/api/legal-pages/privacy-policy/",
  17. status: 500,
  18. responseText: {
  19. 'detail': 'Some terrible Django error'
  20. }
  21. });
  22. visit('/privacy-policy');
  23. andThen(function() {
  24. assert.equal(currentPath(), 'error');
  25. });
  26. });
  27. test('app went away', function(assert) {
  28. Ember.$.mockjax({
  29. url: "/api/legal-pages/privacy-policy/",
  30. status: 0,
  31. responseText: {
  32. 'detail': 'Connection rejected'
  33. }
  34. });
  35. visit('/privacy-policy');
  36. andThen(function() {
  37. assert.equal(currentPath(), 'error-0');
  38. });
  39. });
  40. test('not found', function(assert) {
  41. Ember.$.mockjax({
  42. url: "/api/legal-pages/privacy-policy/",
  43. status: 404,
  44. responseText: {
  45. 'detail': 'Not found'
  46. }
  47. });
  48. visit('/privacy-policy');
  49. andThen(function() {
  50. assert.equal(currentPath(), 'error-404');
  51. });
  52. });
  53. test('permission denied', function(assert) {
  54. Ember.$.mockjax({
  55. url: "/api/legal-pages/privacy-policy/",
  56. status: 403,
  57. responseText: {
  58. 'detail': 'Permission denied'
  59. }
  60. });
  61. visit('/privacy-policy');
  62. andThen(function() {
  63. assert.equal(currentPath(), 'error-403');
  64. });
  65. });
  66. test('permission denied with reason', function(assert) {
  67. Ember.$.mockjax({
  68. url: "/api/legal-pages/privacy-policy/",
  69. status: 403,
  70. responseText: {
  71. 'detail': 'Lorem ipsum dolor met.'
  72. }
  73. });
  74. visit('/privacy-policy');
  75. andThen(function() {
  76. assert.equal(currentPath(), 'error-403');
  77. var $e = find('.lead');
  78. assert.equal(Ember.$.trim($e.text()), 'Lorem ipsum dolor met.');
  79. });
  80. });
  81. test('banned', function(assert) {
  82. Ember.$.mockjax({
  83. url: "/api/legal-pages/privacy-policy/",
  84. status: 403,
  85. responseText: {
  86. 'ban': {
  87. 'expires_on': null,
  88. 'message': {
  89. 'plain': 'You are banned.',
  90. 'html': '<p>You are banned.</p>'
  91. }
  92. }
  93. }
  94. });
  95. visit('/privacy-policy');
  96. andThen(function() {
  97. assert.equal(currentPath(), 'error-banned');
  98. var errorMessage = find('.lead p').text();
  99. assert.equal(errorMessage, 'You are banned.');
  100. var expirationMessage = find('.error-message>p').text();
  101. assert.equal(expirationMessage, 'This ban is permanent.');
  102. });
  103. });
  104. test('not found route', function(assert) {
  105. visit('/this-url-really-doesnt-exist');
  106. andThen(function() {
  107. assert.equal(currentPath(), 'error-404');
  108. });
  109. });