Skip to content

Commit aedceb0

Browse files
committed
Add cypress testing
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 7b25ce9 commit aedceb0

30 files changed

+7079
-613
lines changed

.github/workflows/cypress.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Cypress
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- stable*
9+
10+
env:
11+
APP_NAME: viewer
12+
BRANCH: ${{ github.base_ref }}
13+
TESTING: true
14+
15+
jobs:
16+
init:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout server
21+
uses: actions/checkout@v3
22+
23+
- name: Read package.json node and npm engines version
24+
uses: skjnldsv/read-package-engines-version-actions@v1.2
25+
id: versions
26+
with:
27+
fallbackNode: "^12"
28+
fallbackNpm: "^6"
29+
30+
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
31+
uses: actions/setup-node@v3
32+
with:
33+
cache: 'npm'
34+
node-version: ${{ steps.versions.outputs.nodeVersion }}
35+
36+
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
37+
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
38+
39+
- name: Install dependencies & build app
40+
run: |
41+
npm ci
42+
TESTING=true npm run build --if-present
43+
44+
- name: Save context
45+
uses: actions/cache@v3
46+
with:
47+
key: cypress-context-${{ github.run_id }}
48+
path: /home/runner/work/server
49+
50+
cypress:
51+
runs-on: ubuntu-latest
52+
needs: init
53+
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
# run multiple copies of the current job in parallel
58+
containers: [1]
59+
60+
name: runner ${{ matrix.containers }}
61+
62+
steps:
63+
- name: Restore context
64+
uses: actions/cache@v3
65+
with:
66+
key: cypress-context-${{ github.run_id }}
67+
path: /home/runner/work/server
68+
69+
- name: Run E2E cypress tests
70+
uses: cypress-io/github-action@v4
71+
with:
72+
record: true
73+
parallel: true
74+
# cypress env
75+
ci-build-id: ${{ github.sha }}-${{ github.run_number }}
76+
tag: ${{ github.event_name }}
77+
env:
78+
# Needs to be prefixed with CYPRESS_
79+
CYPRESS_BRANCH: ${{ env.BRANCH }}
80+
CYPRESS_GH: true
81+
# https://github.com/cypress-io/github-action/issues/124
82+
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
83+
# Needed for some specific code workarounds
84+
TESTING: true
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
87+
88+
summary:
89+
runs-on: ubuntu-latest
90+
needs: [init, cypress]
91+
92+
if: always()
93+
94+
name: cypress-summary
95+
96+
steps:
97+
- name: Summary status
98+
run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ composer.phar
163163

164164
./.htaccess
165165
core/js/mimetypelist.js
166+
167+
# Tests - cypress
168+
cypress/snapshots
169+
cypress/videos

apps/theming/css/default.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
--background-invert-if-dark: no;
5555
--background-invert-if-bright: invert(100%);
5656
--background-image-invert-if-bright: no;
57-
--image-background: url('/core/img/app-background.jpg');
58-
--image-background-default: url('/core/img/app-background.jpg');
59-
--color-background-plain: #0082c9;
6057
--primary-invert-if-bright: no;
6158
--color-primary: #006aa3;
6259
--color-primary-default: #0082c9;
@@ -75,4 +72,6 @@
7572
--color-primary-element-light-hover: #dbe5ea;
7673
--color-primary-element-text-dark: #ededed;
7774
--gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
75+
--image-background-default: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
76+
--color-background-plain: #0082c9;
7877
}

apps/theming/lib/ImageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getImageUrl(string $key): string {
9494
case 'favicon':
9595
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
9696
case 'background':
97-
return $this->urlGenerator->linkTo(Application::APP_ID, "img/background/" . BackgroundService::DEFAULT_BACKGROUND);
97+
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND);
9898
}
9999
return '';
100100
}

apps/theming/lib/Service/BackgroundService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
use OC\User\NoUserException;
3232
use OCA\Theming\AppInfo\Application;
3333
use OCA\Theming\ThemingDefaults;
34-
use OCP\Files\AppData\IAppDataFactory;
3534
use OCP\Files\File;
3635
use OCP\Files\IAppData;
3736
use OCP\Files\IRootFolder;

