From 547ae180ddc79cd062268586ded06957091b1e01 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Fri, 31 Jan 2025 15:15:16 -0500 Subject: [PATCH] fix: delete .original files --- .../__test__/generic-modification.spec.ts | 36 +- .../DefaultPageLayout.php.original.php | 1225 ----------------- .../snapshots/Notifications.page.original.php | 286 ---- 3 files changed, 18 insertions(+), 1529 deletions(-) delete mode 100644 api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/DefaultPageLayout.php.original.php delete mode 100644 api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/Notifications.page.original.php 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 @@ - -/dev/null &"); - -function annotate($text) {echo "\n\n";} -?> - -lang=""> - -<?=_var($var,'NAME')?>/<?=_var($myPage,'name')?> - - - - - - - - -"> -"> -"> -"> -"> -"> -"> -"> - - - - - - - - - - - -
- - - -"; -if ($themes2) echo "
"; -foreach ($buttons as $button) { - annotate($button['file']); - // include page specific stylesheets (if existing) - $css = "/{$button['root']}/sheets/{$button['name']}"; - $css_stock = "$css.css"; - $css_theme = "$css-$theme.css"; - if (is_file($docroot.$css_stock)) echo '',"\n"; - if (is_file($docroot.$css_theme)) echo '',"\n"; - // create page content - eval('?>'.parse_text($button['text'])); -} -unset($buttons,$button); - -// Build page content -// Reload page every X minutes during extended viewing? -if (isset($myPage['Load']) && $myPage['Load']>0) echo "\n\n"; -echo "
"; -$tab = 1; -$pages = []; -if (!empty($myPage['text']) && page_enabled($myPage)) $pages[$myPage['name']] = $myPage; -if (_var($myPage,'Type')=='xmenu') $pages = array_merge($pages, find_pages($myPage['name'])); -if (isset($myPage['Tabs'])) $display['tabs'] = strtolower($myPage['Tabs'])=='true' ? 0 : 1; -$tabbed = $display['tabs']==0 && count($pages)>1; - -foreach ($pages as $page) { - $close = false; - if (isset($page['Title'])) { - eval("\$title=\"{$page['Title']}\";"); - if ($tabbed) { - echo "
"; - $close = true; - } else { - if ($tab==1) echo "
"; - echo "
"; - echo tab_title($title,$page['root'],_var($page,'Tag',false)); - echo "
"; - } - $tab++; - } - if (isset($page['Type']) && $page['Type']=='menu') { - $pgs = find_pages($page['name']); - foreach ($pgs as $pg) { - @eval("\$title=\"{$pg['Title']}\";"); - $icon = _var($pg,'Icon',""); - if (substr($icon,-4)=='.png') { - $root = $pg['root']; - if (file_exists("$docroot/$root/images/$icon")) { - $icon = ""; - } elseif (file_exists("$docroot/$root/$icon")) { - $icon = ""; - } else { - $icon = ""; - } - } elseif (substr($icon,0,5)=='icon-') { - $icon = ""; - } elseif ($icon[0]!='<') { - if (substr($icon,0,3)!='fa-') $icon = "fa-$icon"; - $icon = ""; - } - echo ""; - } - } - // create list of nchan scripts to be started - if (isset($page['Nchan'])) nchan_merge($page['root'], $page['Nchan']); - annotate($page['file']); - // include page specific stylesheets (if existing) - $css = "/{$page['root']}/sheets/{$page['name']}"; - $css_stock = "$css.css"; - $css_theme = "$css-$theme.css"; - if (is_file($docroot.$css_stock)) echo '',"\n"; - if (is_file($docroot.$css_theme)) echo '',"\n"; - // create page content - empty($page['Markdown']) || $page['Markdown']=='true' ? eval('?>'.Markdown(parse_text($page['text']))) : eval('?>'.parse_text($page['text'])); - if ($close) echo "
"; -} -if (count($pages)) { - $running = file_exists($nchan_pid) ? file($nchan_pid,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : []; - $start = array_diff($nchan, $running); // returns any new scripts to be started - $stop = array_diff($running, $nchan); // returns any old scripts to be stopped - $running = array_merge($start, $running); // update list of current running nchan scripts - // start nchan scripts which are new - foreach ($start as $row) { - $script = explode(':',$row)[0]; - exec("$docroot/$script &>/dev/null &"); - } - // stop nchan scripts with the :stop option - foreach ($stop as $row) { - [$script,$opt] = my_explode(':',$row); - if ($opt == 'stop') { - exec("pkill -f $docroot/$script &>/dev/null &"); - array_splice($running,array_search($row,$running),1); - } - } - if (count($running)) file_put_contents($nchan_pid,implode("\n",$running)."\n"); else @unlink($nchan_pid); -} -unset($pages,$page,$pgs,$pg,$icon,$nchan,$running,$start,$stop,$row,$script,$opt,$nchan_run); -?> -
-
-
- -'; -$progress = (_var($var,'fsProgress')!='') ? "•{$var['fsProgress']}" : ""; -switch (_var($var,'fsState')) { -case 'Stopped': - echo " ",_('Array Stopped'),"$progress"; break; -case 'Starting': - echo " ",_('Array Starting'),"$progress"; break; -case 'Stopping': - echo " ",_('Array Stopping'),"$progress"; break; -default: - echo " ",_('Array Started'),"$progress"; break; -} -echo ""; -echo "Unraid® webGui ©2024, Lime Technology, Inc."; -echo " "._('manual').""; -echo "
"; -?> - - - diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/Notifications.page.original.php b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/Notifications.page.original.php deleted file mode 100644 index 22e485de7..000000000 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/snapshots/Notifications.page.original.php +++ /dev/null @@ -1,286 +0,0 @@ -Menu="UserPreferences" -Type="xmenu" -Title="Notification Settings" -Icon="icon-notifications" -Tag="phone-square" ---- - - - -
- - - - - - - - - - - - - -_(Notifications display)_: -: - -:notifications_display_help: - -_(Display position)_: -: - -:notifications_display_position_help: - -_(Auto-close)_ (_(seconds)_): -: _(a value of zero means no automatic closure)_ - -:notifications_auto_close_help: - -_(Date format)_: -: - -:notifications_date_format_help: - -_(Time format)_: -: - -:notifications_time_format_help: - -_(Store notifications to flash)_: -: - -:notifications_store_flash_help: - -_(System notifications)_: -: - -:notifications_system_help: - -_(Unraid OS update notification)_: -: - -:notifications_os_update_help: - -_(Plugins update notification)_: -: - -:notifications_plugins_update_help: - -_(Docker update notification)_: -: - -:notifications_docker_update_help: - -_(Language update notification)_: -: - -_(Array status notification)_: -: - -:notifications_array_status_help: - - -: - - -: - - -: - - -: - - -: - -:notifications_agent_selection_help: - -_(Notification entity)_: -: _(Notices)_ - >_(Browser)_   - >_(Email)_   - >_(Agents)_   - -  -: _(Warnings)_ - >_(Browser)_   - >_(Email)_   - >_(Agents)_   - -  -: _(Alerts)_ - >_(Browser)_   - >_(Email)_   - >_(Agents)_   - -:notifications_classification_help: - - -: -