51 lines
3 KiB
JavaScript
51 lines
3 KiB
JavaScript
// Run: node --test ide/ui/js/new-hub.test.mjs (new-hub.js imports ui.js, so its source is checked here, and its entries with a stubbed module)
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const src = readFileSync(join(here, 'new-hub.js'), 'utf8')
|
|
.replace("import { chooser, t } from './ui.js';", 'const chooser = () => {}; const t = (k) => k;');
|
|
const { hubEntries, GROUPS } = await import('data:text/javascript;base64,' + Buffer.from(src).toString('base64'));
|
|
|
|
const calls = [];
|
|
const app = (caps, windows = {}) => ({
|
|
project: { capabilities: caps }, tree: { targetDir: () => '', newFile: (...a) => calls.push(['newFile', ...a]), newDirectory: () => calls.push(['newDirectory']) },
|
|
actions: { run: (id) => calls.push(['action', id]) }, showTool: () => {}, ...windows,
|
|
});
|
|
const ids = (a) => hubEntries(a).map((e) => e.id);
|
|
|
|
test('a plain project only gets the generic entries', () => {
|
|
assert.deepEqual(ids(app({})), ['Project/File…', 'Project/Folder…', 'Project/PHP class…']);
|
|
});
|
|
|
|
test('a read-only project gets none of the file entries', () => {
|
|
assert.deepEqual(ids(app({ readOnly: true })), []);
|
|
});
|
|
|
|
test('a Symfony project gets the Symfony, Doctrine and security entries its windows allow', () => {
|
|
const symfonyConsole = { load: async () => calls.push(['load']), select: (n) => calls.push(['select', n]) };
|
|
const a = app({ console: 'bin/console' }, { symfonyConsole, doctrine: {}, symfonyForms: {}, validationPanel: {}, scripts: {}, translations: {} });
|
|
const got = ids(a);
|
|
for (const want of ['Symfony/Controller…', 'Symfony/Command…', 'Symfony/Twig template…', 'Symfony/Form type…', 'Symfony/Validation constraint…', 'Doctrine/Entity…', 'Doctrine/Migration (diff)',
|
|
'Security/Voter…', 'Security/User…', 'Scripts and tests/Script…', 'Scripts and tests/Castor task…', 'Translations/Translation key…']) assert.ok(got.includes(want), want);
|
|
assert.ok(!got.some((id) => id.startsWith('API and HTTP/'))); // no API Platform / HTTP client window here
|
|
for (const e of hubEntries(a)) assert.ok(GROUPS.includes(e.group), e.id);
|
|
});
|
|
|
|
test('entries call the existing actions and commands', async () => {
|
|
calls.length = 0;
|
|
const symfonyConsole = { load: async () => calls.push(['load']), select: (n) => calls.push(['select', n]) };
|
|
const a = app({ console: 'bin/console' }, { symfonyConsole, doctrine: {} });
|
|
const run = (id) => hubEntries(a).find((e) => e.id === id).run();
|
|
await run('Doctrine/Entity…');
|
|
await run('Symfony/Controller…');
|
|
await run('Symfony/Command…');
|
|
assert.deepEqual(calls, [['action', 'doctrineNewEntity'], ['load'], ['select', 'make:controller'], ['action', 'newSymfonyCommand']]);
|
|
});
|
|
|
|
test('a Laravel project has no Symfony entries', () => {
|
|
assert.ok(!ids(app({ console: 'artisan' }, { symfonyConsole: {} })).some((id) => id.startsWith('Symfony/') || id.startsWith('Security/')));
|
|
});
|