Add scouthub-home-fe
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import Keycloak from 'keycloak-js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { OrganizationContextService } from '../core/organization-context.service';
|
||||
import { Home } from './home';
|
||||
|
||||
describe('Home', () => {
|
||||
let component: Home;
|
||||
let fixture: ComponentFixture<Home>;
|
||||
let organizationContext: { currentOrganizationName: Observable<string | null> };
|
||||
let keycloak: { logout: ReturnType<typeof vi.fn> };
|
||||
|
||||
async function setup(): Promise<void> {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Home],
|
||||
providers: [
|
||||
{ provide: OrganizationContextService, useValue: organizationContext },
|
||||
{ provide: Keycloak, useValue: keycloak }
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(Home);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
organizationContext = { currentOrganizationName: of('Agesci Milano 1') };
|
||||
keycloak = { logout: vi.fn() };
|
||||
});
|
||||
|
||||
it('si crea correttamente', async () => {
|
||||
await setup();
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('mostra il nome del gruppo scout corrente', async () => {
|
||||
await setup();
|
||||
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Agesci Milano 1');
|
||||
});
|
||||
|
||||
it('mostra il link verso l\'app Attività puntando a attivitaAppBaseUrl', async () => {
|
||||
await setup();
|
||||
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
const link = compiled.querySelector('a.servizio-card') as HTMLAnchorElement;
|
||||
expect(link).toBeTruthy();
|
||||
expect(link.getAttribute('href')).toBe(environment.attivitaAppBaseUrl);
|
||||
});
|
||||
|
||||
it('invoca il logout di Keycloak al click sul pulsante "Esci"', async () => {
|
||||
await setup();
|
||||
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
const button = compiled.querySelector('button') as HTMLButtonElement;
|
||||
button.click();
|
||||
|
||||
expect(keycloak.logout).toHaveBeenCalledWith({ redirectUri: window.location.origin + '/' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user