feat(editorial): preserve public editions and add QA review workflow
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
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/editorial-edition.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, ...rest }) =>
|
||||
React.createElement('a', { href, ...rest }, children),
|
||||
useForm: (data) => ({
|
||||
data,
|
||||
errors: {},
|
||||
processing: false,
|
||||
setData() {},
|
||||
transform() {},
|
||||
post() {},
|
||||
}),
|
||||
};
|
||||
if (name === './shared')
|
||||
return {
|
||||
Management: ({ children }) =>
|
||||
React.createElement('main', null, children),
|
||||
Field: ({ label, children }) =>
|
||||
React.createElement('label', null, label, children),
|
||||
control: '',
|
||||
button: '',
|
||||
};
|
||||
if (name === './editorial-workflow')
|
||||
return {
|
||||
states: {
|
||||
draft: 'Rascunho',
|
||||
approved: 'Aprovado',
|
||||
in_review: 'Em revisão',
|
||||
},
|
||||
};
|
||||
return require(name);
|
||||
},
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const Page = module.exports.default;
|
||||
const props = {
|
||||
resource: {
|
||||
id: 91,
|
||||
title: 'Artigo QA',
|
||||
published: true,
|
||||
public_edition_no: 1,
|
||||
},
|
||||
manager: true,
|
||||
legalReviewer: true,
|
||||
current: true,
|
||||
canApprove: true,
|
||||
independentRequired: true,
|
||||
history: [],
|
||||
editions: [{ id: 'qa-edition', revision_no: 2, state: 'draft' }],
|
||||
reviewers: [{ id: 5, name: 'Equipa de revisão' }],
|
||||
edition: {
|
||||
id: 'qa-edition',
|
||||
revision_no: 2,
|
||||
version: 1,
|
||||
state: 'draft',
|
||||
content_hash: 'a'.repeat(64),
|
||||
fresh: true,
|
||||
legal_required: false,
|
||||
approval: null,
|
||||
legal_validation: null,
|
||||
payload: {
|
||||
resource: {
|
||||
title: 'Novo título',
|
||||
editorial_content: JSON.stringify({
|
||||
body: '<script>não executar</script>',
|
||||
}),
|
||||
},
|
||||
files: [
|
||||
{
|
||||
id: 'qa-file',
|
||||
file_name: 'anexo.pdf',
|
||||
version_no: 2,
|
||||
sha256: 'b'.repeat(64),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
const render = (changes = {}) =>
|
||||
renderToStaticMarkup(React.createElement(Page, { ...props, ...changes }));
|
||||
|
||||
test('draft preserves public version and offers submission without approval or publication', () => {
|
||||
const html = render();
|
||||
assert.match(html, /Versão pública: edição 1/);
|
||||
assert.match(html, /value="submit"/);
|
||||
assert.doesNotMatch(html, /value="(?:approve|publish)"/);
|
||||
assert.match(
|
||||
html,
|
||||
/href="\/management\/editorial\/resources\/91\/editions\/qa-edition\/files\/qa-file" target="_blank" rel="noopener noreferrer"/,
|
||||
);
|
||||
assert.match(html, /<script>/);
|
||||
assert.doesNotMatch(html, /<script>/);
|
||||
});
|
||||
test('approved edition offers explicit publication; stale files and historical versions cannot be published', () => {
|
||||
assert.match(
|
||||
render({
|
||||
edition: { ...props.edition, state: 'approved', approval: '{}' },
|
||||
}),
|
||||
/value="publish"/,
|
||||
);
|
||||
const stale = render({
|
||||
edition: { ...props.edition, state: 'approved', fresh: false },
|
||||
});
|
||||
assert.match(stale, /Os anexos mudaram/);
|
||||
assert.doesNotMatch(stale, /value="publish"/);
|
||||
const historical = render({ current: false });
|
||||
assert.match(historical, /Versão histórica para consulta/);
|
||||
assert.doesNotMatch(historical, /<form/);
|
||||
assert.match(historical, /edition=qa-edition/);
|
||||
});
|
||||
test('contributor does not see independent approval or legal-validation actions', () => {
|
||||
const html = render({
|
||||
canApprove: false,
|
||||
edition: { ...props.edition, state: 'in_review' },
|
||||
});
|
||||
assert.doesNotMatch(html, /value="(?:approve|legal_validate)"/);
|
||||
assert.match(html, /responsável independente/);
|
||||
});
|
||||
Reference in New Issue
Block a user