Ajoute projet et migration milestone
Signed-off-by: Gato <cedric@goutailler-olivier.fr>
This commit is contained in:
+37
-23
@@ -3,26 +3,35 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { vi } from 'vitest';
|
||||
import { KeycloakService } from '../auth/keycloak.service';
|
||||
import { ProjectContextService } from '../projects/project-context.service';
|
||||
import { ProjectEntity } from '../projects/projects.store';
|
||||
import { Menu } from './menu';
|
||||
|
||||
describe('Menu', () => {
|
||||
let component: Menu;
|
||||
let fixture: ComponentFixture<Menu>;
|
||||
const keycloakMock = {
|
||||
isAuthenticated: signal(false),
|
||||
username: signal<string | undefined>(undefined),
|
||||
logout: vi.fn(),
|
||||
login: vi.fn(),
|
||||
};
|
||||
|
||||
const isAuthenticated = signal(false);
|
||||
const username = signal<string | undefined>(undefined);
|
||||
const projectId = signal<number | null>(null);
|
||||
const project = signal<ProjectEntity | null>(null);
|
||||
|
||||
const keycloakMock = { isAuthenticated, username, logout: vi.fn(), login: vi.fn() };
|
||||
const projectContextMock = { projectId, project };
|
||||
|
||||
beforeEach(async () => {
|
||||
isAuthenticated.set(false);
|
||||
projectId.set(null);
|
||||
project.set(null);
|
||||
keycloakMock.logout = vi.fn();
|
||||
keycloakMock.login = vi.fn();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Menu],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: KeycloakService, useValue: keycloakMock },
|
||||
{ provide: ProjectContextService, useValue: projectContextMock },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -35,28 +44,33 @@ describe('Menu', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should have five menu items', () => {
|
||||
const items = (component as any).menuItems as { label: string; path: string }[];
|
||||
expect(items.length).toBe(6);
|
||||
});
|
||||
describe('projectMenuItems', () => {
|
||||
it('returns empty array when no project is selected', () => {
|
||||
expect((component as any).projectMenuItems()).toEqual([]);
|
||||
});
|
||||
|
||||
it('should contain Issues link', () => {
|
||||
const items = (component as any).menuItems as { label: string; path: string }[];
|
||||
expect(items.some((i) => i.path === '/issues')).toBe(true);
|
||||
});
|
||||
|
||||
it('should contain Milestones link', () => {
|
||||
const items = (component as any).menuItems as { label: string; path: string }[];
|
||||
expect(items.some((i) => i.path === '/milestones')).toBe(true);
|
||||
});
|
||||
|
||||
it('should contain Dashboard link', () => {
|
||||
const items = (component as any).menuItems as { label: string; path: string }[];
|
||||
expect(items.some((i) => i.path === '/dashboard')).toBe(true);
|
||||
it('returns dashboard, issues, milestones and statuts items when a project is selected', () => {
|
||||
projectId.set(5);
|
||||
const items = (component as any).projectMenuItems();
|
||||
expect(items.length).toBe(4);
|
||||
expect(items[0].path).toBe('/projects/5/dashboard');
|
||||
expect(items[1].path).toBe('/projects/5/issues');
|
||||
expect(items[2].path).toBe('/projects/5/milestones');
|
||||
expect(items[3].path).toBe('/projects/5/statuses');
|
||||
});
|
||||
});
|
||||
|
||||
it('logout calls keycloak.logout()', () => {
|
||||
(component as any).logout();
|
||||
expect(keycloakMock.logout).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows Projets link when authenticated', async () => {
|
||||
isAuthenticated.set(true);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const links = fixture.nativeElement.querySelectorAll('a.sidebar-link');
|
||||
const hrefs = Array.from(links).map((l: any) => l.getAttribute('href') ?? '');
|
||||
expect(hrefs.some((h) => h === '/projects')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user