Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/app/services/cRaterPingService.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { HttpClient } from '@angular/common/http';
import { CRaterPingService } from '../../assets/wise5/services/cRaterPingService';
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { MockProvider } from 'ng-mocks';
import { of } from 'rxjs';

let cRaterPingService: CRaterPingService;
let httpClientMock: jasmine.Spy;
const testId = 'berkeley_test_id';

describe('CRaterPingService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [MockProvider(HttpClient), CRaterPingService]
});
cRaterPingService = TestBed.inject(CRaterPingService);
httpClientMock = spyOn(TestBed.inject(HttpClient), 'post').and.returnValue(of({}));
});

it('should send ping to endpoint when startPinging() is called', () => {
cRaterPingService.startPinging(testId);
expect(httpClientMock).toHaveBeenCalledTimes(1);
});

it('should wait before sending another ping', fakeAsync(() => {
cRaterPingService.startPinging(testId);
tick(294999);
expect(httpClientMock).toHaveBeenCalledTimes(1);
tick(2);
expect(httpClientMock).toHaveBeenCalledTimes(2);
}));

it('should stop trying to ping when stopPinging()', fakeAsync(() => {
cRaterPingService.startPinging(testId);
expect(httpClientMock).toHaveBeenCalledTimes(1);
cRaterPingService.stopPinging(testId);
tick(500000);
expect(httpClientMock).toHaveBeenCalledTimes(1);
}));
});
96 changes: 49 additions & 47 deletions src/app/student-teacher-common-services.module.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
import { NgModule } from '@angular/core';
import { AchievementService } from '../assets/wise5/services/achievementService';
import { AiChatService } from '../assets/wise5/components/aiChat/aiChatService';
import { AnimationService } from '../assets/wise5/components/animation/animationService';
import { AnnotationService } from '../assets/wise5/services/annotationService';
import { AudioOscillatorService } from '../assets/wise5/components/audioOscillator/audioOscillatorService';
import { AudioRecorderService } from '../assets/wise5/services/audioRecorderService';
import { BranchService } from '../assets/wise5/services/branchService';
import { ClassroomStatusService } from '../assets/wise5/services/classroomStatusService';
import { ClickToSnipImageService } from '../assets/wise5/services/clickToSnipImageService';
import { CompletionService } from '../assets/wise5/services/completionService';
import { ComponentService } from '../assets/wise5/components/componentService';
import { ComponentServiceLookupService } from '../assets/wise5/services/componentServiceLookupService';
import { ComponentTypeService } from '../assets/wise5/services/componentTypeService';
import { ComputerAvatarService } from '../assets/wise5/services/computerAvatarService';
import { ConceptMapService } from '../assets/wise5/components/conceptMap/conceptMapService';
import { ConfigService } from '../assets/wise5/services/configService';
import { ProjectService } from '../assets/wise5/services/projectService';
import { ProjectLibraryService } from '../assets/wise5/services/projectLibraryService';
import { VLEProjectService } from '../assets/wise5/vle/vleProjectService';
import { ConstraintService } from '../assets/wise5/services/constraintService';
import { CRaterService } from '../assets/wise5/services/cRaterService';
import { SessionService } from '../assets/wise5/services/sessionService';
import { StudentAssetService } from '../assets/wise5/services/studentAssetService';
import { TagService } from '../assets/wise5/services/tagService';
import { AudioRecorderService } from '../assets/wise5/services/audioRecorderService';
import { AnnotationService } from '../assets/wise5/services/annotationService';
import { StudentWebSocketService } from '../assets/wise5/services/studentWebSocketService';
import { StudentDataService } from '../assets/wise5/services/studentDataService';
import { AchievementService } from '../assets/wise5/services/achievementService';
import { SummaryService } from '../assets/wise5/components/summary/summaryService';
import { TableService } from '../assets/wise5/components/table/tableService';
import { NotebookService } from '../assets/wise5/services/notebookService';
import { NotificationService } from '../assets/wise5/services/notificationService';
import { OutsideURLService } from '../assets/wise5/components/outsideURL/outsideURLService';
import { MatchService } from '../assets/wise5/components/match/matchService';
import { MultipleChoiceService } from '../assets/wise5/components/multipleChoice/multipleChoiceService';
import { OpenResponseService } from '../assets/wise5/components/openResponse/openResponseService';
import { NodeService } from '../assets/wise5/services/nodeService';
import { DialogGuidanceService } from '../assets/wise5/components/dialogGuidance/dialogGuidanceService';
import { DiscussionService } from '../assets/wise5/components/discussion/discussionService';
import { DrawService } from '../assets/wise5/components/draw/drawService';
import { EmbeddedService } from '../assets/wise5/components/embedded/embeddedService';
import { GraphService } from '../assets/wise5/components/graph/graphService';
import { HTMLService } from '../assets/wise5/components/html/htmlService';
import { LabelService } from '../assets/wise5/components/label/labelService';
import { AnimationService } from '../assets/wise5/components/animation/animationService';
import { AudioOscillatorService } from '../assets/wise5/components/audioOscillator/audioOscillatorService';
import { ConceptMapService } from '../assets/wise5/components/conceptMap/conceptMapService';
import { GraphService } from '../assets/wise5/components/graph/graphService';
import { ComponentService } from '../assets/wise5/components/componentService';
import { WiseLinkService } from './services/wiseLinkService';
import { DialogGuidanceService } from '../assets/wise5/components/dialogGuidance/dialogGuidanceService';
import { PeerChatService } from '../assets/wise5/components/peerChat/peerChatService';
import { ShowMyWorkService } from '../assets/wise5/components/showMyWork/showMyWorkService';
import { ShowGroupWorkService } from '../assets/wise5/components/showGroupWork/showGroupWorkService';
import { ComputerAvatarService } from '../assets/wise5/services/computerAvatarService';
import { StudentStatusService } from '../assets/wise5/services/studentStatusService';
import { MatchService } from '../assets/wise5/components/match/matchService';
import { MultipleChoiceService } from '../assets/wise5/components/multipleChoice/multipleChoiceService';
import { NgModule } from '@angular/core';
import { NodeProgressService } from '../assets/wise5/services/nodeProgressService';
import { NodeService } from '../assets/wise5/services/nodeService';
import { NodeStatusService } from '../assets/wise5/services/nodeStatusService';
import { NotebookService } from '../assets/wise5/services/notebookService';
import { NotificationService } from '../assets/wise5/services/notificationService';
import { OpenResponseCompletionCriteriaService } from '../assets/wise5/components/openResponse/openResponseCompletionCriteriaService';
import { ComponentServiceLookupService } from '../assets/wise5/services/componentServiceLookupService';
import { ComponentTypeService } from '../assets/wise5/services/componentTypeService';
import { BranchService } from '../assets/wise5/services/branchService';
import { OpenResponseService } from '../assets/wise5/components/openResponse/openResponseService';
import { OutsideURLService } from '../assets/wise5/components/outsideURL/outsideURLService';
import { PathService } from '../assets/wise5/services/pathService';
import { TabulatorDataService } from '../assets/wise5/components/table/tabulatorDataService';
import { StompService } from '../assets/wise5/services/stompService';
import { ClickToSnipImageService } from '../assets/wise5/services/clickToSnipImageService';
import { StudentPeerGroupService } from '../assets/wise5/services/studentPeerGroupService';
import { ConstraintService } from '../assets/wise5/services/constraintService';
import { NodeStatusService } from '../assets/wise5/services/nodeStatusService';
import { PeerChatService } from '../assets/wise5/components/peerChat/peerChatService';
import { PeerGroupService } from '../assets/wise5/services/peerGroupService';
import { NodeProgressService } from '../assets/wise5/services/nodeProgressService';
import { CompletionService } from '../assets/wise5/services/completionService';
import { CRaterPingService } from '../assets/wise5/services/cRaterPingService';
import { ProjectLibraryService } from '../assets/wise5/services/projectLibraryService';
import { ProjectService } from '../assets/wise5/services/projectService';
import { SessionService } from '../assets/wise5/services/sessionService';
import { ShowGroupWorkService } from '../assets/wise5/components/showGroupWork/showGroupWorkService';
import { ShowMyWorkService } from '../assets/wise5/components/showMyWork/showMyWorkService';
import { StompService } from '../assets/wise5/services/stompService';
import { StudentAssetService } from '../assets/wise5/services/studentAssetService';
import { StudentDataService } from '../assets/wise5/services/studentDataService';
import { StudentNodeService } from '../assets/wise5/services/studentNodeService';
import { StudentPeerGroupService } from '../assets/wise5/services/studentPeerGroupService';
import { StudentProjectTranslationService } from '../assets/wise5/services/studentProjectTranslationService';
import { AiChatService } from '../assets/wise5/components/aiChat/aiChatService';
import { TeacherNodeService } from '../assets/wise5/services/teacherNodeService';
import { StudentStatusService } from '../assets/wise5/services/studentStatusService';
import { StudentWebSocketService } from '../assets/wise5/services/studentWebSocketService';
import { SummaryService } from '../assets/wise5/components/summary/summaryService';
import { TableService } from '../assets/wise5/components/table/tableService';
import { TabulatorDataService } from '../assets/wise5/components/table/tabulatorDataService';
import { TagService } from '../assets/wise5/services/tagService';
import { TeacherDataService } from '../assets/wise5/services/teacherDataService';
import { TeacherNodeService } from '../assets/wise5/services/teacherNodeService';
import { TeacherWebSocketService } from '../assets/wise5/services/teacherWebSocketService';
import { ClassroomStatusService } from '../assets/wise5/services/classroomStatusService';
import { VLEProjectService } from '../assets/wise5/vle/vleProjectService';
import { WiseLinkService } from './services/wiseLinkService';

