11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2-
32import { PokedexComponent } from './pokedex.component' ;
3+ import { Component } from '@angular/core' ;
4+ import { RouterTestingModule } from '@angular/router/testing' ;
5+ import { MatDialog } from '@angular/material/dialog' ;
6+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
7+ import { of } from 'rxjs' ;
8+ import { vi } from 'vitest' ;
9+
10+ // Create Mock Components
11+ @Component ( {
12+ selector : 'app-pokemon-list' ,
13+ standalone : true ,
14+ template : '<div>Mock Pokemon List</div>' ,
15+ } )
16+ class MockPokemonListComponent { }
17+
18+ @Component ( {
19+ selector : 'app-form' ,
20+ standalone : true ,
21+ template : '<div>Mock Form</div>' ,
22+ } )
23+ class MockFormComponent { }
24+
25+ @Component ( {
26+ selector : 'app-banner-grid' ,
27+ standalone : true ,
28+ template : '<div>Mock Banner Grid</div>' ,
29+ } )
30+ class MockBannerGridComponent { }
431
532describe ( 'PokedexComponent' , ( ) => {
633 let component : PokedexComponent ;
734 let fixture : ComponentFixture < PokedexComponent > ;
35+ let mockMatDialog : { open : ReturnType < typeof vi . fn > } ;
836
937 beforeEach ( async ( ) => {
38+ mockMatDialog = {
39+ open : vi . fn ( ) . mockReturnValue ( {
40+ afterClosed : ( ) => of ( null ) ,
41+ } ) ,
42+ } ;
43+
1044 await TestBed . configureTestingModule ( {
11- imports : [ PokedexComponent ] ,
12- } ) . compileComponents ( ) ;
45+ imports : [ PokedexComponent , RouterTestingModule , BrowserAnimationsModule ] ,
46+ providers : [ { provide : MatDialog , useValue : mockMatDialog } ] ,
47+ } )
48+ . overrideComponent ( PokedexComponent , {
49+ set : {
50+ imports : [
51+ MockPokemonListComponent ,
52+ MockFormComponent ,
53+ MockBannerGridComponent ,
54+ ] ,
55+ } ,
56+ } )
57+ . compileComponents ( ) ;
1358
1459 fixture = TestBed . createComponent ( PokedexComponent ) ;
1560 component = fixture . componentInstance ;
@@ -19,4 +64,15 @@ describe('PokedexComponent', () => {
1964 it ( 'should create' , ( ) => {
2065 expect ( component ) . toBeTruthy ( ) ;
2166 } ) ;
67+
68+ it ( 'should set hideForm to false when openForm is called' , ( ) => {
69+ expect ( component . hideForm ) . toBe ( true ) ;
70+ component . openForm ( ) ;
71+ expect ( component . hideForm ) . toBe ( false ) ;
72+ } ) ;
73+
74+ it ( 'should open dialog when openDialog is called' , ( ) => {
75+ component . openDialog ( ) ;
76+ expect ( mockMatDialog . open ) . toHaveBeenCalled ( ) ;
77+ } ) ;
2278} ) ;
0 commit comments