1- import { provideHttpClientTesting } from '@angular/common/http/testing' ;
21import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3- import { FormsModule } from '@angular/forms' ;
4- import { MatCardModule } from '@angular/material/card' ;
5- import { MatDialogModule } from '@angular/material/dialog' ;
6- import { MatFormFieldModule } from '@angular/material/form-field' ;
7- import { MatIconModule } from '@angular/material/icon' ;
8- import { MatInputModule } from '@angular/material/input' ;
92import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
103import { StudentTeacherCommonServicesModule } from '../../../../../app/student-teacher-common-services.module' ;
114import { ComputerAvatar } from '../../../common/computer-avatar/ComputerAvatar' ;
12- import { ComponentHeaderComponent } from '../../../directives/component-header/component-header.component' ;
135import { ComputerAvatarService } from '../../../services/computerAvatarService' ;
146import { DialogGuidanceFeedbackService } from '../../../services/dialogGuidanceFeedbackService' ;
157import { ProjectService } from '../../../services/projectService' ;
@@ -19,57 +11,24 @@ import { ComputerDialogResponseMultipleScores } from '../ComputerDialogResponseM
1911import { ComputerDialogResponseSingleScore } from '../ComputerDialogResponseSingleScore' ;
2012import { CRaterResponse } from '../../common/cRater/CRaterResponse' ;
2113import { CRaterScore } from '../../common/cRater/CRaterScore' ;
22- import { DialogResponsesComponent } from '../dialog-responses/dialog-responses.component' ;
2314import { DialogGuidanceService } from '../dialogGuidanceService' ;
2415import { DialogGuidanceStudentComponent } from './dialog-guidance-student.component' ;
2516import { DialogGuidanceComponent } from '../DialogGuidanceComponent' ;
2617import { RawCRaterResponse } from '../../common/cRater/RawCRaterResponse' ;
27- import { NO_ERRORS_SCHEMA } from '@angular/core' ;
28- import { ChatInputComponent } from '../../../common/chat-input/chat-input.component' ;
2918import { provideHttpClient , withInterceptorsFromDi } from '@angular/common/http' ;
3019
3120let component : DialogGuidanceStudentComponent ;
3221let fixture : ComponentFixture < DialogGuidanceStudentComponent > ;
3322const robotAvatar = new ComputerAvatar ( 'robot' , 'Robot' , 'robot.png' ) ;
34-
35- function initializeComponent ( isComputerAvatarEnabled : boolean ) : void {
36- fixture = TestBed . createComponent ( DialogGuidanceStudentComponent ) ;
37- component = fixture . componentInstance ;
38- component . component = createDialogGuidanceComponent ( isComputerAvatarEnabled ) ;
39- spyOn ( component , 'subscribeToSubscriptions' ) . and . callFake ( ( ) => { } ) ;
40- spyOn ( component , 'isNotebookEnabled' ) . and . returnValue ( false ) ;
41- fixture . detectChanges ( ) ;
42- }
43-
44- function createDialogGuidanceComponent ( isComputerAvatarEnabled : boolean ) : DialogGuidanceComponent {
45- const componentContent = TestBed . inject ( DialogGuidanceService ) . createComponent ( ) ;
46- componentContent . isComputerAvatarEnabled = isComputerAvatarEnabled ;
47- return new DialogGuidanceComponent ( componentContent , null ) ;
48- }
49-
5023describe ( 'DialogGuidanceStudentComponent' , ( ) => {
5124 beforeEach ( async ( ) => {
5225 await TestBed . configureTestingModule ( {
53- declarations : [ DialogGuidanceStudentComponent ] ,
54- schemas : [ NO_ERRORS_SCHEMA ] ,
5526 imports : [
5627 BrowserAnimationsModule ,
57- ChatInputComponent ,
58- ComponentHeaderComponent ,
59- DialogResponsesComponent ,
60- FormsModule ,
61- MatCardModule ,
62- MatDialogModule ,
63- MatFormFieldModule ,
64- MatIconModule ,
65- MatInputModule ,
28+ DialogGuidanceStudentComponent ,
6629 StudentTeacherCommonServicesModule
6730 ] ,
68- providers : [
69- DialogGuidanceFeedbackService ,
70- provideHttpClient ( withInterceptorsFromDi ( ) ) ,
71- provideHttpClientTesting ( )
72- ]
31+ providers : [ DialogGuidanceFeedbackService , provideHttpClient ( withInterceptorsFromDi ( ) ) ]
7332 } ) . compileComponents ( ) ;
7433 } ) ;
7534
@@ -101,19 +60,19 @@ describe('DialogGuidanceStudentComponent', () => {
10160 ) ;
10261 component . setIsSubmitDirty ( true ) ;
10362 const response = createDummyScoringResponse ( ) ;
104- expect ( component . responses . length ) . toEqual ( 0 ) ;
63+ expect ( component [ ' responses' ] . length ) . toEqual ( 0 ) ;
10564 component . cRaterSuccessResponse ( response ) ;
10665 expect ( broadcastComponentSubmitTriggeredSpy ) . toHaveBeenCalled ( ) ;
107- expect ( component . responses . length ) . toEqual ( 1 ) ;
66+ expect ( component [ ' responses' ] . length ) . toEqual ( 1 ) ;
10867 } ) ;
10968
11069 it ( 'should disable submit button after using all submits' , ( ) => {
11170 component . componentContent . maxSubmitCount = 2 ;
112- expect ( component . studentCanRespond ) . toEqual ( true ) ;
71+ expect ( component [ ' studentCanRespond' ] ) . toEqual ( true ) ;
11372 simulateSubmit ( component ) ;
114- expect ( component . studentCanRespond ) . toEqual ( true ) ;
73+ expect ( component [ ' studentCanRespond' ] ) . toEqual ( true ) ;
11574 simulateSubmit ( component ) ;
116- expect ( component . studentCanRespond ) . toEqual ( false ) ;
75+ expect ( component [ ' studentCanRespond' ] ) . toEqual ( false ) ;
11776 } ) ;
11877
11978 it ( 'should handle crater error response' , ( ) => {
@@ -129,7 +88,7 @@ describe('DialogGuidanceStudentComponent', () => {
12988 it ( 'should initialize computer avatar to default computer avatar' , ( ) => {
13089 initializeComponent ( false ) ;
13190 expectComputerAvatarSelectorNotToBeShown ( component ) ;
132- expect ( component . computerAvatar ) . not . toBeNull ( ) ;
91+ expect ( component [ ' computerAvatar' ] ) . not . toBeNull ( ) ;
13392 } ) ;
13493
13594 it ( `should initialize computer avatar when the student has not previously chosen a computer
@@ -183,7 +142,7 @@ describe('DialogGuidanceStudentComponent', () => {
183142
184143 it ( 'should select computer avatar' , ( ) => {
185144 component . selectComputerAvatar ( robotAvatar ) ;
186- expect ( component . computerAvatar ) . toEqual ( robotAvatar ) ;
145+ expect ( component [ ' computerAvatar' ] ) . toEqual ( robotAvatar ) ;
187146 expectComputerAvatarSelectorNotToBeShown ( component ) ;
188147 } ) ;
189148
@@ -196,19 +155,34 @@ describe('DialogGuidanceStudentComponent', () => {
196155 const defaultComputerAvatar = computerAvatarService . getDefaultAvatar ( ) ;
197156 spyOn ( computerAvatarService , 'getAvatar' ) . and . returnValue ( defaultComputerAvatar ) ;
198157 component . initializeComputerAvatar ( ) ;
199- expect ( component . computerAvatar ) . toEqual ( defaultComputerAvatar ) ;
158+ expect ( component [ ' computerAvatar' ] ) . toEqual ( defaultComputerAvatar ) ;
200159 } ) ;
201160
202161 it ( 'should select computer avatar when there is a computer avatar initial response' , ( ) => {
203162 const text = 'Hi there, who lives in a pineapple under sea?' ;
204163 component . componentContent . computerAvatarSettings . initialResponse = text ;
205- expect ( component . responses . length ) . toEqual ( 0 ) ;
164+ expect ( component [ ' responses' ] . length ) . toEqual ( 0 ) ;
206165 component . selectComputerAvatar ( robotAvatar ) ;
207- expect ( component . responses . length ) . toEqual ( 1 ) ;
208- expect ( component . responses [ 0 ] . text ) . toEqual ( text ) ;
166+ expect ( component [ ' responses' ] . length ) . toEqual ( 1 ) ;
167+ expect ( component [ ' responses' ] [ 0 ] . text ) . toEqual ( text ) ;
209168 } ) ;
210169} ) ;
211170
171+ function initializeComponent ( isComputerAvatarEnabled : boolean ) : void {
172+ fixture = TestBed . createComponent ( DialogGuidanceStudentComponent ) ;
173+ component = fixture . componentInstance ;
174+ component . component = createDialogGuidanceComponent ( isComputerAvatarEnabled ) ;
175+ spyOn ( component , 'subscribeToSubscriptions' ) . and . callFake ( ( ) => { } ) ;
176+ spyOn ( component , 'isNotebookEnabled' ) . and . returnValue ( false ) ;
177+ fixture . detectChanges ( ) ;
178+ }
179+
180+ function createDialogGuidanceComponent ( isComputerAvatarEnabled : boolean ) : DialogGuidanceComponent {
181+ const componentContent = TestBed . inject ( DialogGuidanceService ) . createComponent ( ) ;
182+ componentContent . isComputerAvatarEnabled = isComputerAvatarEnabled ;
183+ return new DialogGuidanceComponent ( componentContent , null ) ;
184+ }
185+
212186function simulateSubmit ( component : DialogGuidanceStudentComponent ) : void {
213187 const response = createDummyScoringResponse ( ) ;
214188 component . setIsSubmitDirty ( true ) ;
0 commit comments