Files
frontend/apps/sn/scripts/aged-pipe-list.test.cjs
T

65 lines
3.1 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const test = require('node:test');
const ts = require('typescript');
const directory = path.resolve(__dirname, '../app/(map-layout)/map/components/agedPipe');
const source = fs.readFileSync(path.join(directory, 'agedPipeUtils.ts'), 'utf8');
const compiled = ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS },
}).outputText;
const exportsValue = {};
vm.runInNewContext(compiled, {
exports: exportsValue,
require: (id) => {
if (id.endsWith('/formatDisplayValue')) return { formatDisplayData: (row) => row };
if (id === '../common/table') return { MS_SWAGE_PPL_CODES: [], MS_SWAGE_PPL_USE_CODES: [] };
throw new Error(`Unexpected import: ${id}`);
},
});
const { AGED_PIPE_LIST_HEADLIST: headers, getAgedPipeManagementName: name } = exportsValue;
test('list preserves existing columns and groups agency, installation date and age', () => {
assert.deepEqual(Array.from(headers, (column) => column.id), [
'rowNumber', 'fcltMngNo', 'mngInstNm', 'instlYmd', 'elapsedYears',
'pdmtVl', 'prlgVl', 'usgCd', 'mqltCd',
]);
assert.equal(headers.reduce((total, column) => total + column.widthPercent, 0), 100);
});
test('agency name uses existing API names without changing source codes', () => {
const agencies = [{ mngInstCd: '123', lwrInstNm: '검증기관' }];
const row = { mngInstCd: '123' };
assert.equal(name(row, agencies), '검증기관');
assert.equal(row.mngInstCd, '123');
assert.equal(name({ mng_inst_cd: ' 123 ' }, agencies), '검증기관');
assert.equal(name({ mngInstNm: '원본기관', mngInstCd: '123' }, agencies), '원본기관');
assert.equal(name({ mngInstNm: '-', mngInstCd: '123' }, agencies), '검증기관');
assert.equal(name({ mngInstCd: '999' }, agencies), '999');
assert.equal(name({}, agencies), '-');
});
test('search controls are ordered province, municipality, elapsed years', () => {
const page = fs.readFileSync(path.join(directory, 'AgedPipePopupPage.tsx'), 'utf8');
const panel = page.slice(page.indexOf('<PopupSearchPanel'), page.indexOf('</PopupSearchPanel>'));
const labels = Array.from(panel.matchAll(/<span[^>]*>\s*([^<]+?)\s*<\/span>/g), (match) => match[1].trim());
assert.deepEqual(labels, ['시도', '시군구', '경과년도']);
});
test('aged pipe popup uses the common centered placement without changing its size', () => {
const definitions = fs.readFileSync(path.resolve(__dirname, '../src/features/windowPopup/model/popupDefinitions.ts'), 'utf8');
const exported = {};
vm.runInNewContext(ts.transpileModule(definitions, {
compilerOptions: { module: ts.ModuleKind.CommonJS },
}).outputText, { exports: exported });
const popup = exported.windowPopupDefinitions.agedPipePopup;
assert.equal(popup.width, 1160);
assert.equal(popup.height, 820);
assert.equal(popup.placement ?? 'center', 'center');
assert.equal(popup.alignTop ?? false, false);
assert.equal(popup.offsetLeft ?? 0, 0);
assert.equal(popup.offsetTop ?? 0, 0);
});