Skip to content

Commit

Permalink
Merged in coar-CST-11523 (pull request DSpace#1029)
Browse files Browse the repository at this point in the history
[CST-11523] footer component unit tests

Approved-by: Stefano Maffei
  • Loading branch information
alisaismailati authored and steph-ieffam committed Nov 20, 2023
2 parents 3a6d8f3 + 53ba509 commit 2386bb8
Showing 1 changed file with 63 additions and 12 deletions.
75 changes: 63 additions & 12 deletions src/app/footer/footer.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ... test imports
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, inject, TestBed,waitForAsync } from '@angular/core/testing';

import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';

Expand All @@ -9,6 +9,7 @@ import { By } from '@angular/platform-browser';

import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { StoreModule } from '@ngrx/store';
import { of } from 'rxjs';

// Load the implementations that should be tested
import { FooterComponent } from './footer.component';
Expand All @@ -18,22 +19,21 @@ import { storeModuleConfig } from '../app.reducer';
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
import { AuthorizationDataServiceStub } from '../shared/testing/authorization-service.stub';
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
import { of } from 'rxjs';
import { environment } from 'src/environments/environment';


let comp: FooterComponent;
let compAny: any;
let fixture: ComponentFixture<FooterComponent>;
let de: DebugElement;
let el: HTMLElement;

let notifyInfoServiceStub: any;
let notifyInfoService = {
isCoarConfigEnabled: () => of(true)
};

describe('Footer component', () => {

// waitForAsync beforeEach
beforeEach(waitForAsync(() => {
notifyInfoServiceStub = {
isCoarConfigEnabled: () => of(true)
};
return TestBed.configureTestingModule({
imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({
loader: {
Expand All @@ -45,7 +45,7 @@ describe('Footer component', () => {
providers: [
FooterComponent,
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
{ provide: NotifyInfoService, useValue: notifyInfoServiceStub },
{ provide: NotifyInfoService, useValue: notifyInfoService }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
Expand All @@ -54,9 +54,8 @@ describe('Footer component', () => {
// synchronous beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);

comp = fixture.componentInstance; // component test instance

comp = fixture.componentInstance;
compAny = comp as any;
// query for the title <p> by CSS element selector
de = fixture.debugElement.query(By.css('p'));
el = de.nativeElement;
Expand All @@ -67,4 +66,56 @@ describe('Footer component', () => {
expect(app).toBeTruthy();
}));


it('should set showPrivacyPolicy to the value of environment.info.enablePrivacyStatement', () => {
expect(comp.showPrivacyPolicy).toBe(environment.info.enablePrivacyStatement);
});

it('should set showEndUserAgreement to the value of environment.info.enableEndUserAgreement', () => {
expect(comp.showEndUserAgreement).toBe(environment.info.enableEndUserAgreement);
});

describe('showCookieSettings', () => {
it('should call cookies.showSettings() if cookies is defined', () => {
const cookies = jasmine.createSpyObj('cookies', ['showSettings']);
compAny.cookies = cookies;
comp.showCookieSettings();
expect(cookies.showSettings).toHaveBeenCalled();
});

it('should not call cookies.showSettings() if cookies is undefined', () => {
compAny.cookies = undefined;
expect(() => comp.showCookieSettings()).not.toThrow();
});

it('should return false', () => {
expect(comp.showCookieSettings()).toBeFalse();
});
});

describe('when coarLdnEnabled is true', () => {
beforeEach(() => {
spyOn(notifyInfoService, 'isCoarConfigEnabled').and.returnValue(of(true));
fixture.detectChanges();
});

it('should set coarLdnEnabled based on notifyInfoService', () => {
expect(comp.coarLdnEnabled).toBeTruthy();
// Check if COAR Notify section is rendered
const notifySection = fixture.debugElement.query(By.css('.notify-enabled'));
expect(notifySection).toBeTruthy();
});

it('should redirect to info/coar-notify-support', () => {
// Check if the link to the COAR Notify support page is present
const routerLink = fixture.debugElement.query(By.css('a[routerLink="info/coar-notify-support"].coar-notify-support-route'));
expect(routerLink).toBeTruthy();
});

it('should have an img tag with the class "n-coar" when coarLdnEnabled is true', fakeAsync(() => {
// Check if the img tag with the class "n-coar" is present
const imgTag = fixture.debugElement.query(By.css('.notify-enabled img.n-coar'));
expect(imgTag).toBeTruthy();
}));
});
});

0 comments on commit 2386bb8

Please sign in to comment.