Skip to content

Commit

Permalink
Add starter choices for MC authoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima committed Dec 3, 2024
1 parent f34864a commit e4f2a73
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/app/services/multipleChoiceService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let componentId1: string = 'abcdefghij';
describe('MultipleChoiceService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: [
imports: [],
providers: [
AnnotationService,
ConfigService,
MultipleChoiceService,
Expand All @@ -37,8 +37,8 @@ describe('MultipleChoiceService', () => {
TagService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
});
]
});
service = TestBed.inject(MultipleChoiceService);
choice1 = createChoice(choiceId1, choiceText1, '', false);
choice2 = createChoice(choiceId2, choiceText2, '', false);
Expand All @@ -58,7 +58,7 @@ function createComponent() {
const component = service.createComponent();
expect(component.type).toEqual('MultipleChoice');
expect(component.choiceType).toEqual('radio');
expect(component.choices).toEqual([]);
expect(component.choices.length).toEqual(2);
expect(component.showFeedback).toEqual(true);
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/assets/wise5/components/multipleChoice/Choice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export interface Choice {
export class Choice {
feedbackToShow: string;
id: string;
isCorrect: boolean;
text: string;

constructor(id: string, text: string, isCorrect: boolean, feedbackToShow: string) {
this.id = id;
this.text = text;
this.isCorrect = isCorrect;
this.feedbackToShow = feedbackToShow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FlexLayoutModule } from '@angular/flex-layout';
import { EditComponentPrompt } from '../../../../../app/authoring-tool/edit-component-prompt/edit-component-prompt.component';
import { TranslatableAssetChooserComponent } from '../../../authoringTool/components/translatable-asset-chooser/translatable-asset-chooser.component';
import { TranslatableInputComponent } from '../../../authoringTool/components/translatable-input/translatable-input.component';
import { Choice } from '../Choice';

@Component({
imports: [
Expand Down Expand Up @@ -80,13 +81,7 @@ export class MultipleChoiceAuthoring extends AbstractComponentAuthoring {
}

protected addChoice(): void {
const newChoice = {
id: generateRandomKey(),
text: '',
feedback: '',
isCorrect: false
};
this.componentContent.choices.push(newChoice);
this.componentContent.choices.push(new Choice(generateRandomKey(), '', false, ''));
this.componentChanged();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
'use strict';

import { ComponentService } from '../componentService';
import { Injectable } from '@angular/core';
import { arraysContainSameValues } from '../../common/array/array';
import { Choice } from './Choice';
import { generateRandomKey } from '../../common/string/string';

@Injectable()
export class MultipleChoiceService extends ComponentService {
getComponentTypeLabel(): string {
return $localize`Multiple Choice`;
}

createComponent() {
createComponent(): any {
const component: any = super.createComponent();
component.type = 'MultipleChoice';
component.prompt = $localize`Choose an option from below`;
component.choiceType = 'radio';
component.choices = [];
component.choices = [
new Choice(generateRandomKey(), $localize`Choice 1`, false, ''),
new Choice(generateRandomKey(), $localize`Choice 2`, false, '')
];
component.showFeedback = true;
return component;
}
Expand Down
23 changes: 22 additions & 1 deletion src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -19593,7 +19593,7 @@ Warning: This will delete all existing choices and buckets in this component.</s
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/components/multipleChoice/multiple-choice-authoring/multiple-choice-authoring.component.ts</context>
<context context-type="linenumber">94</context>
<context context-type="linenumber">89</context>
</context-group>
</trans-unit>
<trans-unit id="6683126302760629027" datatype="html">
Expand Down Expand Up @@ -19829,6 +19829,27 @@ Warning: This will delete all existing choices in this component.</source>
<context context-type="linenumber">25,28</context>
</context-group>
</trans-unit>
<trans-unit id="4018977700600303269" datatype="html">
<source>Choose an option from below</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/components/multipleChoice/multipleChoiceService.ts</context>
<context context-type="linenumber">16</context>
</context-group>
</trans-unit>
<trans-unit id="1267813701388263700" datatype="html">
<source>Choice 1</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/components/multipleChoice/multipleChoiceService.ts</context>
<context context-type="linenumber">19</context>
</context-group>
</trans-unit>
<trans-unit id="169678945905320246" datatype="html">
<source>Choice 2</source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/components/multipleChoice/multipleChoiceService.ts</context>
<context context-type="linenumber">20</context>
</context-group>
</trans-unit>
<trans-unit id="7864549548500976713" datatype="html">
<source>Students type a response to a question or prompt.</source>
<context-group purpose="location">
Expand Down

0 comments on commit e4f2a73

Please sign in to comment.