@NgModule({
providers: [
Expand Down Expand Up @@ -100,6 +101,7 @@ import { ClassroomStatusService } from '../assets/wise5/services/classroomStatus
PathService,
PeerChatService,
PeerGroupService,
CRaterPingService,
ProjectLibraryService,
{ provide: ProjectService, useExisting: VLEProjectService },
SessionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
i18n-placeholder
[(ngModel)]="response"
(keypress)="keyPressed($event)"
(focus)="focusEvent.emit()"
></textarea>
</mat-form-field>
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ChatInputComponent } from './chat-input.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ChatInputComponent } from './chat-input.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MockProvider } from 'ng-mocks';
import { CRaterPingService } from '../../services/cRaterPingService';

describe('ChatInputComponent', () => {
let component: ChatInputComponent;
let fixture: ComponentFixture<ChatInputComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [BrowserAnimationsModule, ChatInputComponent]
imports: [BrowserAnimationsModule, ChatInputComponent],
providers: [MockProvider(CRaterPingService)]
});
fixture = TestBed.createComponent(ChatInputComponent);
component = fixture.componentInstance;
Expand Down
9 changes: 5 additions & 4 deletions src/assets/wise5/common/chat-input/chat-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';

@Component({
selector: 'chat-input',
templateUrl: './chat-input.component.html',
styleUrls: ['./chat-input.component.scss'],
imports: [FormsModule, FlexLayoutModule, MatButtonModule, MatFormFieldModule, MatInputModule]
selector: 'chat-input',
templateUrl: './chat-input.component.html',
styleUrls: ['./chat-input.component.scss'],
imports: [FormsModule, FlexLayoutModule, MatButtonModule, MatFormFieldModule, MatInputModule]
})
export class ChatInputComponent {
@Output() focusEvent = new EventEmitter<string>();
protected response: string = '';
@Input() submitDisabled: boolean = false;
@Output() submitEvent: EventEmitter<string> = new EventEmitter<string>();
Expand Down
16 changes: 8 additions & 8 deletions src/assets/wise5/components/component/component.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import {
createComponent
} from '@angular/core';
import { ClickToSnipImageService } from '../../services/clickToSnipImageService';
import { ConfigService } from '../../services/configService';
import { NotebookService } from '../../services/notebookService';
import { ProjectService } from '../../services/projectService';
import { StudentDataService } from '../../services/studentDataService';
import { CommonModule } from '@angular/common';
import { Component as WISEComponent } from '../../common/Component';
import { ComponentFactory } from '../../common/ComponentFactory';
import { components } from '../Components';
import { ConfigService } from '../../services/configService';
import { HelpIconComponent } from '../../themes/default/themeComponents/helpIcon/help-icon.component';
import { CommonModule } from '@angular/common';
import { NotebookService } from '../../services/notebookService';
import { ProjectService } from '../../services/projectService';
import { StudentDataService } from '../../services/studentDataService';

@Component({
imports: [CommonModule, HelpIconComponent],
selector: 'component',
templateUrl: 'component.component.html'
imports: [CommonModule, HelpIconComponent],
selector: 'component',
templateUrl: 'component.component.html'
})
export class ComponentComponent {
protected component: WISEComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/>
@if (studentCanRespond) {
<chat-input
(focusEvent)="startPinging()"
[submitDisabled]="isWaitingForComputerResponse"
(submitEvent)="submitStudentResponse($event)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ComponentHeaderComponent } from '../../../directives/component-header/c
import { DialogResponsesComponent } from '../dialog-responses/dialog-responses.component';
import { ChatInputComponent } from '../../../common/chat-input/chat-input.component';
import { CommonModule } from '@angular/common';
import { CRaterPingService } from '../../../services/cRaterPingService';

@Component({
imports: [
Expand Down Expand Up @@ -74,7 +75,8 @@ export class DialogGuidanceStudentComponent extends ComponentStudent {
protected notebookService: NotebookService,
protected studentAssetService: StudentAssetService,
protected dataService: StudentDataService,
protected studentStatusService: StudentStatusService
protected studentStatusService: StudentStatusService,
private cRaterPingService: CRaterPingService
) {
super(
annotationService,
Expand Down Expand Up @@ -110,6 +112,18 @@ export class DialogGuidanceStudentComponent extends ComponentStudent {
this.initializeComputerAvatar();
}

protected startPinging(): void {
this.cRaterPingService.startPinging(this.getItemId());
}

ngOnDestroy(): void {
this.cRaterPingService.stopPinging(this.getItemId());
}

private getItemId(): string {
return this.component.content.itemId;
}

showInitialMessage(): void {
this.addDialogResponse(
new ComputerDialogResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
(ngModelChange)="studentDataChanged()"
[disabled]="isDisabled"
cdkTextareaAutosize
(focus)="onFocus()"
>
</textarea>
<speech-to-text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { OpenResponseService } from '../openResponseService';
import { OpenResponseStudent } from './open-response-student.component';
import { DialogWithoutCloseComponent } from '../../../directives/dialog-without-close/dialog-without-close.component';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { CRaterPingService } from '../../../services/cRaterPingService';
import { MockProvider } from 'ng-mocks';

let component: OpenResponseStudent;
const componentId = 'component1';
Expand All @@ -31,8 +33,9 @@ const response = 'Hello World';
describe('OpenResponseStudent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [DialogWithoutCloseComponent, OpenResponseStudent],
imports: [BrowserAnimationsModule,
declarations: [DialogWithoutCloseComponent, OpenResponseStudent],
imports: [
BrowserAnimationsModule,
BrowserModule,
CommonModule,
ComponentHeaderComponent,
Expand All @@ -41,9 +44,15 @@ describe('OpenResponseStudent', () => {
MatDialogModule,
MatIconModule,
ReactiveFormsModule,
StudentTeacherCommonServicesModule],
providers: [AudioRecorderService, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()]
});
StudentTeacherCommonServicesModule
],
providers: [
AudioRecorderService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
MockProvider(CRaterPingService)
]
});
});

beforeEach(() => {
Expand Down Expand Up @@ -180,18 +189,15 @@ function expectPopupToBeCalledWith(

function createComponentState() {
describe('createComponentState', () => {
it(
'should create component state',
waitForAsync(() => {
spyOn(TestBed.inject(OpenResponseService), 'isCompletedV2').and.returnValue(true);
component.studentResponse = response;
component.createComponentState('save').then((componentState: any) => {
expect(componentState.componentId).toEqual(componentId);
expect(componentState.nodeId).toEqual(nodeId);
expect(componentState.studentData.response).toEqual(response);
});
})
);
it('should create component state', waitForAsync(() => {
spyOn(TestBed.inject(OpenResponseService), 'isCompletedV2').and.returnValue(true);
component.studentResponse = response;
component.createComponentState('save').then((componentState: any) => {
expect(componentState.componentId).toEqual(componentId);
expect(componentState.nodeId).toEqual(nodeId);
expect(componentState.studentData.response).toEqual(response);
});
}));
});
}

Expand Down
Loading
Loading