UNPKG

@pega/dx-component-builder-sdk

Version:

Utility for building custom UI components

243 lines (183 loc) 8.13 kB
// import { exec } from 'child_process'; const path = require('path'); const fs = require('fs'); const util = require('node:util'); const exec = util.promisify(require('node:child_process').exec); describe('create mapAll clearMap custom local', () => { it('initial delete/cleanup', async () => { const script = `npm run deleteAll Local Y --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); }, 10000); it('npm run create Local text custom', async () => { const fileName = 'MyTestText'; const newFileName = `Pega_DXIL_${fileName}`; const script = `npm run create Field Text ${fileName} "My Test Text" 0.0.1 DXIL "" "My Test Text Description" Pega --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); // want message to contain component name expect(stdout).toContain(newFileName); // don't want message with already exists expect(stdout).not.toContain('already exists'); // check to see file exists // const fileDir = path.resolve(`src/components/${newFileName}`); const createConstellationFile = path.resolve('../../..', path.join(`src/components/custom-constellation/field/${newFileName}`, 'index.tsx') ); const doesConstellationExist = fs.existsSync(createConstellationFile); expect(doesConstellationExist).toBeTruthy(); const createCustomFile = path.resolve('../../..', path.join(`src/components/custom-sdk/field/${newFileName}`, `index.tsx`) ); const doesCustomExist = fs.existsSync(createCustomFile); expect(doesCustomExist).toBeTruthy(); // if (doesExist) { // // remove it // fs.rmdirSync(fileDir, { recursive: true }); // } }, 10000); it('npm run create Local page custom', async () => { const fileName = 'MyTestPage'; const newFileName = `Pega_DXIL_${fileName}`; const script = `npm run create Widget PAGE ${fileName} "My Test Page" 0.0.1 DXIL "" "My Test Page Description" Pega --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); // want message to contain component name expect(stdout).toContain(newFileName); // don't want message with already exists expect(stdout).not.toContain('already exists'); // check to see file exists // const fileDir = path.resolve(`src/components/${newFileName}`); const createConstellationFile = path.resolve('../../..', path.join(`src/components/custom-constellation/widget/${newFileName}`, 'index.tsx') ); const doesConstellationExist = fs.existsSync(createConstellationFile); expect(doesConstellationExist).toBeTruthy(); const createCustomFile = path.resolve('../../..', path.join(`src/components/custom-sdk/widget/${newFileName}`, `index.tsx`) ); const doesCustomExist = fs.existsSync(createCustomFile); expect(doesCustomExist).toBeTruthy(); }, 10000); it('npm run create Local details custom', async () => { const fileName = 'MyTestDetails'; const newFileName = `Pega_DXIL_${fileName}`; const script = `npm run create Template DETAILS ${fileName} "My Test Details" 0.0.1 DXIL "" "My Test Details Description" Pega --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); // want message to contain component name expect(stdout).toContain(newFileName); // don't want message with already exists expect(stdout).not.toContain('already exists'); // check to see file exists // const fileDir = path.resolve(`src/components/${newFileName}`); const createConstellationFile = path.resolve('../../..', path.join(`src/components/custom-constellation/template/${newFileName}`, 'index.tsx') ); const doesConstellationExist = fs.existsSync(createConstellationFile); expect(doesConstellationExist).toBeTruthy(); const createCustomFile = path.resolve('../../..', path.join(`src/components/custom-sdk/template/${newFileName}`, `index.tsx`) ); const doesCustomExist = fs.existsSync(createCustomFile); expect(doesCustomExist).toBeTruthy(); }, 10000); it('npm run mapAll verify in map custom', async () => { const script = `npm run mapAll custom --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); expect(stdout).toContain('Mapping: Pega_DXIL_MyTestText'); expect(stdout).toContain('Mapping: Pega_DXIL_MyTestPage'); expect(stdout).toContain('Mapping: Pega_DXIL_MyTestDetails'); // verify in map const pegaLocalComponentMapPath = path.join(path.resolve('../../..'), 'sdk-local-component-map.js'); const mapData = fs.readFileSync(pegaLocalComponentMapPath, { encoding: 'utf8' }); let isInMap = true; if (mapData.indexOf('Pega_DXIL_MyTestText') < 0) { isInMap = false; } if (mapData.indexOf('PegaDxilMyTestText') < 0) { isInMap = false; } if (mapData.indexOf('Pega_DXIL_MyTestPage') < 0) { isInMap = false; } if (mapData.indexOf('PegaDxilMyTestPage') < 0) { isInMap = false; } if (mapData.indexOf('Pega_DXIL_MyTestDetails') < 0) { isInMap = false; } if (mapData.indexOf('PegaDxilMyTestDetails') < 0) { isInMap = false; } expect(isInMap).toBeTruthy(); // done(); }, 100000); it('npm run clearMap', async () => { const script = `npm run clearMap --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); expect(stdout).toContain('Clear component map'); // map const pegaLocalComponentMapPath = path.join(path.resolve('../../..'), 'sdk-local-component-map.js'); const mapData = fs.readFileSync(pegaLocalComponentMapPath, { encoding: 'utf8' }); // blank map const blankMap = path.join(path.resolve('../../..'), 'node_modules/@pega/react-sdk-components/lib', 'sdk-local-component-map.js'); const blankMapData = fs.readFileSync(blankMap, { encoding: 'utf8' }); expect(mapData).toEqual(blankMapData); }, 10000); it('npm run deleteAll Local verify not in map custom', async () => { const script = `npm run deleteAll Local custom Y --prefix ../../..`; const { stdout, stderr } = await exec(script); // console.log(stdout); expect(stdout).not.toBeNull(); expect(stderr).not.toBeNull(); // pick one const newFileName = 'Pega_DXIL_MyTestText'; // want message to contain component name expect(stdout).toContain(newFileName); // message deleted expect(stdout).toContain('is deleted'); // check to see file exists // verify in not map const pegaLocalComponentMapPath = path.join(path.resolve('../../..'), 'sdk-local-component-map.js'); const mapData = fs.readFileSync(pegaLocalComponentMapPath, { encoding: 'utf8' }); let isInMap = false; if (mapData.indexOf('Pega_DXIL_MyTestText') >= 0) { isInMap = true; } if (mapData.indexOf('PegaDxilMyTestText') >= 0) { isInMap = true; } if (mapData.indexOf('Pega_DXIL_MyTestPage') >= 0) { isInMap = true; } if (mapData.indexOf('PegaDxilMyTestPage') >= 0) { isInMap = true; } if (mapData.indexOf('Pega_DXIL_MyTestDetails') >= 0) { isInMap = true; } if (mapData.indexOf('PegaDxilMyTestDetails') >= 0) { isInMap = true; } expect(isInMap).not.toBeTruthy(); // const fileDir = path.resolve(`src/components/${newFileName}`); // const createFile = path.resolve(path.join(`src/components/${newFileName}`, 'index.tsx')); // const doesExist = fs.existsSync(createFile); // expect(doesExist).not.toBeTruthy(); }, 20000); });