commit16
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import { createElement } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import ts from 'typescript';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
function load(file, overrides = {}) {
|
||||
const output = ts.transpileModule(
|
||||
fs.readFileSync(new URL(file, import.meta.url), 'utf8'),
|
||||
{
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
},
|
||||
).outputText;
|
||||
const module = { exports: {} };
|
||||
compileFunction(output, ['require', 'module', 'exports'])(
|
||||
(name) => overrides[name] ?? require(name),
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
return module.exports;
|
||||
}
|
||||
function render(payload) {
|
||||
const empty = () => null;
|
||||
const page = load('../../resources/js/pages/desk/request.tsx', {
|
||||
'@inertiajs/react': {
|
||||
Link: ({ href, children }) =>
|
||||
createElement('a', { href }, children),
|
||||
useForm: (data) => ({ data, errors: {}, processing: false }),
|
||||
},
|
||||
'@/lib/operation-key': { createOperationKey: () => 'synthetic-key' },
|
||||
'@/lib/desk-field-visibility': load(
|
||||
'../../resources/js/lib/desk-field-visibility.ts',
|
||||
),
|
||||
'@/components/dossier-prefill': { DossierPrefill: empty },
|
||||
'@/components/country-select': { __esModule: true, default: empty },
|
||||
'@/components/investment-territory': { TerritoryFields: empty },
|
||||
'@/components/desk-internal-operations': {
|
||||
DocumentReview: empty,
|
||||
RequestOperations: empty,
|
||||
},
|
||||
'@/pages/investment/shared': {
|
||||
Frame: ({ children }) => createElement('main', null, children),
|
||||
card: '',
|
||||
input: '',
|
||||
button: '',
|
||||
},
|
||||
}).default;
|
||||
return renderToStaticMarkup(
|
||||
page({
|
||||
request: {
|
||||
id: 'synthetic-request',
|
||||
version: 1,
|
||||
status: 'draft',
|
||||
payload,
|
||||
protocol: null,
|
||||
editable_fields: [],
|
||||
analyst_id: null,
|
||||
due_at: null,
|
||||
},
|
||||
case: { id: 'synthetic-case', title: 'Synthetic dossier' },
|
||||
definition: {
|
||||
title: 'Synthetic form',
|
||||
result: 'Synthetic result',
|
||||
fields: {
|
||||
detail: {
|
||||
label: 'Deep detail',
|
||||
type: 'text',
|
||||
required: true,
|
||||
when: { field: 'branch', equals: '1' },
|
||||
},
|
||||
branch: {
|
||||
label: 'Branch question',
|
||||
type: 'select',
|
||||
required: true,
|
||||
options: { 0: 'No', 1: 'Yes' },
|
||||
when: { field: 'root', equals: '1' },
|
||||
},
|
||||
root: {
|
||||
label: 'Root question',
|
||||
type: 'select',
|
||||
required: true,
|
||||
options: { 0: 'No', 1: 'Yes' },
|
||||
},
|
||||
},
|
||||
},
|
||||
owner: true,
|
||||
manager: false,
|
||||
analyst: false,
|
||||
fieldsEditable: true,
|
||||
states: { draft: 'Draft' },
|
||||
transitions: [],
|
||||
findings: [],
|
||||
messages: [],
|
||||
analysts: [],
|
||||
territoryPaths: {},
|
||||
events: [],
|
||||
documents: [],
|
||||
payments: [],
|
||||
caseVersion: 1,
|
||||
countries: [],
|
||||
toolPrefill: null,
|
||||
}),
|
||||
);
|
||||
}
|
||||
await test('hidden parent answers never reveal nested questions, while reopening the branch restores their answers', () => {
|
||||
const payload = { root: '0', branch: '1', detail: 'Preserved detail' };
|
||||
const hidden = render(payload);
|
||||
assert.ok(hidden.includes('Root question'));
|
||||
assert.ok(!hidden.includes('Branch question'));
|
||||
assert.ok(!hidden.includes('Deep detail'));
|
||||
assert.ok(!hidden.includes('Preserved detail'));
|
||||
const visible = render({ ...payload, root: '1' });
|
||||
assert.ok(visible.includes('Branch question'));
|
||||
assert.ok(visible.includes('Deep detail'));
|
||||
assert.ok(visible.includes('Preserved detail'));
|
||||
assert.deepEqual(payload, {
|
||||
root: '0',
|
||||
branch: '1',
|
||||
detail: 'Preserved detail',
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user