apps/theming/lib/ThemingDefaults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getColorPrimary(): string {
247247
* Return the default color primary
248248
*/
249249
public function getDefaultColorPrimary(): string {
250-
$color = $this->config->getAppValue(Application::APP_ID, 'color');
250+
$color = $this->config->getAppValue(Application::APP_ID, 'color', '');
251251
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
252252
$color = '#0082c9';
253253
}

apps/theming/src/AdminTheming.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export default {
286286
text-align: center;
287287
margin-top: 10px;
288288
background-color: var(--color-primary-default);
289-
background-image: var(--image-background-default, var(--image-background-plain, linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
289+
background-image: var(--image-background-default, var(--image-background-plain, linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
290290
291291
&-logo {
292292
width: 20%;

apps/theming/src/components/BackgroundSettings.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!--
22
- @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
3-
- @copyright Copyright (c) 2022 Greta Doci <gretadoci@gmail.com>
43
-
5-
- @author Julius Härtl <jus@bitgrid.net>
6-
- @author Greta Doci <gretadoci@gmail.com>
74
- @author Christopher Ng <chrng8@gmail.com>
5+
- @author Greta Doci <gretadoci@gmail.com>
6+
- @author John Molakvoæ <skjnldsv@protonmail.com>
7+
- @author Julius Härtl <jus@bitgrid.net>
88
-
99
- @license GNU AGPL version 3 or any later version
1010
-
@@ -24,11 +24,12 @@
2424
-->
2525

2626
<template>
27-
<div class="background-selector">
27+
<div class="background-selector" data-user-theming-background-settings>
2828
<!-- Custom background -->
2929
<button class="background background__filepicker"
3030
:class="{ 'icon-loading': loading === 'custom', 'background--active': backgroundImage === 'custom' }"
3131
:data-color-bright="invertTextColor(Theming.color)"
32+
data-user-theming-background-custom
3233
tabindex="0"
3334
@click="pickFile">
3435
{{ t('theming', 'Custom background') }}
@@ -40,6 +41,7 @@
4041
:class="{ 'icon-loading': loading === 'default', 'background--active': backgroundImage === 'default' }"
4142
:data-color-bright="invertTextColor(Theming.defaultColor)"
4243
:style="{ '--border-color': Theming.defaultColor }"
44+
data-user-theming-background-default
4345
tabindex="0"
4446
@click="setDefault">
4547
{{ t('theming', 'Default background') }}
@@ -52,6 +54,7 @@
5254
:data-color="Theming.color"
5355
:data-color-bright="invertTextColor(Theming.color)"
5456
:style="{ backgroundColor: Theming.color, '--border-color': Theming.color}"
57+
data-user-theming-background-color
5558
tabindex="0">
5659
{{ t('theming', 'Change color') }}
5760
</button>
@@ -63,6 +66,7 @@
6366
v-tooltip="shippedBackground.details.attribution"
6467
:class="{ 'icon-loading': loading === shippedBackground.name, 'background--active': backgroundImage === shippedBackground.name }"
6568
:data-color-bright="shippedBackground.details.theming === 'dark'"
69+
:data-user-theming-background-shipped="shippedBackground.name"
6670
:style="{ backgroundImage: 'url(' + shippedBackground.preview + ')', '--border-color': shippedBackground.details.primary_color }"
6771
class="background background__shipped"
6872
tabindex="0"
@@ -72,6 +76,7 @@
7276

7377
<!-- Remove background -->
7478
<button class="background background__delete"
79+
data-user-theming-background-clear
7580
tabindex="0"
7681
@click="removeBackground">
7782
{{ t('theming', 'Remove background') }}

apps/theming/tests/Controller/ThemingControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public function testGetLoginBackgroundNotExistent() {
680680

681681
public function testGetLoginBackground() {
682682
$file = $this->createMock(ISimpleFile::class);
683-
$file->method('getName')->willReturn('app-background.jpg');
683+
$file->method('getName')->willReturn('background.png');
684684
$file->method('getMTime')->willReturn(42);
685685
$this->imageManager->expects($this->once())
686686
->method('getImage')

apps/theming/tests/Themes/DefaultThemeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
*/
2323
namespace OCA\Theming\Tests\Service;
2424

25+
use OCA\Theming\AppInfo\Application;
2526
use OCA\Theming\ImageManager;
2627
use OCA\Theming\ITheme;
28+
use OCA\Theming\Service\BackgroundService;
2729
use OCA\Theming\Themes\DefaultTheme;
2830
use OCA\Theming\ThemingDefaults;
2931
use OCA\Theming\Util;
@@ -80,6 +82,11 @@ protected function setUp(): void {
8082
->method('getDefaultColorPrimary')
8183
->willReturn('#0082c9');
8284

85+
$this->themingDefaults
86+
->expects($this->any())
87+
->method('getBackground')
88+
->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND);
89+
8390
$this->l10n
8491
->expects($this->any())
8592
->method('t')

0 commit comments

Comments
 (0)