diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts index 30242d9e2..b7fa13ba9 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts @@ -1,11 +1,12 @@ import { Logger } from '@nestjs/common'; import { readFile, writeFile } from 'fs/promises'; import { basename, resolve } from 'path'; + import { describe, expect, test } from 'vitest'; +import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification'; import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification'; import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification'; -import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification'; import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification'; interface ModificationTestCase { @@ -16,40 +17,41 @@ interface ModificationTestCase { const testCases: ModificationTestCase[] = [ { ModificationClass: DefaultPageLayoutModification, - fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/DefaultPageLayout.php', + fileUrl: + 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/DefaultPageLayout.php', }, { ModificationClass: NotificationsPageModification, - fileUrl: "https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/Notifications.page", + fileUrl: + 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/Notifications.page', }, { - fileUrl: 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/.login.php', + fileUrl: + 'https://github.com/unraid/webgui/raw/refs/heads/master/emhttp/plugins/dynamix/include/.login.php', ModificationClass: SSOFileModification, - } + }, ]; async function testModification(testCase: ModificationTestCase) { // First download the file from Github const fileName = basename(testCase.fileUrl); - - const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`); - const fileContent = await fetch(testCase.fileUrl).then(response => response.text()); - await writeFile(path, fileContent); - expect(fileContent.length).toBeGreaterThan(0); + const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`); + const originalContent = await fetch(testCase.fileUrl).then((response) => response.text()); + await writeFile(path, originalContent); + + expect(originalContent.length).toBeGreaterThan(0); const logger = new Logger(); const patcher = await new testCase.ModificationClass(logger); // @ts-ignore - Ignore for testing purposes patcher.filePath = path; - + // @ts-ignore - Ignore for testing purposes const patch = await patcher.generatePatch(); // Test patch matches snapshot - await expect(patch).toMatchFileSnapshot( - `../patches/${patcher.id}.patch` - ); + await expect(patch).toMatchFileSnapshot(`../patches/${patcher.id}.patch`); // Apply patch and verify modified file await patcher.apply(); @@ -60,13 +62,11 @@ async function testModification(testCase: ModificationTestCase) { // Rollback and verify original state await patcher.rollback(); const revertedContent = await readFile(path, 'utf-8'); - await expect(revertedContent).toMatchFileSnapshot( - `snapshots/${fileName}.original.php` - ); + await expect(revertedContent).toMatch(originalContent); } describe('File modifications', () => { - test.each(testCases)('$name modifier correctly applies to fresh install', async (testCase) => { + test.each(testCases)(`$fileUrl modifier correctly applies to fresh install`, async (testCase) => { await testModification(testCase); }); }); diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/DefaultPageLayout.php.original.php b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/DefaultPageLayout.php.original.php deleted file mode 100644 index 6cb750a5c..000000000 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/DefaultPageLayout.php.original.php +++ /dev/null @@ -1,1225 +0,0 @@ - - -$display['font'] = filter_var($_COOKIE['fontSize'] ?? $display['font'] ?? '',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION); -$theme = strtok($display['theme'],'-'); -$header = $display['header']; -$backgnd = $display['background']; -$themes1 = in_array($theme,['black','white']); -$themes2 = in_array($theme,['gray','azure']); -$config = "/boot/config"; -$entity = $notify['entity'] & 1 == 1; -$alerts = '/tmp/plugins/my_alerts.txt'; - -// adjust the text color in docker log window -$fgcolor = in_array($theme,['white','azure']) ? '#1c1c1c' : '#f2f2f2'; -exec("sed -ri 's/^\.logLine\{color:#......;/.logLine{color:$fgcolor;/' $docroot/plugins/dynamix.docker.manager/log.htm >/dev/null &"); - -function annotate($text) {echo "\n\n";} -?> - -lang="=strtok($locale,'_')?:'en'?>"> -
-