Advertisement
Guest User

Untitled

a guest
May 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. import {
  2. async,
  3. ComponentFixture,
  4. fakeAsync,
  5. TestBed
  6. } from '@angular/core/testing';
  7.  
  8. import { Subject } from 'rxjs';
  9.  
  10. import { TestUtils } from '../../../test';
  11.  
  12. import { AddressBookProvider } from '../../../providers/address-book/address-book';
  13. import { ConfigProvider } from './../../../providers/config/config';
  14. import { FeePolicyPage } from './fee-policy';
  15.  
  16. describe('FeePolicyPage', () => {
  17. let fixture: ComponentFixture<FeePolicyPage>;
  18. let instance: any;
  19. let testBed: typeof TestBed;
  20.  
  21. beforeEach(
  22. async(() =>
  23. TestUtils.configurePageTestingModule([FeePolicyPage]).then(testEnv => {
  24. fixture = testEnv.fixture;
  25. instance = testEnv.instance;
  26. testBed = testEnv.testBed;
  27. instance.showCard = {
  28. setShowRateCard: () => { }
  29. };
  30. fixture.detectChanges();
  31. })
  32. )
  33. );
  34. afterEach(() => {
  35. fixture.destroy();
  36. });
  37. describe('Lifecycle Hooks', () => {
  38. describe('ionViewDidEnter', () => {
  39. beforeEach(function () {
  40. spyOn(instance.logger, 'error');
  41. spyOn(instance, 'updateCurrentValues');
  42. });
  43. fit('should set new fee level and update current values', () => {
  44. const pMock = Promise.resolve("data");
  45.  
  46. spyOn(instance.feeProvider, 'getFeeLevels').and.returnValue(pMock);
  47.  
  48. instance.ionViewDidEnter();
  49.  
  50. expect(instance.updateCurrentValues).toHaveBeenCalled();
  51.  
  52. });
  53. // it('should log and set new error if getFeeLevels fails', () => {
  54. // spyOn(instance.feeProvider, 'getFeeLevels').and.throwError("bad error");
  55.  
  56. // instance.ionViewDidEnter();
  57.  
  58. // expect(instance.logger.error).toHaveBeenCalled();
  59. // // expect(instance.error).toEqual("bad error");
  60. // });
  61. });
  62. });
  63. describe('Methods', () => {
  64. describe('#save', () => {
  65. beforeEach(function () {
  66. spyOn(instance.logger, 'debug');
  67. spyOn(instance, 'updateCurrentValues');
  68. spyOn(instance, 'setFee');
  69. spyOn(instance.feeProvider, 'getCurrentFeeLevel').and.returnValue('urgent');
  70. });
  71. it('should do nothing if current fee level is empty', () => {
  72. instance.currentFeeLevel = null;
  73. instance.save();
  74.  
  75. expect(instance.logger.debug).not.toHaveBeenCalled();
  76. expect(instance.updateCurrentValues).not.toHaveBeenCalled();
  77. expect(instance.setFee).not.toHaveBeenCalled();
  78. });
  79. it('should do nothing if current fee level equals existing fee level', () => {
  80. instance.currentFeeLevel = 'urgent';
  81. instance.save();
  82.  
  83. expect(instance.logger.debug).not.toHaveBeenCalled();
  84. expect(instance.updateCurrentValues).not.toHaveBeenCalled();
  85. expect(instance.setFee).not.toHaveBeenCalled();
  86. });
  87. it('should log new fee level, update current values, and set new fee level', () => {
  88. instance.currentFeeLevel = 'normal';
  89. instance.save();
  90.  
  91. expect(instance.logger.debug).toHaveBeenCalled();
  92. expect(instance.updateCurrentValues).toHaveBeenCalled();
  93. expect(instance.setFee).toHaveBeenCalled();
  94. });
  95. });
  96. });
  97. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement