Files
Investidor-V2/tests/frontend/portal-institutional-contact.test.mjs
T

54 lines
2.8 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { compileFunction } from 'node:vm';
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 Empty = () => null;
const passthrough = ({ children }) => React.createElement('div', null, children);
function load(file, page) {
const code = ts.transpileModule(fs.readFileSync(new URL(file, import.meta.url), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, jsx: ts.JsxEmit.ReactJSX, target: ts.ScriptTarget.ES2022 },
}).outputText;
const module = { exports: {} };
const aliases = new Proxy({ default: Empty }, { get: (target, name) => name in target ? target[name] : Empty });
compileFunction(code, ['require', 'module', 'exports'])((name) => {
if (name === 'lucide-react') return aliases;
if (name === '@inertiajs/react') return {
Link: 'a', Head: Empty, usePage: () => page,
useForm: (data) => ({ data, errors: {}, processing: false, setData() {}, post() {}, reset() {} }),
};
if (name === '@/components/tempo-brand') return { useTempoUi: () => ({ t: (text) => text, language: 'pt' }), TempoSocialLinks: Empty };
if (name === '@/pages/investment/shared') return { Frame: passthrough };
if (name.startsWith('@/')) return aliases;
return require(name);
}, module, module.exports);
return module.exports;
}
test('footer identifies the decided operator without implying a public partnership', () => {
const { TempoFooter } = load('../../resources/js/components/tempo-footer.tsx', {
props: { portalOperator: 'Tempo, Lda.', portalInstitutionalContactEmail: 'institution@example.invalid' },
});
const html = renderToStaticMarkup(React.createElement(TempoFooter));
assert.match(html, /Operado por.*Tempo, Lda\./s);
assert.match(html, /mailto:institution@example.invalid/);
assert.doesNotMatch(html, /parceria com a APIEX/);
});
test('support distinguishes the existing institutional contact from dedicated support', () => {
const { default: Services } = load('../../resources/js/pages/portal/services.tsx', {
url: '/apoio', props: { auth: { user: null }, portalInstitutionalContactEmail: 'institution@example.invalid' },
});
const html = renderToStaticMarkup(React.createElement(Services, { section: 'support', contacts: {}, countries: [] }));
assert.match(html, /Contacto institucional/);
assert.match(html, /mailto:institution@example.invalid/);
assert.doesNotMatch(html, /Os contactos directos ainda não/);
assert.match(html, /utilize o formulário desta página/);
});