1+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2+ import { ProjectCardComponent , ProjectCardData } from './project-card.component' ;
3+
4+ describe ( 'ProjectCardComponent' , ( ) => {
5+ let component : ProjectCardComponent ;
6+ let fixture : ComponentFixture < ProjectCardComponent > ;
7+
8+ const sampleProject : ProjectCardData = {
9+ title : 'Cross-Project Dashboard' ,
10+ unitCode : 'CPD-F02' ,
11+ status : 'In progress' ,
12+ progressSummary : 'Reusable dashboard project-card component is being prepared.' ,
13+ description : 'This card summarises one project without hardcoding the dashboard data.' ,
14+ destinationUrl : '/projects/cpd-f02'
15+ } ;
16+
17+ beforeEach ( async ( ) => {
18+ await TestBed . configureTestingModule ( {
19+ declarations : [ ProjectCardComponent ]
20+ } ) . compileComponents ( ) ;
21+
22+ fixture = TestBed . createComponent ( ProjectCardComponent ) ;
23+ component = fixture . componentInstance ;
24+ component . project = sampleProject ;
25+ fixture . detectChanges ( ) ;
26+ } ) ;
27+
28+ it ( 'should create the project card component' , ( ) => {
29+ expect ( component ) . toBeTruthy ( ) ;
30+ } ) ;
31+
32+ it ( 'should display the supplied project details' , ( ) => {
33+ const text = fixture . nativeElement . textContent ;
34+
35+ expect ( text ) . toContain ( 'Cross-Project Dashboard' ) ;
36+ expect ( text ) . toContain ( 'CPD-F02' ) ;
37+ expect ( text ) . toContain ( 'In progress' ) ;
38+ expect ( text ) . toContain ( 'Reusable dashboard project-card component is being prepared.' ) ;
39+ } ) ;
40+
41+ it ( 'should provide an accessible project link' , ( ) => {
42+ const link : HTMLAnchorElement = fixture . nativeElement . querySelector ( 'a' ) ;
43+
44+ expect ( link ) . toBeTruthy ( ) ;
45+ expect ( link . getAttribute ( 'href' ) ) . toBe ( '/projects/cpd-f02' ) ;
46+ expect ( link . getAttribute ( 'aria-label' ) ) . toBe ( 'Open project details' ) ;
47+ } ) ;
48+
49+ it ( 'should handle missing optional fields' , ( ) => {
50+ component . project = {
51+ title : 'Sample Project' ,
52+ status : 'Completed' ,
53+ progressSummary : 'Core details are still displayed.' ,
54+ destinationUrl : '/projects/sample'
55+ } ;
56+
57+ fixture . detectChanges ( ) ;
58+
59+ const text = fixture . nativeElement . textContent ;
60+ expect ( text ) . toContain ( 'Sample Project' ) ;
61+ expect ( text ) . toContain ( 'Completed' ) ;
62+ expect ( text ) . toContain ( 'Core details are still displayed.' ) ;
63+ } ) ;
64+ } ) ;
0 commit comments