Skip to content
Snippets Groups Projects
Commit 40da0dcf authored by jojohoch's avatar jojohoch
Browse files

Sanitize `inputAssistancePreset` for text input elements

- Expand the list of elements zo sanitize to
['text-field', 'text-area', 'text-field-simple', 'spell-correct']
- Rename sanitize method
- Change expectations in tests
parent eb256bc5
No related branches found
No related tags found
No related merge requests found
......@@ -254,7 +254,7 @@ describe('SanitizationService', () => {
service.sanitizeUnitDefinition(JSON.parse(JSON.stringify(sampleUnit130TextFields)));
expect(sanitizedUnit130TextFields.pages[0].sections[0].elements[0])
.toEqual(jasmine.objectContaining({
'inputAssistancePreset': 'none',
'inputAssistancePreset': null,
'inputAssistancePosition': 'floating',
'restrictedToInputAssistanceChars': false
}));
......@@ -278,7 +278,7 @@ describe('SanitizationService', () => {
service.sanitizeUnitDefinition(JSON.parse(JSON.stringify(sampleUnit112TextFields)));
expect(sanitizedUnit112TextFields.pages[0].sections[0].elements[0])
.toEqual(jasmine.objectContaining({
'inputAssistancePreset': 'none',
'inputAssistancePreset': null,
'inputAssistancePosition': 'floating'
}));
expect(sanitizedUnit112TextFields.pages[0].sections[0].elements[0])
......@@ -303,7 +303,7 @@ describe('SanitizationService', () => {
// text areas
expect(sanitizedUnit112TextFields.pages[0].sections[0].elements[3])
.toEqual(jasmine.objectContaining({
'inputAssistancePreset': 'none',
'inputAssistancePreset': null,
'inputAssistancePosition': 'floating'
}));
expect(sanitizedUnit112TextFields.pages[0].sections[0].elements[3])
......
......@@ -89,9 +89,9 @@ export class SanitizationService {
if (newElement.type === 'text') {
newElement = SanitizationService.handleTextElement(newElement);
}
if (['text-field', 'text-area']
if (['text-field', 'text-area', 'text-field-simple', 'spell-correct']
.includes(newElement.type as string)) {
newElement = SanitizationService.sanitizeTextFieldElement(newElement);
newElement = SanitizationService.sanitizeTextInputElement(newElement);
}
if (newElement.type === 'cloze') {
newElement = this.handleClozeElement(newElement as Record<string, UIElementValue>);
......@@ -211,11 +211,14 @@ export class SanitizationService {
return newElement as TextElement;
}
private static sanitizeTextFieldElement(element: Record<string, UIElementValue>): InputElement {
private static sanitizeTextInputElement(element: Record<string, UIElementValue>): InputElement {
const newElement = { ...element };
if (newElement.restrictedToInputAssistanceChars === undefined && newElement.inputAssistancePreset === 'french') {
newElement.restrictedToInputAssistanceChars = false;
}
if (newElement.inputAssistancePreset === 'none') {
newElement.inputAssistancePreset = null;
}
return newElement as InputElement;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment