fix(client): replace apple quotes in fill in the blanks before testing (#57987)

This commit is contained in:
Tom
2025-01-09 11:24:17 -06:00
committed by GitHub
parent bf3ba3363a
commit a8ae17502f
3 changed files with 22 additions and 1 deletions
@@ -33,6 +33,7 @@ import Scene from '../components/scene/scene';
import { SceneSubject } from '../components/scene/scene-subject';
import { getChallengePaths } from '../utils/challenge-paths';
import { isChallengeCompletedSelector } from '../redux/selectors';
import { replaceAppleQuotes } from '../../../utils/replace-apple-quotes';
import './show.css';
@@ -133,7 +134,9 @@ const ShowFillInTheBlank = ({
const blankAnswers = fillInTheBlank.blanks.map(b => b.answer);
const newAnswersCorrect = userAnswers.map(
(userAnswer, i) => !!userAnswer && userAnswer.trim() === blankAnswers[i]
(userAnswer, i) =>
!!userAnswer &&
replaceAppleQuotes(userAnswer.trim()) === blankAnswers[i]
);
setAnswersCorrect(newAnswersCorrect);
const hasWrongAnswer = newAnswersCorrect.some(a => a === false);
@@ -0,0 +1,13 @@
import { replaceAppleQuotes } from './replace-apple-quotes';
describe('replaceAppleQuotes()', () => {
it('replaces apple quotes with regular quotes', () => {
expect(replaceAppleQuotes('“double” quotes and single quotes')).toBe(
`"double" quotes and 'single' quotes`
);
});
it('returns the original string if there are no smart quotes', () => {
expect(replaceAppleQuotes('No quotes')).toBe('No quotes');
});
});
+5
View File
@@ -0,0 +1,5 @@
export function replaceAppleQuotes(text: string): string {
return typeof text !== 'string'
? text
: text.replace(/[“”]/g, '"').replace(/[‘’]/g, "'");
}