From f26ee9c69d98b9208f709e0c7aa284755708adbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 30 Nov 2022 17:45:58 +0100 Subject: [PATCH] Faster theming tests, better colours comparison and properly follow admin theming changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/theming/appinfo/routes.php | 5 + .../lib/Controller/ThemingController.php | 21 +++ .../lib/Controller/UserThemeController.php | 1 + .../theming/lib/Service/BackgroundService.php | 2 +- apps/theming/lib/ThemingDefaults.php | 12 +- apps/theming/src/AdminTheming.vue | 6 +- .../src/components/admin/FileInputField.vue | 6 +- cypress/e2e/theming/admin-settings.cy.ts | 170 ++++++++++-------- cypress/e2e/theming/themingUtils.ts | 75 ++++++++ cypress/e2e/theming/user-background.cy.ts | 10 +- cypress/support/commands.ts | 33 +++- dist/theming-admin-theming.js | 4 +- dist/theming-admin-theming.js.map | 2 +- package-lock.json | 17 +- package.json | 1 + 15 files changed, 257 insertions(+), 108 deletions(-) create mode 100644 cypress/e2e/theming/themingUtils.ts diff --git a/apps/theming/appinfo/routes.php b/apps/theming/appinfo/routes.php index eceb447620d..8647ae135a8 100644 --- a/apps/theming/appinfo/routes.php +++ b/apps/theming/appinfo/routes.php @@ -39,6 +39,11 @@ return [ 'url' => '/ajax/undoChanges', 'verb' => 'POST' ], + [ + 'name' => 'Theming#undoAll', + 'url' => '/ajax/undoAllChanges', + 'verb' => 'POST' + ], [ 'name' => 'Theming#uploadImage', 'url' => '/ajax/uploadImage', diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 2cac9a345a4..8868208197d 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -275,6 +275,27 @@ class ThemingController extends Controller { ); } + /** + * Revert all theming settings to their default values + * @AuthorizedAdminSetting(settings=OCA\Theming\Settings\Admin) + * + * @return DataResponse + * @throws NotPermittedException + */ + public function undoAll(): DataResponse { + $this->themingDefaults->undoAll(); + + return new DataResponse( + [ + 'data' => + [ + 'message' => $this->l10n->t('Saved'), + ], + 'status' => 'success' + ] + ); + } + /** * @PublicPage * @NoCSRFRequired diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php index 112a8a23638..a227e72d998 100644 --- a/apps/theming/lib/Controller/UserThemeController.php +++ b/apps/theming/lib/Controller/UserThemeController.php @@ -186,6 +186,7 @@ class UserThemeController extends OCSController { $this->backgroundService->setFileBackground($value); break; case BackgroundService::BACKGROUND_DEFAULT: + // Delete both background and color keys $this->backgroundService->setDefaultBackground(); break; default: diff --git a/apps/theming/lib/Service/BackgroundService.php b/apps/theming/lib/Service/BackgroundService.php index a3af56b08f8..4879ad1cbad 100644 --- a/apps/theming/lib/Service/BackgroundService.php +++ b/apps/theming/lib/Service/BackgroundService.php @@ -160,7 +160,7 @@ class BackgroundService { public function setDefaultBackground(): void { $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_image'); - $this->config->setUserValue($this->userId, Application::APP_ID, 'background_color', $this->themingDefaults->getDefaultColorPrimary()); + $this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_color'); } /** diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 881a27f9936..afec58dc3a3 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -439,18 +439,26 @@ class ThemingDefaults extends \OC_Defaults { * @param string $setting * @param string $value */ - public function set($setting, $value) { + public function set($setting, $value): void { $this->config->setAppValue('theming', $setting, $value); $this->increaseCacheBuster(); } + /** + * Revert all settings to the default value + */ + public function undoAll(): void { + $this->config->deleteAppValues('theming'); + $this->increaseCacheBuster(); + } + /** * Revert settings to the default value * * @param string $setting setting which should be reverted * @return string default value */ - public function undo($setting) { + public function undo($setting): string { $this->config->deleteAppValue('theming', $setting); $this->increaseCacheBuster(); diff --git a/apps/theming/src/AdminTheming.vue b/apps/theming/src/AdminTheming.vue index bb26dcc0f30..f922143e04d 100644 --- a/apps/theming/src/AdminTheming.vue +++ b/apps/theming/src/AdminTheming.vue @@ -58,15 +58,15 @@ -
-