errors_handler_controller_test.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/global/errors_handler_controller');
  20. describe('App.ErrorsHandlerController', function () {
  21. var controller;
  22. beforeEach(function() {
  23. controller = App.ErrorsHandlerController.create();
  24. });
  25. describe("#loadErrorLogs()", function () {
  26. beforeEach(function() {
  27. sinon.stub(controller, 'getUserPref');
  28. });
  29. afterEach(function() {
  30. controller.getUserPref.restore();
  31. });
  32. it("getUserPref should be called", function() {
  33. controller.loadErrorLogs();
  34. expect(controller.getUserPref.calledWith('errors')).to.be.true;
  35. });
  36. });
  37. describe("#saveErrorLogs()", function () {
  38. beforeEach(function() {
  39. sinon.stub(controller, 'postUserPref');
  40. });
  41. afterEach(function() {
  42. controller.postUserPref.restore();
  43. });
  44. it("postUserPref should be called", function() {
  45. controller.saveErrorLogs('err', 'url', 1, 2, {});
  46. var args = controller.postUserPref.getCall(0).args;
  47. expect(JSON.stringify(args[1][Object.keys(args[1])[0]])).to.be.equal(JSON.stringify({
  48. "file": "url",
  49. "line": 1,
  50. "col": 2,
  51. "error": "err"
  52. }));
  53. expect(args[0]).to.be.equal('errors');
  54. });
  55. });
  56. });