Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(tests): Adjust theming test for new splitted background and prima…
…ry colors

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed May 21, 2024
commit 538a04968a24f645b12ca2647952a5b73ebc3eac
6 changes: 3 additions & 3 deletions apps/settings/src/components/AdminAI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ export default {

.draggable__number {
border-radius: 20px;
border: 2px solid var(--color-primary-default);
color: var(--color-primary-default);
padding: 0px 7px;
border: 2px solid var(--color-primary-element);
color: var(--color-primary-element);
padding: 0px 7px;
margin-right: 3px;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/theming/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
--primary-invert-if-bright: no;
--primary-invert-if-dark: invert(100%);
--color-primary: #00679e;
--color-primary-default: #0082c9;
--color-primary-text: #ffffff;
--color-primary-hover: #3285b1;
--color-primary-light: #e5eff5;
Expand All @@ -87,4 +86,5 @@
--gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
--color-background-plain: #00679e;
--color-background-plain-text: #ffffff;
--image-background: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
}
5 changes: 3 additions & 2 deletions apps/theming/lib/Service/BackgroundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
use OCP\PreConditionNotMetException;

class BackgroundService {
public const DEFAULT_COLOR = '#0082c9';
public const DEFAULT_COLOR = '#00679e';
public const DEFAULT_BACKGROUND_COLOR = '#00679e';

/**
Expand Down Expand Up @@ -300,9 +300,10 @@ public function setGlobalBackground($path): string|null {
$meanColor = $this->calculateMeanColor($image);
if ($meanColor !== false) {
$this->config->setAppValue(Application::APP_ID, 'background_color', $meanColor);

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCP\IConfig::setAppValue has been marked as deprecated
return $meanColor;
}
return $meanColor;
}
return null;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions apps/theming/lib/Themes/CommonThemeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected function generatePrimaryVariables(string $colorMainBackground, string
'--primary-invert-if-dark' => $this->util->invertTextColor($colorPrimaryElement) ? 'no' : 'invert(100%)',

'--color-primary' => $this->primaryColor,
'--color-primary-default' => $this->defaultPrimaryColor,
'--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
'--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60),
'--color-primary-light' => $colorPrimaryLight,
Expand Down Expand Up @@ -105,7 +104,7 @@ protected function generateGlobalBackgroundVariables(): array {
if ($this->imageManager->hasImage($image)) {
$imageUrl = $this->imageManager->getImageUrl($image);
$variables["--image-$image"] = "url('" . $imageUrl . "')";
} else if ($image === 'background') {
} elseif ($image === 'background') {
// Apply default background if nothing is configured
$variables['--image-background'] = "url('" . $this->themingDefaults->getBackground() . "')";
}
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function elementColor($color, ?bool $brightBackground = null, ?string $ba
$contrast = $this->colorContrast($color, $blurredBackground);

// Min. element contrast is 3:1 but we need to keep hover states in mind -> min 3.2:1
$minContrast = $highContrast ? 5.5 : 3.2;
$minContrast = $highContrast ? 5.6 : 3.2;

while ($contrast < $minContrast && $iteration++ < 100) {
$hsl = Color::hexToHsl($color);
Expand Down
4 changes: 4 additions & 0 deletions apps/theming/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"color-element-dark",
"logo",
"background",
"background-text",
"background-plain",
"background-default",
"logoheader",
Expand Down Expand Up @@ -99,6 +100,9 @@
"background": {
"type": "string"
},
"background-text": {
"type": "string"
},
"background-plain": {
"type": "boolean"
},
Expand Down
14 changes: 10 additions & 4 deletions apps/theming/tests/Settings/PersonalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Theming\AppInfo\Application;
use OCA\Theming\ImageManager;
use OCA\Theming\ITheme;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\Service\ThemesService;
use OCA\Theming\Settings\Personal;
use OCA\Theming\Themes\DarkHighContrastTheme;
Expand Down Expand Up @@ -116,18 +117,23 @@ public function testGetForm(string $enforcedTheme, $themesState) {
->with('enforce_theme', '')
->willReturn($enforcedTheme);

$this->config->expects($this->once())
$this->config->expects($this->any())
->method('getUserValue')
->with('admin', 'core', 'apporder')
->willReturn('[]');
->willReturnMap([
['admin', 'core', 'apporder', '[]', '[]'],
['admin', 'theming', 'background_image', BackgroundService::BACKGROUND_DEFAULT],
]);

$this->appManager->expects($this->once())
->method('getDefaultAppForUser')
->willReturn('forcedapp');

$this->initialStateService->expects($this->exactly(4))
$this->initialStateService->expects($this->exactly(7))
->method('provideInitialState')
->withConsecutive(
['shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS],
['themingDefaults'],
['userBackgroundImage'],
['themes', $themesState],
['enforceTheme', $enforcedTheme],
['isUserThemingDisabled', false],
Expand Down
74 changes: 11 additions & 63 deletions apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,90 +455,46 @@ public function dataGetColorPrimary() {
'with fallback default' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '',
'userBackgroundColor' => '',
'userPrimaryColor' => '',
'expected' => BackgroundService::DEFAULT_COLOR,
],
'with custom admin background' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '#123',
'userBackgroundColor' => '',
'userPrimaryColor' => '',
'expected' => '#123',
],
'with custom invalid admin background' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => 'invalid-name',
'userBackgroundColor' => '',
'userPrimaryColor' => '',
'expected' => BackgroundService::DEFAULT_COLOR,
],
'with custom admin primary' => [
'disableTheming' => 'no',
'primaryColor' => '#aaa',
'backgroundColor' => '',
'userBackgroundColor' => '',
'userPrimaryColor' => '',
'expected' => '#aaa',
],
'with custom invalid admin primary' => [
'disableTheming' => 'no',
'primaryColor' => 'invalid',
'backgroundColor' => '',
'userBackgroundColor' => '',
'userPrimaryColor' => '',
'expected' => BackgroundService::DEFAULT_COLOR,
],
'with custom user background' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '',
'userBackgroundColor' => '#456',
'userPrimaryColor' => '#456',
'expected' => '#456',
],
'with custom invalid user primary' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '',
'userBackgroundColor' => '',
'userPrimaryColor' => 'invalid-name',
'expected' => BackgroundService::DEFAULT_COLOR,
],
'with custom user primary' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '',
'userBackgroundColor' => '',
'userPrimaryColor' => '#bbb',
'expected' => '#bbb',
],
'with custom invalid user background' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '',
'userBackgroundColor' => 'invalid-name',
'userPrimaryColor' => '',
'expected' => BackgroundService::DEFAULT_COLOR,
],
'with custom admin and user background' => [
'disableTheming' => 'no',
'primaryColor' => '',
'backgroundColor' => '#123',
'userBackgroundColor' => '#456',
'userPrimaryColor' => '#456',
'expected' => '#456',
'with disabled user theming primary' => [
'disableTheming' => 'yes',
'primaryColor' => '#aaa',
'userPrimaryColor' => '#bbb',
'expected' => '#aaa',
],
];
}

/**
* @dataProvider dataGetColorPrimary
*/
public function testGetColorPrimary(string $disableTheming, string $primaryColor, string $backgroundColor, string $userBackgroundColor, $userPrimaryColor, $expected) {
public function testGetColorPrimary(string $disableTheming, string $primaryColor, string $userPrimaryColor, string $expected) {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
->method('getUser')
Expand All @@ -552,15 +508,12 @@ public function testGetColorPrimary(string $disableTheming, string $primaryColor
->willReturnMap([
['theming', 'disable-user-theming', 'no', $disableTheming],
['theming', 'primary_color', '', $primaryColor],
['theming', 'background_color', '', $backgroundColor],
]);
$this->config
->expects($this->any())
->method('getUserValue')
->willReturnMap([
['user', 'theming', 'background_color', '', $userBackgroundColor],
['user', 'theming', 'primary_color', $userBackgroundColor, $userPrimaryColor],
]);
->with('user', 'theming', 'primary_color', '')
->willReturn($userPrimaryColor);

$this->assertEquals($expected, $this->template->getColorPrimary());
}
Expand Down Expand Up @@ -668,15 +621,10 @@ public function testUndoPrimaryColor() {
->method('deleteAppValue')
->with('theming', 'primary_color');
$this->config
->expects($this->exactly(2))
->expects($this->once())
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
['theming', 'primary_color', null],
)->willReturnOnConsecutiveCalls(
'15',
$this->defaults->getColorPrimary(),
);
->with('theming', 'cachebuster', '0')
->willReturn('15');
$this->config
->expects($this->once())
->method('setAppValue')
Expand Down
Loading