From e04246bf58a82fa603447d74e33c6234ba38e2e7 Mon Sep 17 00:00:00 2001 From: tzAcee Date: Sat, 23 Mar 2024 16:20:08 +0100 Subject: [PATCH] finish replacement tests --- .../ui-test/file-content-replacement.test.ts | 233 ++++++++++++++++++ src/test/ui-test/utils/class-helper.ts | 18 ++ 2 files changed, 251 insertions(+) diff --git a/src/test/ui-test/file-content-replacement.test.ts b/src/test/ui-test/file-content-replacement.test.ts index 6041320..08325e9 100644 --- a/src/test/ui-test/file-content-replacement.test.ts +++ b/src/test/ui-test/file-content-replacement.test.ts @@ -63,86 +63,319 @@ describe('File-content replacement test suite', () => { it('[header file content] - HEADERFILENAME once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*HEADERFILENAME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = fileName; + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - SOURCEFILENAME once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*SOURCEFILENAME*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = fileName.replace(".h", ".cpp"); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - CLASSNAMEUPPER once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CLASSNAMEUPPER*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className.toUpperCase(); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - CLASSNAMELOWER once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CLASSNAMELOWER*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className.toLowerCase(); + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - CLASSNAMECAPI once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CLASSNAMECAPI*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className[0].toUpperCase() + className.substring(1); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - CLASSNAME once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CLASSNAME*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[header file content] - CURRENTDATETIME once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CURRENTDATETIME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const currentDateTimeString = new Date().toLocaleString(); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + + try + { + assert(content == currentDateTimeString); + } catch(e) + { + const diff = Math.abs(new Date(content).getTime() - new Date(currentDateTimeString).getTime()); + console.log("time diff", diff); + assert(diff < 1000); + } }) it('[header file content] - CURRENTDATE once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CURRENTDATE*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const currentDateString = new Date().toLocaleDateString(); + + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + + assert(content == currentDateString); }) it('[header file content] - CURRENTTIME once', async () => { + await ext_settings.setHeaderFileContentPreset("{{*CURRENTTIME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const currentTimeString = new Date().toLocaleTimeString(); + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + + const trimmedContent = content.trim().replace(/\u{2007}/gu, ' ').replace(/\u{202F}/gu, ' '); + const trimmedCurrentTimeString = currentTimeString.trim().replace(/\u{2007}/gu, ' ').replace(/\u{202F}/gu, ' '); + + assert(trimmedContent == trimmedCurrentTimeString); }) it('[header file content] - combination', async () => { + + await ext_settings.setHeaderFileContentPreset("{{*CLASSNAMECAPI*}}-{{*CLASSNAME*}}-{{*HEADERFILENAME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const fileName = className + ".h"; + const path = workSpaceDir + "/" + fileName; + const capitalized = className[0].toUpperCase() + className.substring(1); + const expectedContent = capitalized + "-"+className+"-"+fileName; + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) // source file content tests: it('[source file content] - HEADERFILENAME multiple', async () => { + await ext_settings.setSourceFileContentPreset("{{*HEADERFILENAME*}}-{{*HEADERFILENAME*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = fileName.replace(".cpp", ".h")+"-"+fileName.replace(".cpp", ".h"); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - HEADERFILENAME once', async () => { + await ext_settings.setSourceFileContentPreset("{{*HEADERFILENAME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = fileName.replace(".cpp", ".h"); + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - SOURCEFILENAME once', async () => { + await ext_settings.setSourceFileContentPreset("{{*SOURCEFILENAME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = fileName; + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - CLASSNAMEUPPER once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CLASSNAMEUPPER*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className.toUpperCase(); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - CLASSNAMELOWER once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CLASSNAMELOWER*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className.toLowerCase(); + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - CLASSNAMECAPI once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CLASSNAMECAPI*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className[0].toUpperCase() + className.substring(1); + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - CLASSNAME once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CLASSNAME*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const expectedContent = className; + + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)); }) it('[source file content] - CURRENTDATETIME once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CURRENTDATETIME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const currentDateTimeString = new Date().toLocaleString(); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + + try + { + assert(content == currentDateTimeString); + } catch(e) + { + assert(Math.abs(new Date(content).getTime() - new Date(currentDateTimeString).getTime()) < 10); + } }) it('[source file content] - CURRENTDATE once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CURRENTDATE*}}"); + const className = "testClass"; + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const currentDateString = new Date().toLocaleDateString(); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + + assert(content == currentDateString); }) it('[source file content] - CURRENTTIME once', async () => { + await ext_settings.setSourceFileContentPreset("{{*CURRENTTIME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + const currentTimeString = new Date().toLocaleTimeString(); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + + const content = await ClassHelper.fileExistsGetContent(path, className); + const trimmedContent = content.trim().replace(/\u{2007}/gu, ' ').replace(/\u{202F}/gu, ' '); + const trimmedCurrentTimeString = currentTimeString.trim().replace(/\u{2007}/gu, ' ').replace(/\u{202F}/gu, ' '); + + assert(trimmedContent == trimmedCurrentTimeString); }) it('[source file content] - combination', async () => { + + await ext_settings.setSourceFileContentPreset("{{*CLASSNAMECAPI*}}-{{*CLASSNAME*}}-{{*SOURCEFILENAME*}}"); + const className = "testClass"; + + await cppCreatorExt.openExtPromptByCmdPallette(className); + + const fileName = className + ".cpp"; + const path = workSpaceDir + "/" + fileName; + const capitalized = className[0].toUpperCase() + className.substring(1); + const expectedContent = capitalized + "-"+className+"-"+fileName; + assert(await ClassHelper.fileExistsWithContent(className, path, expectedContent, false)) }) }); \ No newline at end of file diff --git a/src/test/ui-test/utils/class-helper.ts b/src/test/ui-test/utils/class-helper.ts index 62ea51b..95dd349 100644 --- a/src/test/ui-test/utils/class-helper.ts +++ b/src/test/ui-test/utils/class-helper.ts @@ -18,6 +18,24 @@ export class ClassHelper return true; } + static async fileExistsGetContent(path: string, className: string) + { + assert(await this.fileExists(path)); + + let fileContent = ""; + + await until(()=>{ + fileContent = fs.readFileSync(path).toString(); + return fileContent != ""; + }, 2000); + + const pathWithoutFileName = path.substring(0, path.lastIndexOf("/")); + const expNotif = `Your class "${className}" has been created! (@${pathWithoutFileName})`; + assert(await VSController.isNotificationSent(expNotif)); + + return fileContent; + } + static async fileExistsWithContent(className: string, path: string, content: string, deleteAfterwards: boolean) { assert(content != "");