Skip to content

Commit 9ebc326

Browse files
refactor(DialogGuidanceStudentComponent): Convert to standalone (#2114)
1 parent 7e52ea7 commit 9ebc326

File tree

5 files changed

+79
-111
lines changed

5 files changed

+79
-111
lines changed

src/assets/wise5/components/component/component-student.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { StudentAssetsDialogModule } from '../../vle/studentAsset/student-assets
77
import { AnimationStudentModule } from '../animation/animation-student/animation-student.module';
88
import { AudioOscillatorStudentModule } from '../audioOscillator/audio-oscillator-student/audio-oscillator.module';
99
import { ConceptMapStudentModule } from '../conceptMap/concept-map-student/concept-map-student.module';
10-
import { DialogGuidanceStudentModule } from '../dialogGuidance/dialogGuidanceStudentModule';
1110
import { DiscussionStudentModule } from '../discussion/discussion-student/discussion-student.module';
1211
import { DrawStudentModule } from '../draw/draw-student/draw-student-module';
1312
import { EmbeddedStudentModule } from '../embedded/embedded-student/embedded-student.module';
@@ -26,6 +25,7 @@ import { ComponentComponent } from './component.component';
2625
import { AiChatStudentModule } from '../aiChat/ai-chat-student/ai-chat-student.module';
2726
import { HelpIconComponent } from '../../themes/default/themeComponents/helpIcon/help-icon.component';
2827
import { MultipleChoiceStudentComponent } from '../multipleChoice/multiple-choice-student/multiple-choice-student.component';
28+
import { DialogGuidanceStudentComponent } from '../dialogGuidance/dialog-guidance-student/dialog-guidance-student.component';
2929

3030
@NgModule({
3131
imports: [
@@ -35,7 +35,7 @@ import { MultipleChoiceStudentComponent } from '../multipleChoice/multiple-choic
3535
CommonModule,
3636
ComponentComponent,
3737
ConceptMapStudentModule,
38-
DialogGuidanceStudentModule,
38+
DialogGuidanceStudentComponent,
3939
DiscussionStudentModule,
4040
DrawStudentModule,
4141
EmbeddedStudentModule,
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
<computer-avatar-selector
2-
*ngIf="computerAvatarSelectorVisible"
3-
[computerAvatarSettings]="componentContent.computerAvatarSettings"
4-
(chooseAvatarEvent)="selectComputerAvatar($event)"
5-
/>
6-
<mat-card appearance="outlined" *ngIf="!computerAvatarSelectorVisible" class="mat-elevation-z2">
7-
<component-header [component]="component"></component-header>
8-
<dialog-responses
9-
[responses]="responses"
10-
[isWaitingForComputerResponse]="isWaitingForComputerResponse"
11-
[computerAvatar]="computerAvatar"
12-
>
13-
</dialog-responses>
14-
<chat-input
15-
*ngIf="studentCanRespond"
16-
[submitDisabled]="isWaitingForComputerResponse"
17-
(submitEvent)="submitStudentResponse($event)"
18-
></chat-input>
19-
</mat-card>
1+
@if (computerAvatarSelectorVisible) {
2+
<computer-avatar-selector
3+
[computerAvatarSettings]="componentContent.computerAvatarSettings"
4+
(chooseAvatarEvent)="selectComputerAvatar($event)"
5+
/>
6+
} @else {
7+
<mat-card appearance="outlined" class="mat-elevation-z2">
8+
<component-header [component]="component" />
9+
<dialog-responses
10+
[responses]="responses"
11+
[isWaitingForComputerResponse]="isWaitingForComputerResponse"
12+
[computerAvatar]="computerAvatar"
13+
/>
14+
@if (studentCanRespond) {
15+
<chat-input
16+
[submitDisabled]="isWaitingForComputerResponse"
17+
(submitEvent)="submitStudentResponse($event)"
18+
/>
19+
}
20+
</mat-card>
21+
}

src/assets/wise5/components/dialogGuidance/dialog-guidance-student/dialog-guidance-student.component.spec.ts

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { provideHttpClientTesting } from '@angular/common/http/testing';
21
import { 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';
92
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
103
import { StudentTeacherCommonServicesModule } from '../../../../../app/student-teacher-common-services.module';
114
import { ComputerAvatar } from '../../../common/computer-avatar/ComputerAvatar';
12-
import { ComponentHeaderComponent } from '../../../directives/component-header/component-header.component';
135
import { ComputerAvatarService } from '../../../services/computerAvatarService';
146
import { DialogGuidanceFeedbackService } from '../../../services/dialogGuidanceFeedbackService';
157
import { ProjectService } from '../../../services/projectService';
@@ -19,57 +11,24 @@ import { ComputerDialogResponseMultipleScores } from '../ComputerDialogResponseM
1911
import { ComputerDialogResponseSingleScore } from '../ComputerDialogResponseSingleScore';
2012
import { CRaterResponse } from '../../common/cRater/CRaterResponse';
2113
import { CRaterScore } from '../../common/cRater/CRaterScore';
22-
import { DialogResponsesComponent } from '../dialog-responses/dialog-responses.component';
2314
import { DialogGuidanceService } from '../dialogGuidanceService';
2415
import { DialogGuidanceStudentComponent } from './dialog-guidance-student.component';
2516
import { DialogGuidanceComponent } from '../DialogGuidanceComponent';
2617
import { RawCRaterResponse } from '../../common/cRater/RawCRaterResponse';
27-
import { NO_ERRORS_SCHEMA } from '@angular/core';
28-
import { ChatInputComponent } from '../../../common/chat-input/chat-input.component';
2918
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
3019

3120
let component: DialogGuidanceStudentComponent;
3221
let fixture: ComponentFixture<DialogGuidanceStudentComponent>;
3322
const 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-
5023
describe('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+
212186
function simulateSubmit(component: DialogGuidanceStudentComponent): void {
213187
const response = createDummyScoringResponse();
214188
component.setIsSubmitDirty(true);

src/assets/wise5/components/dialogGuidance/dialog-guidance-student/dialog-guidance-student.component.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,36 @@ import { RawCRaterResponse } from '../../common/cRater/RawCRaterResponse';
2929
import { ConstraintService } from '../../../services/constraintService';
3030
import { applyMixins } from '../../../common/apply-mixins';
3131
import { ComputerAvatarInitializer } from '../../../common/computer-avatar/computer-avatar-initializer';
32+
import { ComputerAvatarSelectorComponent } from '../../../vle/computer-avatar-selector/computer-avatar-selector.component';
33+
import { MatCardModule } from '@angular/material/card';
34+
import { ComponentHeaderComponent } from '../../../directives/component-header/component-header.component';
35+
import { DialogResponsesComponent } from '../dialog-responses/dialog-responses.component';
36+
import { ChatInputComponent } from '../../../common/chat-input/chat-input.component';
37+
import { CommonModule } from '@angular/common';
3238

3339
@Component({
34-
selector: 'dialog-guidance-student',
35-
templateUrl: './dialog-guidance-student.component.html',
36-
styleUrls: ['./dialog-guidance-student.component.scss'],
37-
standalone: false
40+
imports: [
41+
ChatInputComponent,
42+
CommonModule,
43+
ComponentHeaderComponent,
44+
ComputerAvatarSelectorComponent,
45+
DialogResponsesComponent,
46+
MatCardModule
47+
],
48+
providers: [DialogGuidanceFeedbackService],
49+
selector: 'dialog-guidance-student',
50+
styleUrl: './dialog-guidance-student.component.scss',
51+
templateUrl: './dialog-guidance-student.component.html'
3852
})
3953
export class DialogGuidanceStudentComponent extends ComponentStudent {
4054
component: DialogGuidanceComponent;
41-
computerAvatar: ComputerAvatar;
55+
protected computerAvatar: ComputerAvatar;
4256
protected computerAvatarSelectorVisible: boolean = false;
43-
cRaterTimeout: number = 40000;
44-
feedbackRuleEvaluator: FeedbackRuleEvaluator<CRaterResponse[]>;
45-
isWaitingForComputerResponse: boolean = false;
46-
responses: DialogResponse[] = [];
47-
studentCanRespond: boolean = true;
57+
private cRaterTimeout: number = 40000;
58+
private feedbackRuleEvaluator: FeedbackRuleEvaluator<CRaterResponse[]>;
59+
protected isWaitingForComputerResponse: boolean = false;
60+
protected responses: DialogResponse[] = [];
61+
protected studentCanRespond: boolean = true;
4862
workgroupId: number;
4963

5064
constructor(
@@ -126,14 +140,14 @@ export class DialogGuidanceStudentComponent extends ComponentStudent {
126140
this.cRaterService
127141
.makeCRaterScoringRequest(this.component.getItemId(), new Date().getTime(), studentResponse)
128142
.pipe(timeout(this.cRaterTimeout))
129-
.subscribe(
130-
(response: any) => {
143+
.subscribe({
144+
next: (response: any) => {
131145
this.cRaterSuccessResponse(response.responses);
132146
},
133-
() => {
147+
error: () => {
134148
this.cRaterErrorResponse();
135149
}
136-
);
150+
});
137151
}
138152

139153
private showWaitingForComputerResponse(): void {

src/assets/wise5/components/dialogGuidance/dialogGuidanceStudentModule.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)