1- import { TestBed } from '@angular/core/testing' ;
1+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
22import { of } from 'rxjs' ;
33import { NodeStatusService } from '../../services/nodeStatusService' ;
44import { StudentDataService } from '../../services/studentDataService' ;
55import { VLEProjectService } from '../../vle/vleProjectService' ;
66import { GroupTabsComponent } from './group-tabs.component' ;
77import { NodeService } from '../../services/nodeService' ;
8+ import { HarnessLoader } from '@angular/cdk/testing' ;
9+ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
10+ import { MatTabGroupHarness } from '@angular/material/tabs/testing' ;
11+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
812
9- const group1 = { id : 'group1' } ;
10- const group2 = { id : 'group2' } ;
13+ const group1 = { id : 'group1' , title : 'Lesson 1' , startId : 'node1' } ;
14+ const group2 = { id : 'group2' , title : 'Lesson 2' , startId : 'node2' } ;
1115const node1 = { id : 'node1' } ;
1216
1317class MockNodeStatusService {
@@ -47,10 +51,14 @@ class MockStudentDataService {
4751}
4852
4953let component : GroupTabsComponent ;
54+ let fixture : ComponentFixture < GroupTabsComponent > ;
55+ let loader : HarnessLoader ;
5056let projectService : VLEProjectService ;
57+ let tabGroup : MatTabGroupHarness ;
5158describe ( 'GroupTabsComponent' , ( ) => {
52- beforeEach ( ( ) => {
59+ beforeEach ( async ( ) => {
5360 TestBed . configureTestingModule ( {
61+ imports : [ BrowserAnimationsModule ] ,
5462 providers : [
5563 GroupTabsComponent ,
5664 { provide : NodeService , useClass : MockNodeService } ,
@@ -59,32 +67,32 @@ describe('GroupTabsComponent', () => {
5967 { provide : StudentDataService , useClass : MockStudentDataService }
6068 ]
6169 } ) ;
62- component = TestBed . inject ( GroupTabsComponent ) ;
70+ fixture = TestBed . createComponent ( GroupTabsComponent ) ;
71+ component = fixture . componentInstance ;
6372 projectService = TestBed . inject ( VLEProjectService ) ;
73+ fixture . detectChanges ( ) ;
74+ loader = TestbedHarnessEnvironment . loader ( fixture ) ;
75+ tabGroup = await loader . getHarness ( MatTabGroupHarness ) ;
6476 } ) ;
6577 ngOnInit ( ) ;
6678 goToGroupTab ( ) ;
6779} ) ;
6880
6981function ngOnInit ( ) {
7082 describe ( 'ngOnInit()' , ( ) => {
71- it ( 'should initialize class variables' , ( ) => {
72- component . ngOnInit ( ) ;
73- expect ( component . groupNodes . length ) . toEqual ( 2 ) ;
74- expect ( component . selectedTabIndex ) . toEqual ( 0 ) ;
83+ it ( 'should initialize class variables' , async ( ) => {
84+ expect ( ( await tabGroup . getTabs ( ) ) . length ) . toEqual ( 2 ) ;
85+ expect ( await ( await tabGroup . getSelectedTab ( ) ) . getLabel ( ) ) . toEqual ( 'Lesson 1' ) ;
7586 } ) ;
7687 } ) ;
7788}
7889
7990function goToGroupTab ( ) {
8091 describe ( 'goToGroupTab()' , ( ) => {
81- it ( "should call function to set new group's startNodeId" , ( ) => {
82- component . groupNodes = [
83- { id : 'group1' , disabled : false , startId : 'node1' , title : 'Lesson 1' }
84- ] ;
92+ it ( "should call function to set new group's startNodeId" , async ( ) => {
8593 const spy = spyOn ( TestBed . inject ( NodeService ) , 'setCurrentNode' ) ;
86- component . goToGroupTab ( 0 ) ;
87- expect ( spy ) . toHaveBeenCalledWith ( 'node1 ' ) ;
94+ await ( await tabGroup . getTabs ( ) ) [ 1 ] . select ( ) ;
95+ expect ( spy ) . toHaveBeenCalledWith ( 'node2 ' ) ;
8896 } ) ;
8997 } ) ;
9098}
0 commit comments