Aplicar Pint e formatação de frontend; delimitar o âmbito do lint
Só formatação automática (pint, vp check --fix), sem alterar comportamento. Excluídos da formatação os registos e artefactos com bytes fixos: docs/, integrations/, storage/, tmp/, output/, resources/data/, tests/Fixtures/, compras-release.json e AGENTS*.md. Scripts operacionais, integrations e auxiliares de teste ficam fora do lint (usam new Function; limpeza na fase 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,43 +9,97 @@ if (!root) throw Error('Explicit verified candidate package root required');
|
||||
|
||||
function workspace(file, host = true) {
|
||||
const forms = [0, 1].map(() => ({
|
||||
dataset: { action: file.startsWith('general-ledger') ? 'prepare' : 'payment-prepare' },
|
||||
values: new Map([['reason', '']]), button: { disabled: false }, appended: [],
|
||||
querySelector(selector) { return selector === 'button' ? this.button : null; },
|
||||
querySelectorAll(selector) { return selector === 'button' ? [this.button] : []; },
|
||||
append(...nodes) { this.appended.push(...nodes); },
|
||||
dataset: {
|
||||
action: file.startsWith('general-ledger')
|
||||
? 'prepare'
|
||||
: 'payment-prepare',
|
||||
},
|
||||
values: new Map([['reason', '']]),
|
||||
button: { disabled: false },
|
||||
appended: [],
|
||||
querySelector(selector) {
|
||||
return selector === 'button' ? this.button : null;
|
||||
},
|
||||
querySelectorAll(selector) {
|
||||
return selector === 'button' ? [this.button] : [];
|
||||
},
|
||||
append(...nodes) {
|
||||
this.appended.push(...nodes);
|
||||
},
|
||||
}));
|
||||
const nodes = Object.fromEntries(['#finance', '#reload', '#status', '#error', 'main'].map(id => [id, { textContent: '', focus() {}, prepend() {} }]));
|
||||
const nodes = Object.fromEntries(
|
||||
['#finance', '#reload', '#status', '#error', 'main'].map((id) => [
|
||||
id,
|
||||
{ textContent: '', focus() {}, prepend() {} },
|
||||
]),
|
||||
);
|
||||
const events = new Map();
|
||||
const state = { reloads: 0, requests: [], response: async () => ({ ok: true, json: async () => ({ state: 'saved' }) }) };
|
||||
const settings = { api: '/api/supplier-payments', csrf: 'synthetic', host_journal_policy: host, host_settlement_policy: host };
|
||||
const state = {
|
||||
reloads: 0,
|
||||
requests: [],
|
||||
response: async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ state: 'saved' }),
|
||||
}),
|
||||
};
|
||||
const settings = {
|
||||
api: '/api/supplier-payments',
|
||||
csrf: 'synthetic',
|
||||
host_journal_policy: host,
|
||||
host_settlement_policy: host,
|
||||
};
|
||||
const source = readFileSync(path.join(root, file), 'utf8');
|
||||
const script = source.match(/<script>([\s\S]*?)<\/script>/)[1]
|
||||
.replace(/const settings=<\?=[\s\S]*?\?>;/, `const settings=${JSON.stringify(settings)};`);
|
||||
const script = source
|
||||
.match(/<script>([\s\S]*?)<\/script>/)[1]
|
||||
.replace(
|
||||
/const settings=<\?=[\s\S]*?\?>;/,
|
||||
`const settings=${JSON.stringify(settings)};`,
|
||||
);
|
||||
let key = 0;
|
||||
const context = vm.createContext({
|
||||
document: {
|
||||
querySelector: selector => nodes[selector],
|
||||
querySelectorAll: selector => selector === '[data-action]' ? forms : [],
|
||||
querySelector: (selector) => nodes[selector],
|
||||
querySelectorAll: (selector) =>
|
||||
selector === '[data-action]' ? forms : [],
|
||||
createElement: () => ({ textContent: '', setAttribute() {} }),
|
||||
},
|
||||
FormData: class { constructor(form) { this.form = form; } [Symbol.iterator]() { return this.form.values.entries(); } },
|
||||
window: { addEventListener: (event, callback) => events.set(event, callback) },
|
||||
FormData: class {
|
||||
constructor(form) {
|
||||
this.form = form;
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this.form.values.entries();
|
||||
}
|
||||
},
|
||||
window: {
|
||||
addEventListener: (event, callback) => events.set(event, callback),
|
||||
},
|
||||
location: { reload: () => state.reloads++, assign() {} },
|
||||
crypto: { randomUUID: () => `synthetic-operation-${++key}` },
|
||||
fetch: async (url, options) => { state.requests.push({ url, ...options }); return state.response(); },
|
||||
fetch: async (url, options) => {
|
||||
state.requests.push({ url, ...options });
|
||||
return state.response();
|
||||
},
|
||||
});
|
||||
vm.runInContext(script, context);
|
||||
const leaving = () => {
|
||||
const event = { prevented: false, preventDefault() { this.prevented = true; } };
|
||||
const event = {
|
||||
prevented: false,
|
||||
preventDefault() {
|
||||
this.prevented = true;
|
||||
},
|
||||
};
|
||||
events.get('beforeunload')?.(event);
|
||||
return event.prevented;
|
||||
};
|
||||
const submit = form => form.onsubmit({ preventDefault() {} });
|
||||
const submit = (form) => form.onsubmit({ preventDefault() {} });
|
||||
return { forms, state, leaving, submit, nodes };
|
||||
}
|
||||
|
||||
for (const file of ['general-ledger/ui/cycle.php', 'payables/ui/settlements.php']) {
|
||||
for (const file of [
|
||||
'general-ledger/ui/cycle.php',
|
||||
'payables/ui/settlements.php',
|
||||
]) {
|
||||
test(`${file}: only an edited preparation warns before leaving`, () => {
|
||||
const w = workspace(file);
|
||||
assert.equal(w.leaving(), false);
|
||||
@@ -62,7 +116,10 @@ for (const file of ['general-ledger/ui/cycle.php', 'payables/ui/settlements.php'
|
||||
await w.submit(w.forms[0]);
|
||||
assert.equal(w.state.reloads, 0);
|
||||
assert.equal(w.forms[0].button.disabled, true);
|
||||
assert.equal(w.forms[1].values.get('reason'), 'Preserve this separate preparation');
|
||||
assert.equal(
|
||||
w.forms[1].values.get('reason'),
|
||||
'Preserve this separate preparation',
|
||||
);
|
||||
assert.equal(w.leaving(), true);
|
||||
assert.equal(w.forms[0].appended.length, 2);
|
||||
assert.match(w.forms[0].appended[0].textContent, /registada/);
|
||||
@@ -76,8 +133,13 @@ for (const file of ['general-ledger/ui/cycle.php', 'payables/ui/settlements.php'
|
||||
|
||||
test(`${file}: unknown network result preserves values and retries the same command identity`, async () => {
|
||||
const w = workspace(file);
|
||||
w.forms[0].values.set('reason', 'Do not lose an interrupted synthetic operation');
|
||||
w.state.response = async () => { throw Error('Synthetic lost response'); };
|
||||
w.forms[0].values.set(
|
||||
'reason',
|
||||
'Do not lose an interrupted synthetic operation',
|
||||
);
|
||||
w.state.response = async () => {
|
||||
throw Error('Synthetic lost response');
|
||||
};
|
||||
await w.submit(w.forms[0]);
|
||||
assert.equal(w.forms[0].button.disabled, false);
|
||||
assert.equal(w.state.reloads, 0);
|
||||
@@ -87,14 +149,20 @@ for (const file of ['general-ledger/ui/cycle.php', 'payables/ui/settlements.php'
|
||||
w.state.response = async () => ({ ok: true, json: async () => ({}) });
|
||||
await w.submit(w.forms[0]);
|
||||
assert.equal(w.state.requests[1].headers['Idempotency-Key'], key);
|
||||
assert.equal(w.forms[0].values.get('reason'), 'Do not lose an interrupted synthetic operation');
|
||||
assert.equal(
|
||||
w.forms[0].values.get('reason'),
|
||||
'Do not lose an interrupted synthetic operation',
|
||||
);
|
||||
assert.equal(w.state.reloads, 1);
|
||||
});
|
||||
|
||||
test(`${file}: a second submit while pending cannot start another request`, async () => {
|
||||
const w = workspace(file);
|
||||
let finish;
|
||||
w.state.response = () => new Promise(resolve => { finish = resolve; });
|
||||
w.state.response = () =>
|
||||
new Promise((resolve) => {
|
||||
finish = resolve;
|
||||
});
|
||||
const pending = w.submit(w.forms[0]);
|
||||
await w.submit(w.forms[0]);
|
||||
assert.equal(w.state.requests.length, 1);
|
||||
|
||||
Reference in New Issue
Block a user