Skip to content

Commit

Permalink
added test for spinner service
Browse files Browse the repository at this point in the history
  • Loading branch information
BSekula committed May 8, 2024
1 parent 9aeaf9c commit 7594662
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*!

Check failure on line 1 in lib/process-services-cloud/src/lib/form/services/spinner/form-cloud-spinner.service.spec.ts

View workflow job for this annotation

GitHub Actions / Lint

Invalid license header
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormCloudSpinnerService } from './form-cloud-spinner.service';
import { OverlayModule } from '@angular/cdk/overlay';
import { FormService, FormSpinnerEvent } from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';
import { Component } from '@angular/core';
import { FormSpinnerComponent } from '../../components/spinner/form-spinner.component';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
import { PortalModule } from '@angular/cdk/portal';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';

@Component({
selector: 'adf-cloud-overlay-test',
template: `<div>adf-cloud-overlay-test</div>`
})
class SpinnerTestComponent {}

describe('FormCloudSpinnerService', () => {
let fixture: ComponentFixture<SpinnerTestComponent>;
let rootLoader: HarnessLoader;
let spinnerService: FormCloudSpinnerService;
let formService: FormService;

const showSpinnerEvent = new FormSpinnerEvent('toggle-spinner', { showSpinner: true, message: 'LOAD_SPINNER_MESSAGE' });
const hideSpinnerEvent = new FormSpinnerEvent('toggle-spinner', { showSpinner: false });

const onDestroy$ = new Subject<boolean>();

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FormSpinnerComponent, SpinnerTestComponent],
providers: [
FormCloudSpinnerService,
{
provide: FormService,
useValue: {
toggleFormSpinner: new Subject()
}
}
],
imports: [OverlayModule, PortalModule, MatProgressSpinnerModule, TranslateModule.forRoot()]
});

fixture = TestBed.createComponent(SpinnerTestComponent);
rootLoader = TestbedHarnessEnvironment.documentRootLoader(fixture);
spinnerService = TestBed.inject(FormCloudSpinnerService);
formService = TestBed.inject(FormService);
});

it('should toggle spinner', async () => {
spinnerService.initSpinnerHandling(onDestroy$);
formService.toggleFormSpinner.next(showSpinnerEvent);
fixture.detectChanges();

let hasSpinner = await rootLoader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBeTrue();

formService.toggleFormSpinner.next(hideSpinnerEvent);
fixture.detectChanges();

hasSpinner = await rootLoader.hasHarness(MatProgressSpinnerHarness);
expect(hasSpinner).toBeFalse();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
* limitations under the License.
*/

import { FormService, FormSpinnerEvent } from '@alfresco/adf-core';
import { Injectable, inject } from '@angular/core';
import { Overlay, OverlayRef } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { Injectable, inject } from '@angular/core';
import { FormSpinnerComponent } from '../../components/spinner/form-spinner.component';
import { FormService, FormSpinnerEvent } from '@alfresco/adf-core';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { FormSpinnerComponent } from '../../components/spinner/form-spinner.component';

@Injectable()
export class FormCloudSpinnerService {
private overlayRef?: OverlayRef;

private formService = inject(FormService);
private overlay = inject(Overlay);

private overlayRef?: OverlayRef;

initSpinnerHandling(onDestroy$: Observable<boolean>): void {
this.formService.toggleFormSpinner.pipe(takeUntil(onDestroy$)).subscribe((event: FormSpinnerEvent) => {
if (event?.payload.showSpinner) {
Expand Down

0 comments on commit 7594662

Please sign in to comment.