Skip to content

Commit 557723a

Browse files
committed
iss1757 - Fix test. Remove passing of stack_js as no longer needed.
1 parent 81cbf73 commit 557723a

8 files changed

Lines changed: 22 additions & 20 deletions

File tree

corsscripts/ascii/ReadMe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
To run these tests locally, you need to be in this folder with write permissions. Then:
2+
```
3+
npm ci # Installs node modules
4+
npm run build # Bundles and minifies
5+
```

corsscripts/ascii/stackascii.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

corsscripts/ascii/stackascii.bundle.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

corsscripts/ascii/stackascii.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import regexall from './extractors/regexall.js';
2020

2121
const extractorlib = { finalfunction, lastexpr, lastblock, lastcalc, regexmatch, regexall };
2222

23-
export default function init(inputIds, operations, stack_js) {
24-
const stackJS = stack_js;
23+
export default function init(inputIds, operations) {
2524
const markdownContainerId = inputIds[0];
2625
// inputIds[1..N] correspond to each parsed answer entry in order.
2726
const alloperations = operations;

stack/cas/castext2/blocks/ascii.block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function compile($format, $options): ?MP_Node {
128128
return 'stack_js.request_access_to_input("' . $item . '"' . $extra . ')';
129129
}, $inputs, array_keys($inputs)));
130130
$linkcode = 'Promise.all([' . $answercalls . '])';
131-
$linkcode .= ".then((inputIds) => {init(inputIds," . json_encode($operations) . ",stack_js);});";
131+
$linkcode .= ".then((inputIds) => {init(inputIds," . json_encode($operations) . ");});";
132132

133133
$r->items[] = new MP_String($linkcode);
134134
$r->items[] = new MP_String("\n</script>");

