error-handling-test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Ember from 'ember';
  2. import startApp from '../helpers/start-app';
  3. var application;
  4. module('Acceptance: Application Error Handler', {
  5. setup: function() {
  6. application = startApp();
  7. },
  8. teardown: function() {
  9. Ember.run(application, 'destroy');
  10. Ember.$.mockjax.clear();
  11. }
  12. });
  13. test('some unhandled error occured', function() {
  14. Ember.$.mockjax({
  15. url: "/api/legal-pages/privacy-policy/",
  16. status: 500,
  17. responseText: {
  18. 'detail': 'The kek'
  19. }
  20. });
  21. visit('/privacy-policy');
  22. andThen(function() {
  23. equal(currentPath(), 'error');
  24. });
  25. });
  26. test('app went away', function() {
  27. Ember.$.mockjax({
  28. url: "/api/legal-pages/privacy-policy/",
  29. status: 0,
  30. responseText: {
  31. 'detail': 'Connection rejected'
  32. }
  33. });
  34. visit('/privacy-policy');
  35. andThen(function() {
  36. equal(currentPath(), 'error-0');
  37. });
  38. });
  39. test('not found', function() {
  40. Ember.$.mockjax({
  41. url: "/api/legal-pages/privacy-policy/",
  42. status: 404,
  43. responseText: {
  44. 'detail': 'Not found'
  45. }
  46. });
  47. visit('/privacy-policy');
  48. andThen(function() {
  49. equal(currentPath(), 'error-404');
  50. });
  51. });
  52. test('permission denied', function() {
  53. Ember.$.mockjax({
  54. url: "/api/legal-pages/privacy-policy/",
  55. status: 403,
  56. responseText: {
  57. 'detail': 'Permission denied'
  58. }
  59. });
  60. visit('/privacy-policy');
  61. andThen(function() {
  62. equal(currentPath(), 'error-403');
  63. });
  64. });
  65. test('permission denied with reason', function() {
  66. Ember.$.mockjax({
  67. url: "/api/legal-pages/privacy-policy/",
  68. status: 403,
  69. responseText: {
  70. 'detail': 'Lorem ipsum dolor met.'
  71. }
  72. });
  73. visit('/privacy-policy');
  74. andThen(function() {
  75. equal(currentPath(), 'error-403');
  76. var $e = find('.lead');
  77. equal(Ember.$.trim($e.text()), 'Lorem ipsum dolor met.');
  78. });
  79. });
  80. test('not found route', function() {
  81. visit('/this-url-really-doesnt-exist');
  82. andThen(function() {
  83. equal(currentPath(), 'error-404');
  84. });
  85. });