Skip to content

Commit e59aea0

Browse files
committed
fix: apply dprint formatting and fix i18n template literal in messages.ts
- Run dprint fmt on all new advanced-settings files to comply with the project's code formatting configuration - Fix i18n extraction error in src/generic/create-or-rerun-course/messages.ts: replace template literal defaultMessage with FormatJS {maxLength} placeholder; update hooks.jsx to pass maxLength value at runtime; update test assertion
1 parent 6c0f6cc commit e59aea0

25 files changed

Lines changed: 211 additions & 108 deletions

src/advanced-settings/AdvancedSettings.test.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import filterMessages from './settings-filters/messages';
1616

1717
// Mock CodeMirror-based JsonInput with a controlled textarea so tests can
1818
// interact with JSON fields without a real browser layout engine.
19-
jest.mock('./setting-card/inputs/JsonInput', () => jest.fn(({ initialValue, onChange, onBlur }) => (
20-
<textarea
21-
data-testid="json-input"
22-
value={initialValue}
23-
onChange={(e) => onChange(e.target.value)}
24-
onBlur={onBlur}
25-
/>
26-
)));
19+
jest.mock('./setting-card/inputs/JsonInput', () =>
20+
jest.fn(({ initialValue, onChange, onBlur }) => (
21+
<textarea
22+
data-testid="json-input"
23+
value={initialValue}
24+
onChange={(e) => onChange(e.target.value)}
25+
onBlur={onBlur}
26+
/>
27+
)));
2728

