Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12578] @ sign is shown as @ when viewing essay question submission page #13142

Merged
merged 4 commits into from
Jul 7, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="plain-text-area" *ngIf="!questionDetails.shouldAllowRichText">
<textarea [ngModel]="responseDetails.answer" (ngModelChange)="triggerResponseDetailsChange('answer', $event)" [attr.aria-label]="getAriaLabel()" [disabled]="isDisabled"></textarea>
<textarea [ngModel]="decodedAnswer" (ngModelChange)="triggerResponseDetailsChange('answer', $event)" [attr.aria-label]="getAriaLabel()" [disabled]="isDisabled"></textarea>
</div>
<tm-rich-text-editor *ngIf="questionDetails.shouldAllowRichText" role="textbox" [attr.aria-label]="getAriaLabel()" [richText]="responseDetails.answer" (richTextChange)="triggerResponseDetailsChange('answer', $event)" [isDisabled]="isDisabled"></tm-rich-text-editor>
<div class="margin-top-7px text-secondary text-end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { FormsModule } from '@angular/forms';
import { TextQuestionEditAnswerFormComponent } from './text-question-edit-answer-form.component';
import { FeedbackQuestionType } from '../../../../types/api-request';
import { RichTextEditorModule } from '../../rich-text-editor/rich-text-editor.module';

describe('TextQuestionEditAnswerFormComponent', () => {
Expand All @@ -22,10 +23,33 @@ describe('TextQuestionEditAnswerFormComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(TextQuestionEditAnswerFormComponent);
component = fixture.componentInstance;
component.questionDetails = {
shouldAllowRichText: false,
questionType: FeedbackQuestionType.TEXT,
questionText: 'Sample question',
recommendedLength: 50,
};
component.responseDetails = { answer: '', questionType: FeedbackQuestionType.TEXT };
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should decode HTML entities for @ sign in plain-text mode', () => {
component.questionDetails.shouldAllowRichText = false;
component.responseDetails.answer = 'Test &#64; symbol';
fixture.detectChanges();

expect(component.decodedAnswer).toBe('Test @ symbol');
});

it('should decode HTML entities for apostrophe in plain-text mode', () => {
component.questionDetails.shouldAllowRichText = false;
component.responseDetails.answer = 'It&#39;s a test';
fixture.detectChanges();

expect(component.decodedAnswer).toBe("It's a test");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export class TextQuestionEditAnswerFormComponent
super(DEFAULT_TEXT_QUESTION_DETAILS(), DEFAULT_TEXT_RESPONSE_DETAILS());
}

decodeHtml(html: string): string {
const txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}

get wordCount(): number {
return this.responseDetails.answer.split(/\s/g)
.filter((item: string) => item.match(/\w/)).length;
Expand All @@ -41,4 +47,8 @@ export class TextQuestionEditAnswerFormComponent

return this.wordCount > lowerLimit && this.wordCount < upperLimit;
}

get decodedAnswer(): string {
return this.decodeHtml(this.responseDetails.answer);
}
}
Loading