error-handling-test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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': 'The kek'
  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('not found route', function(assert) {
  82. visit('/this-url-really-doesnt-exist');
  83. andThen(function() {
  84. assert.equal(currentPath(), 'error-404');
  85. });
  86. });