2829
jest.mock('@src/authz/data/apiHooks', () => ({
2930
useUserPermissions: jest.fn(),
@@ -65,9 +66,11 @@ describe('<AdvancedSettings />', () => {
6566

6667
it('should render without errors', async () => {
6768
render();
68-
expect(await screen.findByText(messages.headingSubtitle.defaultMessage, {
69-
selector: 'small.sub-header-title-subtitle',
70-
})).toBeInTheDocument();
69+
expect(
70+
await screen.findByText(messages.headingSubtitle.defaultMessage, {
71+
selector: 'small.sub-header-title-subtitle',
72+
}),
73+
).toBeInTheDocument();
7174
expect(screen.getByText(messages.headingTitle.defaultMessage, {
7275
selector: 'h2.sub-header-title',
7376
})).toBeInTheDocument();
@@ -177,9 +180,11 @@ describe('<AdvancedSettings />', () => {
177180
data: { canManageAdvancedSettings: true },
178181
} as unknown as ReturnType<typeof useUserPermissions>);
179182
render();
180-
expect(await screen.findByText(messages.headingSubtitle.defaultMessage, {
181-
selector: 'small.sub-header-title-subtitle',
182-
})).toBeInTheDocument();
183+
expect(
184+
await screen.findByText(messages.headingSubtitle.defaultMessage, {
185+
selector: 'small.sub-header-title-subtitle',
186+
}),
187+
).toBeInTheDocument();
183188
expect(screen.getByText(messages.headingTitle.defaultMessage, {
184189
selector: 'h2.sub-header-title',
185190
})).toBeInTheDocument();

src/advanced-settings/AdvancedSettings.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ const AdvancedSettings = () => {
282282
forceOpen={filterText.trim() !== ''}
283283
expandAll={expandAll}
284284
subcategoryMap={category === CATEGORY_CONTENT_BLOCKS ? CONTENT_BLOCKS_SUBCATEGORY_MAP : null}
285-
subcategoryOrder={category === CATEGORY_CONTENT_BLOCKS ? CONTENT_BLOCKS_SUBCATEGORY_ORDER : []}
285+
subcategoryOrder={category === CATEGORY_CONTENT_BLOCKS
286+
? CONTENT_BLOCKS_SUBCATEGORY_ORDER
287+
: []}
286288
/>
287289
),
288290
)}

src/advanced-settings/data/fieldTypeMessages.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ const enumOptionMessages = defineMessages({
3131
finished: {
3232
id: 'course-authoring.advanced-settings.enum.finished',
3333
defaultMessage: 'Finished',
34-
description: 'Option label for Show Answer: show the answer after the learner has used all attempts or the problem is past due',
34+
description:
35+
'Option label for Show Answer: show the answer after the learner has used all attempts or the problem is past due',
3536
},
3637
correctOrPastDue: {
3738
id: 'course-authoring.advanced-settings.enum.correct-or-past-due',
3839
defaultMessage: 'Correct or past due',
39-
description: 'Option label for Show Answer: show the answer once the learner answers correctly or the due date passes',
40+
description:
41+
'Option label for Show Answer: show the answer once the learner answers correctly or the due date passes',
4042
},
4143
pastDue: {
4244
id: 'course-authoring.advanced-settings.enum.past-due',
@@ -61,7 +63,8 @@ const enumOptionMessages = defineMessages({
6163
afterAllAttemptsOrCorrect: {
6264
id: 'course-authoring.advanced-settings.enum.after-all-attempts-or-correct',
6365
defaultMessage: 'After all attempts or correct',
64-
description: 'Option label for Show Answer: show the answer after all attempts are used or the learner answers correctly',
66+
description:
67+
'Option label for Show Answer: show the answer after all attempts are used or the learner answers correctly',
6568
},
6669
attemptedNoPastDue: {
6770
id: 'course-authoring.advanced-settings.enum.attempted-no-past-due',
@@ -141,12 +144,14 @@ const enumOptionMessages = defineMessages({
141144
earlyNoInfo: {
142145
id: 'course-authoring.advanced-settings.enum.early-no-info',
143146
defaultMessage: 'Early (no info)',
144-
description: 'Option label for Certificates Display Behavior: certificates are displayed early with no additional information',
147+
description:
148+
'Option label for Certificates Display Behavior: certificates are displayed early with no additional information',
145149
},
146150
earlyWithInfo: {
147151
id: 'course-authoring.advanced-settings.enum.early-with-info',
148152
defaultMessage: 'Early (with info)',
149-
description: 'Option label for Certificates Display Behavior: certificates are displayed early with additional information shown to learners',
153+
description:
154+
'Option label for Certificates Display Behavior: certificates are displayed early with additional information shown to learners',
150155
},
151156
});
152157

@@ -155,7 +160,7 @@ const enumOptionMessages = defineMessages({
155160
* Used by EnumInput to render localized option labels.
156161
* Keys match the `value` field of each option in ENUM_OPTIONS (fieldTypes.ts).
157162
*/
158-
export const ENUM_LABEL_MESSAGES: Record<string, Record<string, { id: string; defaultMessage: string }>> = {
163+
export const ENUM_LABEL_MESSAGES: Record<string, Record<string, { id: string; defaultMessage: string; }>> = {
159164
showanswer: {
160165
always: enumOptionMessages.always,
161166
answered: enumOptionMessages.answered,
@@ -349,7 +354,8 @@ export const FIELD_PLACEHOLDER_MESSAGES = defineMessages({
349354
topLevelDownstreamParentKey: {
350355
id: 'course-authoring.advanced-settings.placeholder.top-level-downstream-parent-key',
351356
defaultMessage: 'e.g. block-v1:Org+Course+Run+type@vertical+block@id',
352-
description: 'Placeholder for the Top-Level Downstream Parent Key field in Advanced Settings (Open edX block key format)',
357+
description:
358+
'Placeholder for the Top-Level Downstream Parent Key field in Advanced Settings (Open edX block key format)',
353359
},
354360
certNameLong: {
355361
id: 'course-authoring.advanced-settings.placeholder.cert-name-long',

src/advanced-settings/data/fieldTypes.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ describe('serializeValue()', () => {
7777
describe('ENUM_OPTIONS', () => {
7878
it('contains options for all 8 enum fields', () => {
7979
const expectedFields = [
80-
'showanswer', 'rerandomize', 'catalogVisibility', 'courseVisibility',
81-
'showCorrectness', 'videoSharingOptions', 'courseEditMethod', 'certificatesDisplayBehavior',
80+
'showanswer',
81+
'rerandomize',
82+
'catalogVisibility',
83+
'courseVisibility',
84+
'showCorrectness',
85+
'videoSharingOptions',
86+
'courseEditMethod',
87+
'certificatesDisplayBehavior',
8288
];
8389
expectedFields.forEach((field) => {
8490
expect(ENUM_OPTIONS[field]).toBeDefined();

src/advanced-settings/data/fieldTypes.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,47 @@ export const ENUM_OPTIONS: Record<string, EnumOption[]> = {
113113
* Used when the runtime value could be null/empty but the field has a known type.
114114
*/
115115
const NUMBER_KEYS = new Set([
116-
'maxAttempts', 'maxStudentEnrollmentsAllowed', 'entranceExamMinimumScorePct',
117-
'daysEarlyForBeta', 'relativeWeeksDue', 'minimumGradeCredit',
118-
'upstreamVersion', 'upstreamVersionDeclined',
116+
'maxAttempts',
117+
'maxStudentEnrollmentsAllowed',
118+
'entranceExamMinimumScorePct',
119+
'daysEarlyForBeta',
120+
'relativeWeeksDue',
121+
'minimumGradeCredit',
122+
'upstreamVersion',
123+
'upstreamVersionDeclined',
119124
]);
120125

121126
const BOOLEAN_KEYS = new Set([
122-
'certHtmlViewEnabled', 'selfPaced', 'enableTimedExams', 'enableProctoredExams',
123-
'showResetButton', 'mobileAvailable', 'invitationOnly', 'isNew', 'noGrade',
124-
'highlightsEnabledForMessaging', 'allowUnsupportedXblocks', 'allowProctoringOptOut',
125-
'createZendeskTickets', 'enableSubsectionGating', 'entranceExamEnabled',
126-
'allowPublicWikiAccess', 'disableProgressGraph', 'showCalculator', 'hideProgressTab',
127-
'edxnotes', 'videoAutoAdvance', 'videoSpeedOptimizations', 'useLatexCompiler',
128-
'courseSurveyRequired', 'allowAnonymous', 'allowAnonymousToPeers', 'enableCcx',
129-
'forceOnFlexiblePeerOpenassessments', 'downstreamCustomized', 'certificatesShowBeforeEnd',
127+
'certHtmlViewEnabled',
128+
'selfPaced',
129+
'enableTimedExams',
130+
'enableProctoredExams',
131+
'showResetButton',
132+
'mobileAvailable',
133+
'invitationOnly',
134+
'isNew',
135+
'noGrade',
136+
'highlightsEnabledForMessaging',
137+
'allowUnsupportedXblocks',
138+
'allowProctoringOptOut',
139+
'createZendeskTickets',
140+
'enableSubsectionGating',
141+
'entranceExamEnabled',
142+
'allowPublicWikiAccess',
143+
'disableProgressGraph',
144+
'showCalculator',
145+
'hideProgressTab',
146+
'edxnotes',
147+
'videoAutoAdvance',
148+
'videoSpeedOptimizations',
149+
'useLatexCompiler',
150+
'courseSurveyRequired',
151+
'allowAnonymous',
152+
'allowAnonymousToPeers',
153+
'enableCcx',
154+
'forceOnFlexiblePeerOpenassessments',
155+
'downstreamCustomized',
156+
'certificatesShowBeforeEnd',
130157
]);
131158

132159
/**

src/advanced-settings/data/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export type SettingEntry = [string, SettingData];
1414

1515
/** Callback signatures shared across input components and section components. */
1616
export type SetEditedSettings = (
17-
updater: (prev: Record<string, string>) => Record<string, string>
17+
updater: (prev: Record<string, string>) => Record<string, string>,
1818
) => void;

src/advanced-settings/setting-card/SettingCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { useIntl } from '@edx/frontend-platform/i18n';
1414

1515
import messages from './messages';
1616
import {
17-
FIELD_TYPE, getFieldType, serializeValue,
17+
FIELD_TYPE,
18+
getFieldType,
19+
serializeValue,
1820
} from '../data/fieldTypes';
1921
import { FIELD_PLACEHOLDER_MESSAGES } from '../data/fieldTypeMessages';
2022
import BooleanInput from './inputs/BooleanInput';

src/advanced-settings/setting-card/inputs/BooleanInput.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { render, fireEvent, initializeMocks } from '@src/testUtils';
22
import BooleanInput from './BooleanInput';
33

44
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5-
const renderInput = (props: Record<string, any> = {}) => render(
6-
// eslint-disable-next-line react/jsx-props-no-spreading
7-
<BooleanInput name="selfPaced" displayName="Self Paced" {...(props as any)} />,
8-
);
5+
const renderInput = (props: Record<string, any> = {}) =>
6+
render(
7+
// eslint-disable-next-line react/jsx-props-no-spreading
8+
<BooleanInput name="selfPaced" displayName="Self Paced" {...(props as any)} />,
9+
);
910

1011
describe('<BooleanInput />', () => {
11-
beforeEach(() => { initializeMocks(); });
12+
beforeEach(() => {
13+
initializeMocks();
14+
});
1215

1316
it('renders as checked when value is true', () => {
1417
const { getByRole } = renderInput({ value: true, onChange: jest.fn() });

src/advanced-settings/setting-card/inputs/BooleanInput.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ interface BooleanInputProps {
88
}
99

1010
const BooleanInput = ({
11-
value, name, displayName, onChange,
11+
value,
12+
name,
13+
displayName,
14+
onChange,
1215
}: BooleanInputProps) => (
1316
<Form.Switch
1417
id={`setting-bool-${name}`}

src/advanced-settings/setting-card/inputs/EnumInput.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import EnumInput from './EnumInput';
33
import { ENUM_OPTIONS } from '../../data/fieldTypes';
44

55
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
const renderInput = (props: Record<string, any> = {}) => render(
7-
// eslint-disable-next-line react/jsx-props-no-spreading
8-
<EnumInput name="showanswer" displayName="Show Answer" {...(props as any)} />,
9-
);
6+
const renderInput = (props: Record<string, any> = {}) =>
7+
render(
8+
// eslint-disable-next-line react/jsx-props-no-spreading
9+
<EnumInput name="showanswer" displayName="Show Answer" {...(props as any)} />,
10+
);
1011

1112
describe('<EnumInput />', () => {
12-
beforeEach(() => { initializeMocks(); });
13+
beforeEach(() => {
14+
initializeMocks();
15+
});
1316

1417
it('renders the correct options for the given field name', () => {
1518
const { getAllByRole } = renderInput({ value: 'always', onChange: jest.fn() });

0 commit comments

Comments
 (0)