+
+
+ );
+};
+
+ProblemSettingsModal.propTypes = {
+ intl: intlShape.isRequired,
+ currentPatternId: PropTypes.string,
+ onDecide: PropTypes.func.isRequired,
+ onRequestClose: PropTypes.func.isRequired,
+};
+
+export default injectIntl(ProblemSettingsModal);
diff --git a/packages/scratch-gui/src/components/ruby-toolbar/messages.js b/packages/scratch-gui/src/components/ruby-toolbar/messages.js
index c0557db01a6..015f91ce76f 100644
--- a/packages/scratch-gui/src/components/ruby-toolbar/messages.js
+++ b/packages/scratch-gui/src/components/ruby-toolbar/messages.js
@@ -143,11 +143,6 @@ const messages = defineMessages({
defaultMessage: 'Show the line numbers and the rules, in the form of the test questions',
description: 'Tooltip of the switch of the line numbers and the rules of the Japanese mode',
},
- problemSettingsHeading: {
- id: 'gui.rubyToolbar.problemSettingsHeading',
- defaultMessage: 'Rules of the problem',
- description: 'Heading in the More menu of the Japanese mode over the patterns of the settings',
- },
previewRubyOfJapanese: {
id: 'gui.rubyToolbar.previewRubyOfJapanese',
defaultMessage: 'Preview the program in Ruby',
@@ -158,17 +153,6 @@ const messages = defineMessages({
defaultMessage: 'Save the Japanese program (.txt)',
description: 'More menu item of the Japanese mode: save the Japanese program as a text file',
},
- settingsPatternExample: {
- id: 'gui.rubyToolbar.settingsPatternExample',
- defaultMessage: 'The form of the examples (indices from 0)',
- description: 'More menu item of the Japanese mode: write the program by the settings of the examples',
- },
- settingsPatternIndexFromOne: {
- id: 'gui.rubyToolbar.settingsPatternIndexFromOne',
- defaultMessage: 'A problem whose indices start at 1',
- description:
- 'More menu item of the Japanese mode: write the program by the settings of a problem whose indices start at 1',
- },
previewRubyScript: {
id: 'gui.rubyToolbar.previewRubyScript',
defaultMessage: 'Preview Ruby script',
diff --git a/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.css b/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.css
index f97e4f19196..79fee2219f5 100644
--- a/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.css
+++ b/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.css
@@ -341,14 +341,6 @@
background-color: $ui-black-transparent;
}
-.moreMenuHeading {
- padding: calc($space / 2) 0.75rem 0;
- font-size: 0.75rem;
- font-weight: bold;
- color: $text-primary-transparent;
- white-space: nowrap;
-}
-
/*
* スイッチ(Issue #2453): 1 つのものを表示する / しない(使う / 使わない)を、押すたびに入れ替える。
* 「行番号と罫線」と「自動置換」(Issue #2605)で使う。
diff --git a/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.jsx b/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.jsx
index adf12f6fa1d..597adaa065c 100644
--- a/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.jsx
+++ b/packages/scratch-gui/src/components/ruby-toolbar/ruby-toolbar.jsx
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import React, { useState, useCallback, useRef, useEffect } from 'react';
import { useIntl } from 'react-intl';
import analytics from '../../lib/analytics';
-import { dnclSettingsPatternId } from '../../lib/dncl/dncl-settings';
import { isJapaneseLocale } from '../../lib/locale-utils.js';
import { isTouchDevice } from '../../lib/touch-device.js';
import iconAutoCorrect from './icon--auto-correct.svg';
@@ -196,29 +195,6 @@ const RubyToolbar = (props) => {
if (props.onCopyProblemForm) props.onCopyProblemForm();
}, [props]);
- // === Smalruby: Start of settings patterns of the Japanese mode ===
- const handleSelectSettingsPattern = useCallback(
- (patternId) => {
- setShowMoreMenu(false);
- if (props.onDismissBubble) props.onDismissBubble();
- if (props.onSelectSettingsPattern) props.onSelectSettingsPattern(patternId);
- },
- [props],
- );
- const handleSelectExamplePattern = useCallback(
- () => handleSelectSettingsPattern('example'),
- [handleSelectSettingsPattern],
- );
- const handleSelectIndexFromOnePattern = useCallback(
- () => handleSelectSettingsPattern('indexFromOne'),
- [handleSelectSettingsPattern],
- );
- // The pattern the program is written by, read from its sentences when the menu is shown.
- const currentPatternId =
- showMoreMenu && props.dnclMode && props.editorRef && typeof props.editorRef.getValue === 'function'
- ? dnclSettingsPatternId(props.editorRef.getValue())
- : null;
- // === Smalruby: End of settings patterns of the Japanese mode ===
const handlePreviewRubyScript = useCallback(() => {
setShowMoreMenu(false);
if (props.onDismissBubble) props.onDismissBubble();
@@ -490,34 +466,6 @@ const RubyToolbar = (props) => {
{intl.formatMessage(messages.saveJapaneseProgram)}
{
onRequestClose={handleCloseAutoCorrectSettings}
/>
)}
+ {showProblemSettingsModal && (
+
+ )}
{showScriptPreview && (
{
return pattern ? pattern.id : null;
};
+/**
+ * The sentences a pattern writes at the top of a program (shown in the popup
+ * of 「問題の約束」 before they are written).
+ * @param {string} patternId - The id of the pattern.
+ * @returns {Array} The sentences, with their comment mark.
+ */
+const dnclSettingsSentences = (patternId) => {
+ const pattern = SETTINGS_PATTERNS.find((p) => p.id === patternId);
+ if (!pattern) return [];
+ return withSettings('', pattern.settings)
+ .split('\n')
+ .filter((line) => line !== '');
+};
+
/**
* The same program written by the settings of a pattern: the sentences at the
* top are written for the pattern and the program is written again by them, so
@@ -55,4 +69,10 @@ const dnclWithIndexFromOne = (dncl) => {
return withSettings(dncl, { ...settings, indexBase: 1 });
};
-export { dnclSettingsPatternId, dnclWithIndexFromOne, dnclWithSettingsPattern, SETTINGS_PATTERNS };
+export {
+ dnclSettingsPatternId,
+ dnclSettingsSentences,
+ dnclWithIndexFromOne,
+ dnclWithSettingsPattern,
+ SETTINGS_PATTERNS,
+};
diff --git a/packages/scratch-gui/src/locales/en.js b/packages/scratch-gui/src/locales/en.js
index 7996c83a71d..c7fcacde4eb 100644
--- a/packages/scratch-gui/src/locales/en.js
+++ b/packages/scratch-gui/src/locales/en.js
@@ -1752,13 +1752,26 @@ export default {
'gui.rubyToolbar.autoCorrectSwitch': 'Auto-correct',
'gui.rubyToolbar.rulesSwitch': 'Line numbers and rules',
'gui.rubyToolbar.rulesSwitchTitle': 'Show the line numbers and the rules, in the form of the test questions',
- 'gui.rubyToolbar.problemSettingsHeading': 'Rules of the problem',
+ 'gui.problemSettingsModal.title': 'Rules of the problem',
+ 'gui.problemSettingsModal.explanation':
+ 'A problem of the common test first tells its rules (whether the indices of the arrays start at 0 or at 1, and so on). Pick the rules of the problem you solve.',
+ 'gui.problemSettingsModal.patternExample': 'The form of the examples (indices from 0)',
+ 'gui.problemSettingsModal.patternIndexFromOne': 'A problem whose indices start at 1',
+ 'gui.problemSettingsModal.example': 'When {array}, {item} is {value}',
+ 'gui.problemSettingsModal.sentencesLabel': 'The sentences written at the top of the program:',
+ 'gui.problemSettingsModal.noSentences': '(Nothing is written. The sentences of the rules now are removed.)',
+ 'gui.problemSettingsModal.othersKept': 'The other comments stay as they are.',
+ 'gui.problemSettingsModal.cancel': 'Cancel',
+ 'gui.problemSettingsModal.ok': 'OK',
+ 'gui.problemSettingsBand.label': 'Rules of the problem: {rules}',
+ 'gui.problemSettingsBand.example': 'indices from 0',
+ 'gui.problemSettingsBand.indexFromOne': 'indices from 1',
+ 'gui.problemSettingsBand.other': 'other',
+ 'gui.problemSettingsBand.change': 'Change',
'gui.rubyToolbar.previewRubyOfJapanese': 'Preview the program in Ruby',
'gui.rubyToolbar.saveJapaneseProgram': 'Save the Japanese program (.txt)',
'gui.rubyTab.dnclIndexSettingConfirm':
'The pasted program says that its array indices start at 1. Write "すべての配列の添字は 1 から始まる。" at the top of the program, so that the indices start at 1?',
- 'gui.rubyToolbar.settingsPatternExample': 'The form of the examples (indices from 0)',
- 'gui.rubyToolbar.settingsPatternIndexFromOne': 'A problem whose indices start at 1',
'gui.rubyTab.dnclForbiddenPrefixError': '"{name}" cannot be used in a variable in the Japanese tab.',
'gui.rubyTab.dnclPostTestLoopError':
'A post-test loop (a loop that runs once before it checks the condition) cannot be written in Japanese. Write the first run before the loop, then make it a "〜の間繰り返す" loop. You can write it in the Ruby tab.',
diff --git a/packages/scratch-gui/src/locales/ja-Hira.js b/packages/scratch-gui/src/locales/ja-Hira.js
index 628a935b1ba..c028968342d 100644
--- a/packages/scratch-gui/src/locales/ja-Hira.js
+++ b/packages/scratch-gui/src/locales/ja-Hira.js
@@ -2132,13 +2132,26 @@ export default {
'gui.rubyToolbar.autoCorrectSwitch': 'じどうちかん',
'gui.rubyToolbar.rulesSwitch': 'ぎょうばんごうとけいせん',
'gui.rubyToolbar.rulesSwitchTitle': 'ぎょうばんごうとけいせんをひょうじして、もんだいとおなじかたちでよむ',
- 'gui.rubyToolbar.problemSettingsHeading': 'もんだいのやくそく',
+ 'gui.problemSettingsModal.title': 'もんだいのやくそく',
+ 'gui.problemSettingsModal.explanation':
+ 'きょうつうテストのもんだいは、はじめにやくそく(はいれつのそえじが 0 からはじまるか 1 からはじまるか など)をかきます。とくもんだいのやくそくにあわせてえらんでください。',
+ 'gui.problemSettingsModal.patternExample': 'れいじのかたち(そえじは 0 から)',
+ 'gui.problemSettingsModal.patternIndexFromOne': 'そえじが 1 からはじまるもんだい',
+ 'gui.problemSettingsModal.example': '{array} のとき {item} は {value}',
+ 'gui.problemSettingsModal.sentencesLabel': 'プログラムのせんとうにはいるぶん:',
+ 'gui.problemSettingsModal.noSentences': '(なにもはいりません。いまのやくそくのぶんはきえます)',
+ 'gui.problemSettingsModal.othersKept': 'ほかのコメントはそのままのこります。',
+ 'gui.problemSettingsModal.cancel': 'キャンセル',
+ 'gui.problemSettingsModal.ok': 'けってい',
+ 'gui.problemSettingsBand.label': 'もんだいのやくそく: {rules}',
+ 'gui.problemSettingsBand.example': 'そえじは 0 から',
+ 'gui.problemSettingsBand.indexFromOne': 'そえじは 1 から',
+ 'gui.problemSettingsBand.other': 'そのほか',
+ 'gui.problemSettingsBand.change': 'かえる',
'gui.rubyToolbar.previewRubyOfJapanese': 'ルビーになおしたものをかくにん',
'gui.rubyToolbar.saveJapaneseProgram': 'にほんごのプログラムをほぞん(.txt)',
'gui.rubyTab.dnclIndexSettingConfirm':
'はりつけたプログラムには、はいれつのそえじは 1 からはじまるとかいてあります。プログラムのはじめに「すべての配列の添字は 1 から始まる。」とかいて、そえじが 1 からはじまるせっていにしますか?',
- 'gui.rubyToolbar.settingsPatternExample': 'れいじのかたち(そえじは 0 から)',
- 'gui.rubyToolbar.settingsPatternIndexFromOne': 'そえじが 1 からはじまるもんだい',
'gui.rubyTab.dnclForbiddenPrefixError': 'にほんごタブでは、へんすうに「{name}」はつかえません',
'gui.rubyTab.dnclPostTestLoopError':
'あとではんていするくりかえし(さきに 1 かいうごかしてからじょうけんをたしかめるくりかえし)は、にほんごではかけません。さいしょの 1 かいをループのまえにかいてから、「〜のあいだくりかえす」にしてください。ルビータブではかけます。',
diff --git a/packages/scratch-gui/src/locales/ja.js b/packages/scratch-gui/src/locales/ja.js
index a7cb63f294f..7939eb27eb6 100644
--- a/packages/scratch-gui/src/locales/ja.js
+++ b/packages/scratch-gui/src/locales/ja.js
@@ -2081,13 +2081,26 @@ export default {
'gui.rubyToolbar.autoCorrectSwitch': '自動置換',
'gui.rubyToolbar.rulesSwitch': '行番号と罫線',
'gui.rubyToolbar.rulesSwitchTitle': '行番号と罫線を表示して、問題と同じ形で読む',
- 'gui.rubyToolbar.problemSettingsHeading': '問題の約束',
+ 'gui.problemSettingsModal.title': '問題の約束',
+ 'gui.problemSettingsModal.explanation':
+ '共通テストの問題は、はじめに約束(配列の添字が 0 から始まるか 1 から始まるか など)を書きます。解く問題の約束に合わせて選んでください。',
+ 'gui.problemSettingsModal.patternExample': '例示の形(添字は 0 から)',
+ 'gui.problemSettingsModal.patternIndexFromOne': '添字が 1 から始まる問題',
+ 'gui.problemSettingsModal.example': '{array} のとき {item} は {value}',
+ 'gui.problemSettingsModal.sentencesLabel': 'プログラムの先頭に入る文:',
+ 'gui.problemSettingsModal.noSentences': '(何も入りません。いまの約束の文は消えます)',
+ 'gui.problemSettingsModal.othersKept': 'ほかのコメントはそのまま残ります。',
+ 'gui.problemSettingsModal.cancel': 'キャンセル',
+ 'gui.problemSettingsModal.ok': '決定',
+ 'gui.problemSettingsBand.label': '問題の約束: {rules}',
+ 'gui.problemSettingsBand.example': '添字は 0 から',
+ 'gui.problemSettingsBand.indexFromOne': '添字は 1 から',
+ 'gui.problemSettingsBand.other': 'そのほか',
+ 'gui.problemSettingsBand.change': '変える',
'gui.rubyToolbar.previewRubyOfJapanese': 'ルビーに直したものを確認',
'gui.rubyToolbar.saveJapaneseProgram': '日本語のプログラムを保存(.txt)',
'gui.rubyTab.dnclIndexSettingConfirm':
'貼り付けたプログラムには、配列の添字は 1 から始まると書いてあります。プログラムの冒頭に「すべての配列の添字は 1 から始まる。」と書いて、添字が 1 から始まる設定にしますか?',
- 'gui.rubyToolbar.settingsPatternExample': '例示の形(添字は 0 から)',
- 'gui.rubyToolbar.settingsPatternIndexFromOne': '添字が 1 から始まる問題',
'gui.rubyTab.dnclForbiddenPrefixError': '日本語タブでは変数に「{name}」は使えません',
'gui.rubyTab.dnclPostTestLoopError':
'後判定の繰り返し(先に 1 回動かしてから条件を確かめる繰り返し)は日本語では書けません。最初の 1 回をループの前に書いてから、「〜の間繰り返す」にしてください。ルビータブでは書けます。',
diff --git a/packages/scratch-gui/test/integration/dncl-settings-pattern.test.js b/packages/scratch-gui/test/integration/dncl-settings-pattern.test.js
index 0ba8147141f..53fc769e775 100644
--- a/packages/scratch-gui/test/integration/dncl-settings-pattern.test.js
+++ b/packages/scratch-gui/test/integration/dncl-settings-pattern.test.js
@@ -1,8 +1,9 @@
import path from 'path';
import SeleniumHelper from '../helpers/selenium-helper';
-// The patterns of settings of the Japanese mode (Issue #1757): picking one in
-// the more menu writes the sentences at the top and the same program by them.
+// The patterns of settings of the Japanese mode (Issue #1757, #2606): picking one in
+// the popup of 「問題の約束」 (「変える」 of the green band) writes the sentences at the
+// top and the same program by them.
// The program is written for this test; no question of the test is used.
const seleniumHelper = new SeleniumHelper();
const { getDriver, getLogs, loadUri } = seleniumHelper;
@@ -20,15 +21,21 @@ const editorValue = (d) => d.executeScript('return window.monacoEditor.getValue(
const waitFor = (d, check, message) => d.wait(check, 10000, message);
+const bandText = (d) =>
+ d.executeScript('return document.querySelector(\'[data-testid="ruby-tab-problem-settings"]\').textContent');
+
/**
- * Open the more menu and pick an item of it, once the menu shows it.
+ * Open the popup from the green band, pick a pattern and decide.
* @param {object} d - The driver.
- * @param {string} testId - The item.
+ * @param {string} id - The pattern (`example`, `index-from-one`).
*/
-const pickMenuItem = async (d, testId) => {
- await clickByTestId(d, 'ruby-toolbar-more-menu');
- await waitFor(d, () => existsByTestId(d, testId), `The menu did not show ${testId}`);
- await clickByTestId(d, testId);
+const pickPattern = async (d, id) => {
+ await clickByTestId(d, 'ruby-tab-problem-settings-change');
+ const testId = `problem-settings-modal-pattern-${id}`;
+ await waitFor(d, () => existsByTestId(d, testId), 'The popup did not open');
+ await d.executeScript(`document.querySelector('[data-testid="${testId}"] input').click()`);
+ await clickByTestId(d, 'problem-settings-modal-ok');
+ await waitFor(d, async () => !(await existsByTestId(d, testId)), 'The popup did not close');
};
let driver;
@@ -54,7 +61,8 @@ describe('Japanese mode: the patterns of settings', () => {
);
await driver.executeScript(`window.monacoEditor.setValue(${JSON.stringify(CODE)});`);
- await pickMenuItem(driver, 'ruby-toolbar-menu-settings-pattern-index-from-one');
+ expect(await bandText(driver)).toContain('添字は 0 から');
+ await pickPattern(driver, 'index-from-one');
await waitFor(
driver,
async () => (await editorValue(driver)).startsWith('# すべての配列の添字は 1 から始まる。'),
@@ -65,18 +73,12 @@ describe('Japanese mode: the patterns of settings', () => {
expect(value).toContain('# 「and」は「かつ」を意味する論理演算子であり,');
expect(value.endsWith('A = [5, 6]\n表示する(A[1])')).toBe(true);
- await clickByTestId(driver, 'ruby-toolbar-more-menu');
await waitFor(
driver,
- () => existsByTestId(driver, 'ruby-toolbar-menu-settings-pattern-example'),
- 'The menu did not open again',
+ async () => (await bandText(driver)).includes('添字は 1 から'),
+ 'The band did not show the rules',
);
- expect(
- await driver.executeScript(
- 'return document.querySelector(\'[data-testid="ruby-toolbar-menu-settings-pattern-index-from-one"]\').getAttribute("aria-checked")',
- ),
- ).toBe('true');
- await clickByTestId(driver, 'ruby-toolbar-menu-settings-pattern-example');
+ await pickPattern(driver, 'example');
await waitFor(
driver,
async () => !(await editorValue(driver)).includes('添字は 1 から始まる'),
diff --git a/packages/scratch-gui/test/unit/components/problem-settings-modal.test.jsx b/packages/scratch-gui/test/unit/components/problem-settings-modal.test.jsx
new file mode 100644
index 00000000000..3835be2fa96
--- /dev/null
+++ b/packages/scratch-gui/test/unit/components/problem-settings-modal.test.jsx
@@ -0,0 +1,114 @@
+/* eslint-env jest */
+// 日本語タブの「問題の約束」のポップアップと、緑の帯の「変える」(#2606、docs/dncl/README.md)
+import '@testing-library/jest-dom';
+import { fireEvent, render } from '@testing-library/react';
+import React from 'react';
+import { IntlProvider } from 'react-intl';
+import ProblemSettingsBandItem from '../../../src/components/problem-settings-modal/problem-settings-band-item.jsx';
+import ProblemSettingsModal from '../../../src/components/problem-settings-modal/problem-settings-modal.jsx';
+import ja from '../../../src/locales/ja';
+
+jest.mock('../../../src/containers/modal.jsx', () => {
+ const PropTypes = require('prop-types');
+ const MockModal = ({ children, contentLabel }) => (
+
+ {children}
+
+ );
+ MockModal.propTypes = { children: PropTypes.node, contentLabel: PropTypes.string };
+ return MockModal;
+});
+
+const byTestId = (container, id) => container.querySelector(`[data-testid="${id}"]`);
+
+const renderModal = (overrides = {}) => {
+ const props = { currentPatternId: 'example', onDecide: jest.fn(), onRequestClose: jest.fn(), ...overrides };
+ const utils = render(
+
+
+ ,
+ );
+ return { ...utils, props };
+};
+
+const radio = (container, id) => byTestId(container, `problem-settings-modal-pattern-${id}`).querySelector('input');
+
+describe('ProblemSettingsModal', () => {
+ test('shows the explanation and the two patterns with an example each', () => {
+ const { container } = renderModal();
+ expect(container).toHaveTextContent('解く問題の約束に合わせて選んでください');
+ expect(byTestId(container, 'problem-settings-modal-pattern-example')).toHaveTextContent(
+ '例示の形(添字は 0 から)',
+ );
+ expect(byTestId(container, 'problem-settings-modal-pattern-example')).toHaveTextContent('20');
+ expect(byTestId(container, 'problem-settings-modal-pattern-index-from-one')).toHaveTextContent(
+ '添字が 1 から始まる問題',
+ );
+ expect(byTestId(container, 'problem-settings-modal-pattern-index-from-one')).toHaveTextContent('10');
+ });
+
+ test('the pattern the program is written by is chosen first', () => {
+ const { container } = renderModal({ currentPatternId: 'indexFromOne' });
+ expect(radio(container, 'index-from-one')).toBeChecked();
+ expect(radio(container, 'example')).not.toBeChecked();
+ });
+
+ test('shows the sentences the chosen pattern writes at the top', () => {
+ const { container } = renderModal();
+ expect(byTestId(container, 'problem-settings-modal-sentences')).toHaveTextContent('何も入りません');
+ fireEvent.click(radio(container, 'index-from-one'));
+ expect(byTestId(container, 'problem-settings-modal-sentences')).toHaveTextContent(
+ '# すべての配列の添字は 1 から始まる。',
+ );
+ expect(container).toHaveTextContent('ほかのコメントはそのまま残ります。');
+ });
+
+ test('deciding tells the chosen pattern', () => {
+ const { container, props } = renderModal();
+ fireEvent.click(radio(container, 'index-from-one'));
+ fireEvent.click(byTestId(container, 'problem-settings-modal-ok'));
+ expect(props.onDecide).toHaveBeenCalledWith('indexFromOne');
+ });
+
+ test('cancelling changes nothing', () => {
+ const { container, props } = renderModal();
+ fireEvent.click(radio(container, 'index-from-one'));
+ fireEvent.click(byTestId(container, 'problem-settings-modal-cancel'));
+ expect(props.onDecide).not.toHaveBeenCalled();
+ expect(props.onRequestClose).toHaveBeenCalledTimes(1);
+ });
+
+ test('settings that are no pattern have nothing chosen and cannot be decided', () => {
+ const { container } = renderModal({ currentPatternId: null });
+ expect(radio(container, 'example')).not.toBeChecked();
+ expect(radio(container, 'index-from-one')).not.toBeChecked();
+ expect(byTestId(container, 'problem-settings-modal-ok')).toBeDisabled();
+ });
+});
+
+describe('ProblemSettingsBandItem', () => {
+ const renderItem = (overrides = {}) => {
+ const props = { patternId: 'example', onChange: jest.fn(), ...overrides };
+ const utils = render(
+
+
+ ,
+ );
+ return { ...utils, props };
+ };
+
+ test.each([
+ ['example', '問題の約束: 添字は 0 から'],
+ ['indexFromOne', '問題の約束: 添字は 1 から'],
+ [null, '問題の約束: そのほか'],
+ ])('shows the rules of %s', (patternId, text) => {
+ const { container } = renderItem({ patternId });
+ expect(byTestId(container, 'ruby-tab-problem-settings')).toHaveTextContent(text);
+ });
+
+ test('「変える」 opens the popup', () => {
+ const { container, props } = renderItem();
+ fireEvent.click(byTestId(container, 'ruby-tab-problem-settings-change'));
+ expect(props.onChange).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/scratch-gui/test/unit/components/ruby-toolbar-rules-switch.test.jsx b/packages/scratch-gui/test/unit/components/ruby-toolbar-rules-switch.test.jsx
index 67cf65800d6..8e500cb0b5b 100644
--- a/packages/scratch-gui/test/unit/components/ruby-toolbar-rules-switch.test.jsx
+++ b/packages/scratch-gui/test/unit/components/ruby-toolbar-rules-switch.test.jsx
@@ -106,9 +106,6 @@ describe('ruby-toolbar: the more menu', () => {
'ruby-toolbar-menu-copy-problem-form',
'ruby-toolbar-menu-preview',
'ruby-toolbar-menu-download-japanese',
- 'ruby-toolbar-menu-settings-heading',
- 'ruby-toolbar-menu-settings-pattern-example',
- 'ruby-toolbar-menu-settings-pattern-index-from-one',
'ruby-toolbar-menu-auto-correct-settings',
]);
});
@@ -123,8 +120,6 @@ describe('ruby-toolbar: the more menu', () => {
expect(byTestId(container, 'ruby-toolbar-menu-download-japanese')).toHaveTextContent(
'日本語のプログラムを保存(.txt)',
);
- expect(byTestId(container, 'ruby-toolbar-menu-settings-heading')).toHaveTextContent('問題の約束');
- expect(byTestId(container, 'ruby-toolbar-menu-settings-pattern-example')).not.toHaveTextContent('設定');
});
test('saving the Japanese program calls its handler and closes the menu', () => {
diff --git a/packages/scratch-gui/test/unit/components/ruby-toolbar-settings-pattern.test.jsx b/packages/scratch-gui/test/unit/components/ruby-toolbar-settings-pattern.test.jsx
deleted file mode 100644
index bab9cd19ebc..00000000000
--- a/packages/scratch-gui/test/unit/components/ruby-toolbar-settings-pattern.test.jsx
+++ /dev/null
@@ -1,74 +0,0 @@
-/* eslint-env jest */
-// 日本語モードのメニューで、よくある設定のパターンを選べること(#1757、docs/dncl/design.md 4 章)
-import '@testing-library/jest-dom';
-import { fireEvent, render } from '@testing-library/react';
-import React from 'react';
-import { IntlProvider } from 'react-intl';
-import RubyToolbar from '../../../src/components/ruby-toolbar/ruby-toolbar.jsx';
-import ja from '../../../src/locales/ja';
-
-const INDEX_FROM_ONE = [
- '# すべての配列の添字は 1 から始まる。',
- '# 「and」は「かつ」を意味する論理演算子であり,左右の式がともに真のときにだけ真となる。',
- '# 「or」は「または」を意味する論理演算子であり,左右の式の少なくとも一方が真のときに真となる。',
- '# 「not」は「でない」を意味する論理演算子であり,右の式が偽のときにだけ真となる。',
- 'A = [1]',
-].join('\n');
-
-const renderToolbar = (overrides = {}) => {
- const props = {
- locale: 'ja',
- onSelectTarget: jest.fn(),
- onDismissBubble: jest.fn(),
- onSelectSettingsPattern: jest.fn(),
- dnclMode: true,
- editorRef: { getValue: () => 'A = [1]' },
- ...overrides,
- };
- const utils = render(
-
-
- ,
- );
- fireEvent.click(utils.container.querySelector('[data-testid="ruby-toolbar-more-menu"]'));
- return { ...utils, props };
-};
-
-const item = (container, id) => container.querySelector(`[data-testid="ruby-toolbar-menu-settings-pattern-${id}"]`);
-
-describe('ruby-toolbar settings patterns of the Japanese mode', () => {
- test('the menu has the two patterns in the Japanese mode', () => {
- const { container } = renderToolbar();
- expect(item(container, 'example')).toHaveTextContent(ja['gui.rubyToolbar.settingsPatternExample']);
- expect(item(container, 'index-from-one')).toHaveTextContent(
- ja['gui.rubyToolbar.settingsPatternIndexFromOne'],
- );
- });
-
- test('the menu has no pattern out of the Japanese mode', () => {
- const { container } = renderToolbar({ dnclMode: false });
- expect(item(container, 'example')).toBeNull();
- expect(item(container, 'index-from-one')).toBeNull();
- });
-
- test('the pattern the program is written by is checked', () => {
- const { container } = renderToolbar({ editorRef: { getValue: () => INDEX_FROM_ONE } });
- expect(item(container, 'index-from-one')).toHaveAttribute('aria-checked', 'true');
- expect(item(container, 'example')).toHaveAttribute('aria-checked', 'false');
- });
-
- test('a program with no sentence is the form of 例示', () => {
- const { container } = renderToolbar();
- expect(item(container, 'example')).toHaveAttribute('aria-checked', 'true');
- });
-
- test.each([
- ['example', 'example'],
- ['index-from-one', 'indexFromOne'],
- ])('picking %s tells the pattern and closes the menu', (testId, patternId) => {
- const { container, props } = renderToolbar();
- fireEvent.click(item(container, testId));
- expect(props.onSelectSettingsPattern).toHaveBeenCalledWith(patternId);
- expect(item(container, 'example')).toBeNull();
- });
-});
diff --git a/packages/scratch-gui/test/unit/lib/dncl/dncl-settings.test.js b/packages/scratch-gui/test/unit/lib/dncl/dncl-settings.test.js
index b139d075662..608307b0db6 100644
--- a/packages/scratch-gui/test/unit/lib/dncl/dncl-settings.test.js
+++ b/packages/scratch-gui/test/unit/lib/dncl/dncl-settings.test.js
@@ -1,5 +1,6 @@
import {
dnclSettingsPatternId,
+ dnclSettingsSentences,
dnclWithIndexFromOne,
dnclWithSettingsPattern,
} from '../../../../src/lib/dncl/dncl-settings';
@@ -51,11 +52,30 @@ describe('dnclWithSettingsPattern', () => {
expect(dnclWithSettingsPattern(dncl, 'indexFromOne')).toBe([INDEX_FROM_ONE, ...LOGIC_NOTES, dncl].join('\n'));
});
+ test('the other comments at the top stay', () => {
+ const dncl = [INDEX_FROM_ONE, ...LOGIC_NOTES, '# 点数の合計', 'A = [5, 6]'].join('\n');
+ expect(dnclWithSettingsPattern(dncl, 'example')).toBe('# 点数の合計\nA = [5, 6]');
+ });
+
test('an unknown pattern changes nothing', () => {
expect(dnclWithSettingsPattern('A = [1]', 'nothing')).toBe('A = [1]');
});
});
+describe('dnclSettingsSentences', () => {
+ test('the form of 例示 writes no sentence', () => {
+ expect(dnclSettingsSentences('example')).toEqual([]);
+ });
+
+ test('indexes from 1 writes its sentence and the logical operators', () => {
+ expect(dnclSettingsSentences('indexFromOne')).toEqual([INDEX_FROM_ONE, ...LOGIC_NOTES]);
+ });
+
+ test('an unknown pattern writes no sentence', () => {
+ expect(dnclSettingsSentences('nothing')).toEqual([]);
+ });
+});
+
describe('dnclWithIndexFromOne', () => {
test('writes the sentence at the top and keeps the indexes', () => {
expect(dnclWithIndexFromOne('# 配列の添字は1から始まるものとする\nA = [1, 2]\n表示する(A[1])')).toBe(