Files
Investidor-V2/tests/frontend/demography-editorial.test.mjs
T

96 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import ts from 'typescript';
const require = createRequire(import.meta.url);
const source = fs.readFileSync(
new URL(
'../../resources/js/pages/management/demography.tsx',
import.meta.url,
),
'utf8',
);
const code = ts.transpileModule(source, {
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
jsx: ts.JsxEmit.ReactJSX,
},
}).outputText;
const module = { exports: {} };
new Function('require', 'module', 'exports', code)(
(name) => {
if (name === '@inertiajs/react')
return {
Link: ({ href, children }) =>
React.createElement('a', { href }, children),
router: {},
useForm: () => ({ processing: false }),
};
if (name === './shared')
return {
Management: ({ children }) =>
React.createElement('main', null, children),
button: '',
control: '',
};
return require(name);
},
module,
module.exports,
);
const Page = module.exports.default;
const preview = {
id: 'qa-batch',
file_name: 'synthetic.xlsx',
sha256: 'a'.repeat(64),
publication_version: 'Edição não indicada',
status: 'imported',
report: { record_count: 10, issue_counts: {}, issues: [] },
matches: [],
territory_options: [],
events: [],
};
const render = (changes = {}) =>
renderToStaticMarkup(
React.createElement(Page, {
batches: [],
preview,
editorialEnabled: true,
editorialRevision: 0,
...changes,
}),
);
test('new imported batches enter review without a combined approval and publication button', () => {
const html = render();
assert.match(html, /Preparar revisão para publicação/);
assert.doesNotMatch(html, /Aprovar utilização em QA/);
assert.match(
html,
/aprovação e a publicação dos novos lotes são operações distintas/,
);
});
test('legacy public batches remain accepted and published new batches only offer their history', () => {
const legacy = render({ preview: { ...preview, status: 'approved' } });
assert.match(legacy, /preservado sem nova aprovação/);
assert.doesNotMatch(legacy, /Preparar revisão para publicação/);
const published = render({
preview: { ...preview, status: 'approved' },
editorialRevision: 1,
});
assert.match(
published,
/href="\/management\/editorial\/demography\/qa-batch"/,
);
assert.doesNotMatch(
published,
/Preparar nova edição de revisão|Desactivar série/,
);
});