tests/ascii_block_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function test_ascii_compile_adds_default_filter_and_input_request(): void
117117
$strings = $this->get_string_items($compiled);
118118
$joined = implode("\n", $strings);
119119
$this->assertStringContainsString('stack_js.request_access_to_input("ans1",true)', $joined);
120-
$expectedlinkcode = '{init(inputIds,[{"operation":"filter","type":"markdown","transforms":"latexwrap,boldfilter"}],stack_js);}';
120+
$expectedlinkcode = '{init(inputIds,[{"operation":"filter","type":"markdown","transforms":"latexwrap,boldfilter"}]);}';
121121
$this->assertStringContainsString($expectedlinkcode, $joined);
122122
$this->assertStringContainsString(
123123
'id="asciiContainerRow" style="width:calc(100% - 20px);height:calc(400px - 30px);"',
@@ -155,7 +155,7 @@ public function test_ascii_compile_uses_child_filter_and_extractor_operations():
155155
$this->assertStringContainsString('stack_js.request_access_to_input("ans1",true)', $joined);
156156
$this->assertStringContainsString('stack_js.request_access_to_input("ans2")', $joined);
157157
$expectedlinkcode = '{init(inputIds,[{"type":"markdown","transforms":"latexwrap","display":"true","operation":"filter"}' .
158-
',{"type":"lastexpr","targetinput":"ans2","operation":"extractor"}],stack_js);}';
158+
',{"type":"lastexpr","targetinput":"ans2","operation":"extractor"}]);}';
159159
$this->assertStringContainsString($expectedlinkcode, $joined);
160160
$this->assertStringContainsString(
161161
'id="asciiContainerRow" style="width:calc(80% - 20px);height:calc(300px - 30px);"',

tests/jest/ReadMe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
To run these tests locally, you need to be in this folder with write permissions. Then:
2+
```
3+
npm ci # Installs node modules
4+
npm test # Runs tests
5+
```

tests/jest/ascii.stackascii.test.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,13 @@ describe('stackascii init', () => {
128128
});
129129
mockLastexpr.mockImplementation((raw, blocks, op) => `EXTRACT:${raw}:${blocks.map((block) => block.type).join('|')}`);
130130

131-
const stackJS = { clear_input: jest.fn() };
132131
const operations = [
133132
{ operation: 'filter', type: 'markdown', reset: 'false', display: 'true' },
134133
{ operation: 'filter', type: 'calculation', reset: 'true'},
135134
{ operation: 'extractor', type: 'unknown' }
136135
];
137136

138-
init(['markdownInput', 'answer1', 'answer2'], operations, stackJS);
137+
init(['markdownInput', 'answer1', 'answer2'], operations);
139138

140139
expect(mockMarkdown).toHaveBeenCalledWith('alpha', expect.any(Object), operations[0]);
141140
expect(mockCalculation).toHaveBeenCalledWith('alpha', expect.any(Object), operations[1]);
@@ -146,7 +145,6 @@ describe('stackascii init', () => {
146145
expect(env.output.innerHTML).toBe('MD:alpha');
147146
expect(env.answers[0].value).toBe('EXTRACT:alpha:markdown|calculation');
148147
expect(env.answers[0].dispatchEvent).toHaveBeenCalledWith({ type: 'change' });
149-
expect(stackJS.clear_input).not.toHaveBeenCalled();
150148
expect(global.MathJax.typesetPromise).toHaveBeenCalledWith([env.output]);
151149
});
152150

@@ -164,15 +162,14 @@ describe('stackascii init', () => {
164162
mockLastexpr.mockImplementation((raw, blocks, op) => `EXTRACT:${raw}:${blocks.map((block) => block.type).join('|')}`);
165163
mockLastcalc.mockImplementation((raw, blocks, op) => `EXTRACTCALC:${raw}:${blocks.map((block) => block.type).join('|')}`);
166164

167-
const stackJS = { clear_input: jest.fn() };
168165
const operations = [
169166
{ operation: 'filter', type: 'markdown' },
170167
{ operation: 'extractor', type: 'lastexpr' },
171168
{ operation: 'filter', type: 'calculation' },
172169
{ operation: 'extractor', type: 'lastcalc' }
173170
];
174171

175-
init(['markdownInput', 'answer1', 'answer2'], operations, stackJS);
172+
init(['markdownInput', 'answer1', 'answer2'], operations);
176173

177174
expect(mockMarkdown).toHaveBeenCalledWith('alpha', expect.any(Object), operations[0]);
178175
expect(mockLastexpr).toHaveBeenCalledWith('alpha', [
@@ -187,7 +184,6 @@ describe('stackascii init', () => {
187184
expect(env.answers[0].dispatchEvent).toHaveBeenCalledWith({ type: 'change' });
188185
expect(env.answers[1].value).toBe('EXTRACTCALC:alpha:calculation');
189186
expect(env.answers[1].dispatchEvent).toHaveBeenCalledWith({ type: 'change' });
190-
expect(stackJS.clear_input).not.toHaveBeenCalled();
191187
expect(global.MathJax.typesetPromise).toHaveBeenCalledWith([env.output]);
192188
});
193189

@@ -196,15 +192,13 @@ describe('stackascii init', () => {
196192

197193
mockFinalfunction.mockReturnValue('ERROR');
198194

199-
const stackJS = { clear_input: jest.fn() };
200195
const operations = [{ operation: 'extractor', type: 'finalfunction' }];
201196

202-
init(['markdownInput', 'answer1'], operations, stackJS);
197+
init(['markdownInput', 'answer1'], operations);
203198

204199
expect(mockFinalfunction).toHaveBeenCalledWith('beta', [], operations[0]);
205-
expect(stackJS.clear_input).toHaveBeenCalledWith('answer1');
206200
expect(env.answers[0].value).toBe('');
207-
expect(env.answers[0].dispatchEvent).not.toHaveBeenCalled();
201+
expect(env.answers[0].dispatchEvent).toHaveBeenCalledTimes(1);
208202
expect(env.output.innerHTML).toBe('beta');
209203
});
210204

@@ -213,10 +207,9 @@ describe('stackascii init', () => {
213207

214208
mockMarkdown.mockImplementation((text) => `MD:${text}`);
215209

216-
const stackJS = { clear_input: jest.fn() };
217210
const operations = [{ operation: 'filter', type: 'markdown', reset: 'false', display: 'false' }];
218211

219-
init(['markdownInput'], operations, stackJS);
212+
init(['markdownInput'], operations);
220213

221214
expect(env.markdownInput.addEventListener).toHaveBeenCalledWith('change', expect.any(Function));
222215
expect(mockMarkdown).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)