[CSTPER-66] onSubmit test executed within a scheduler and provided _links section on tested data

This commit is contained in:
Corrado Lombardi
2020-10-23 11:53:35 +02:00
parent d50d1506ef
commit 564e4e0b02

View File

@@ -36,6 +36,7 @@ describe('CreateComColPageComponent', () => {
let routeServiceStub; let routeServiceStub;
let routerStub; let routerStub;
let requestServiceStub; let requestServiceStub;
let scheduler;
const logoEndpoint = 'rest/api/logo/endpoint'; const logoEndpoint = 'rest/api/logo/endpoint';
@@ -117,6 +118,7 @@ describe('CreateComColPageComponent', () => {
communityDataService = (comp as any).communityDataService; communityDataService = (comp as any).communityDataService;
routeService = (comp as any).routeService; routeService = (comp as any).routeService;
router = (comp as any).router; router = (comp as any).router;
scheduler = getTestScheduler();
}); });
describe('onSubmit', () => { describe('onSubmit', () => {
@@ -146,8 +148,9 @@ describe('CreateComColPageComponent', () => {
it('should navigate and refresh cache when successful', () => { it('should navigate and refresh cache when successful', () => {
spyOn(router, 'navigate'); spyOn(router, 'navigate');
spyOn((comp as any), 'refreshCache'); spyOn((comp as any), 'refreshCache')
comp.onSubmit(data); scheduler.schedule(() => comp.onSubmit(data));
scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
expect(router.navigate).toHaveBeenCalled(); expect(router.navigate).toHaveBeenCalled();
expect((comp as any).refreshCache).toHaveBeenCalled(); expect((comp as any).refreshCache).toHaveBeenCalled();
@@ -157,7 +160,8 @@ describe('CreateComColPageComponent', () => {
spyOn(router, 'navigate'); spyOn(router, 'navigate');
spyOn(dsoDataService, 'create').and.returnValue(createFailedRemoteDataObject$(newCommunity)); spyOn(dsoDataService, 'create').and.returnValue(createFailedRemoteDataObject$(newCommunity));
spyOn((comp as any), 'refreshCache') spyOn((comp as any), 'refreshCache')
comp.onSubmit(data); scheduler.schedule(() => comp.onSubmit(data));
scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
expect(router.navigate).not.toHaveBeenCalled(); expect(router.navigate).not.toHaveBeenCalled();
expect((comp as any).refreshCache).not.toHaveBeenCalled(); expect((comp as any).refreshCache).not.toHaveBeenCalled();
@@ -173,6 +177,7 @@ describe('CreateComColPageComponent', () => {
value: 'test' value: 'test'
}] }]
}), }),
_links: {},
uploader: { uploader: {
options: { options: {
url: '' url: ''
@@ -189,27 +194,29 @@ describe('CreateComColPageComponent', () => {
it('should not navigate', () => { it('should not navigate', () => {
spyOn(router, 'navigate'); spyOn(router, 'navigate');
comp.onSubmit(data); scheduler.schedule(() => comp.onSubmit(data));
scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
expect(router.navigate).not.toHaveBeenCalled(); expect(router.navigate).not.toHaveBeenCalled();
}); });
it('should set the uploader\'s url to the logo\'s endpoint', () => { it('should set the uploader\'s url to the logo\'s endpoint', () => {
comp.onSubmit(data); scheduler.schedule(() => comp.onSubmit(data));
scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
expect(data.uploader.options.url).toEqual(logoEndpoint); expect(data.uploader.options.url).toEqual(logoEndpoint);
}); });
it('should call the uploader\'s uploadAll', () => { it('should call the uploader\'s uploadAll', () => {
spyOn(data.uploader, 'uploadAll'); spyOn(data.uploader, 'uploadAll');
comp.onSubmit(data); scheduler.schedule(() => comp.onSubmit(data));
scheduler.flush();
fixture.detectChanges(); fixture.detectChanges();
expect(data.uploader.uploadAll).toHaveBeenCalled(); expect(data.uploader.uploadAll).toHaveBeenCalled();
}); });
}); });
describe('cache refresh', () => { describe('cache refresh', () => {
let scheduler;
let communityWithoutParentHref; let communityWithoutParentHref;
beforeEach(() => { beforeEach(() => {