From ae12a73c851d2830406ace9d6ebd77ab75faa51c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 14 Dec 2023 17:58:13 +0100 Subject: [PATCH] fix(theming): Make dark theme accessible and add unit test Signed-off-by: Ferdinand Thiessen --- apps/theming/lib/Themes/DarkTheme.php | 25 ++-- apps/theming/tests/Themes/DarkThemeTest.php | 143 ++++++++++++++++++++ 2 files changed, 156 insertions(+), 12 deletions(-) create mode 100644 apps/theming/tests/Themes/DarkThemeTest.php diff --git a/apps/theming/lib/Themes/DarkTheme.php b/apps/theming/lib/Themes/DarkTheme.php index d33f13dc579..0fed06e2225 100644 --- a/apps/theming/lib/Themes/DarkTheme.php +++ b/apps/theming/lib/Themes/DarkTheme.php @@ -60,10 +60,10 @@ class DarkTheme extends DefaultTheme implements ITheme { $colorBoxShadow = $this->util->darken($colorMainBackground, 70); $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow)); - $colorError = '#ee312b'; - $colorWarning = '#c28900'; - $colorSuccess = '#36914e'; - $colorInfo = '#007bbd'; + $colorError = '#FF5252'; + $colorWarning = '#FFCC00'; + $colorSuccess = '#50BB50'; + $colorInfo = '#00AEFF'; return array_merge( $defaultVariables, @@ -72,6 +72,7 @@ class DarkTheme extends DefaultTheme implements ITheme { '--color-main-text' => $colorMainText, '--color-main-background' => $colorMainBackground, '--color-main-background-rgb' => $colorMainBackgroundRGB, + '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .85)', '--color-scrollbar' => $this->util->lighten($colorMainBackground, 15), @@ -84,26 +85,26 @@ class DarkTheme extends DefaultTheme implements ITheme { '--color-text-maxcontrast' => $colorTextMaxcontrast, '--color-text-maxcontrast-default' => $colorTextMaxcontrast, - '--color-text-maxcontrast-background-blur' => $this->util->lighten($colorTextMaxcontrast, 2), + '--color-text-maxcontrast-background-blur' => $this->util->lighten($colorTextMaxcontrast, 6), '--color-text-light' => 'var(--color-main-text)', // deprecated '--color-text-lighter' => 'var(--color-text-maxcontrast)', // deprecated '--color-error' => $colorError, '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)), - '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 85), - '--color-error-text' => $this->util->lighten($colorError, 12), + '--color-error-hover' => $this->util->lighten($colorError, 10), + '--color-error-text' => $this->util->lighten($colorError, 10), '--color-warning' => $colorWarning, '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)), - '--color-warning-hover' => $this->util->mix($colorWarning, $colorMainBackground, 60), + '--color-warning-hover' => $this->util->lighten($colorWarning, 10), '--color-warning-text' => $colorWarning, '--color-success' => $colorSuccess, '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)), - '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 85), - '--color-success-text' => $this->util->lighten($colorSuccess, 6), + '--color-success-hover' => $this->util->lighten($colorSuccess, 10), + '--color-success-text' => $colorSuccess, '--color-info' => $colorInfo, '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)), - '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 85), - '--color-info-text' => $this->util->lighten($colorInfo, 9), + '--color-info-hover' => $this->util->lighten($colorInfo, 10), + '--color-info-text' => $colorInfo, // used for the icon loading animation '--color-loading-light' => '#777', diff --git a/apps/theming/tests/Themes/DarkThemeTest.php b/apps/theming/tests/Themes/DarkThemeTest.php new file mode 100644 index 00000000000..1a50e08d0f5 --- /dev/null +++ b/apps/theming/tests/Themes/DarkThemeTest.php @@ -0,0 +1,143 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OCA\Theming\Tests\Themes; + +use OCA\Theming\AppInfo\Application; +use OCA\Theming\ImageManager; +use OCA\Theming\ITheme; +use OCA\Theming\Service\BackgroundService; +use OCA\Theming\Themes\DarkTheme; +use OCA\Theming\ThemingDefaults; +use OCA\Theming\Util; +use OCP\App\IAppManager; +use OCP\Files\IAppData; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\IUserSession; +use PHPUnit\Framework\MockObject\MockObject; + +class DarkThemeTest extends AccessibleThemeTestCase { + /** @var ThemingDefaults|MockObject */ + private $themingDefaults; + /** @var IUserSession|MockObject */ + private $userSession; + /** @var IURLGenerator|MockObject */ + private $urlGenerator; + /** @var ImageManager|MockObject */ + private $imageManager; + /** @var IConfig|MockObject */ + private $config; + /** @var IL10N|MockObject */ + private $l10n; + /** @var IAppManager|MockObject */ + private $appManager; + + protected function setUp(): void { + $this->themingDefaults = $this->createMock(ThemingDefaults::class); + $this->userSession = $this->createMock(IUserSession::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->imageManager = $this->createMock(ImageManager::class); + $this->config = $this->createMock(IConfig::class); + $this->l10n = $this->createMock(IL10N::class); + $this->appManager = $this->createMock(IAppManager::class); + + $this->util = new Util( + $this->config, + $this->appManager, + $this->createMock(IAppData::class), + $this->imageManager + ); + + $this->themingDefaults + ->expects($this->any()) + ->method('getColorPrimary') + ->willReturn('#0082c9'); + + $this->themingDefaults + ->expects($this->any()) + ->method('getDefaultColorPrimary') + ->willReturn('#0082c9'); + + $this->themingDefaults + ->expects($this->any()) + ->method('getBackground') + ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); + + $this->l10n + ->expects($this->any()) + ->method('t') + ->willReturnCallback(function ($text, $parameters = []) { + return vsprintf($text, $parameters); + }); + + $this->urlGenerator + ->expects($this->any()) + ->method('imagePath') + ->willReturnCallback(function ($app = 'core', $filename = '') { + return "/$app/img/$filename"; + }); + + $this->theme = new DarkTheme( + $this->util, + $this->themingDefaults, + $this->userSession, + $this->urlGenerator, + $this->imageManager, + $this->config, + $this->l10n, + $this->appManager, + ); + + parent::setUp(); + } + + + public function testGetId() { + $this->assertEquals('dark', $this->theme->getId()); + } + + public function testGetType() { + $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType()); + } + + public function testGetTitle() { + $this->assertEquals('Dark theme', $this->theme->getTitle()); + } + + public function testGetEnableLabel() { + $this->assertEquals('Enable dark theme', $this->theme->getEnableLabel()); + } + + public function testGetDescription() { + $this->assertEquals('A dark theme to ease your eyes by reducing the overall luminosity and brightness.', $this->theme->getDescription()); + } + + public function testGetMediaQuery() { + $this->assertEquals('(prefers-color-scheme: dark)', $this->theme->getMediaQuery()); + } + + public function testGetCustomCss() { + $this->assertEquals('', $this->theme->getCustomCss()); + } +} -- 2.39.5