|
1 | | -import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; |
| 1 | +import { |
| 2 | + ComponentFixture, |
| 3 | + discardPeriodicTasks, |
| 4 | + fakeAsync, |
| 5 | + flush, |
| 6 | + flushMicrotasks, |
| 7 | + TestBed, |
| 8 | + tick, |
| 9 | + waitForAsync |
| 10 | +} from '@angular/core/testing'; |
2 | 11 | import { RouterTestingModule } from '@angular/router/testing'; |
3 | 12 |
|
4 | | -import { Observable, of } from 'rxjs'; |
| 13 | +import { delay, Observable, of, throwError } from 'rxjs'; |
5 | 14 |
|
6 | 15 | import { changeBrowserInnerWidth } from './../../util-test/util-expect.spec'; |
7 | 16 | import { getObservable } from '../../util-test/util-expect.spec'; |
@@ -433,17 +442,49 @@ describe('PoPageJobSchedulerComponent:', () => { |
433 | 442 | }); |
434 | 443 | }); |
435 | 444 |
|
436 | | - it(`emitSuccessMessage: should call 'poNotification.success' with message and call 'resetJobSchedulerForm'`, async () => { |
437 | | - const message = 'msgSuccess'; |
| 445 | + it('should emit success event, show notification, and reset form on successful save', fakeAsync(() => { |
| 446 | + const model = { |
| 447 | + periodicity: 'always', |
| 448 | + firstExecution: new Date(), |
| 449 | + firstExecutionHour: '23:55:00', |
| 450 | + recurrent: true |
| 451 | + }; |
438 | 452 |
|
| 453 | + const parameters = ['']; |
| 454 | + const successSpy = spyOn(component.success, 'emit').and.callThrough(); |
439 | 455 | spyOn(component['poNotification'], 'success'); |
440 | 456 | spyOn(component, <any>'resetJobSchedulerForm'); |
| 457 | + spyOn(component['poPageJobSchedulerService'], 'createResource').and.returnValue(getObservable(parameters)); |
441 | 458 |
|
442 | | - await component['emitSuccessMessage'](message, of()); |
| 459 | + component['save'](model, null); |
| 460 | + |
| 461 | + tick(50); |
443 | 462 |
|
444 | | - expect(component['poNotification'].success).toHaveBeenCalledWith(message); |
445 | 463 | expect(component['resetJobSchedulerForm']).toHaveBeenCalled(); |
446 | | - }); |
| 464 | + expect(component['poNotification'].success).toHaveBeenCalled(); |
| 465 | + expect(successSpy).toHaveBeenCalled(); |
| 466 | + |
| 467 | + discardPeriodicTasks(); |
| 468 | + })); |
| 469 | + |
| 470 | + it('should emit error if there is an error in the API return', fakeAsync(() => { |
| 471 | + const model = { |
| 472 | + periodicity: 'always', |
| 473 | + firstExecution: new Date(), |
| 474 | + firstExecutionHour: '23:55:00', |
| 475 | + recurrent: true |
| 476 | + }; |
| 477 | + |
| 478 | + const errorSpy = spyOn(component.error, 'emit').and.callThrough(); |
| 479 | + spyOn(component['poPageJobSchedulerService'], 'createResource').and.returnValue(throwError(() => {})); |
| 480 | + |
| 481 | + component['save'](model, null); |
| 482 | + |
| 483 | + tick(50); |
| 484 | + expect(errorSpy).toHaveBeenCalled(); |
| 485 | + |
| 486 | + discardPeriodicTasks(); |
| 487 | + })); |
447 | 488 |
|
448 | 489 | it(`getParametersByProcess: should call 'getParametersByProcess' with process and set 'component.parameters' |
449 | 490 | with 'parameters'`, fakeAsync(() => { |
|
0 commit comments