From 52b7fa474d353821d000e516aa2ef1fac8797254 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 9 Feb 2021 11:16:03 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20dark=20mode=20togg?= =?UTF-8?q?le=20to=20desktop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/app/routes/application.js | 26 ++++++++++++ ui/desktop/app/templates/application.hbs | 23 +++++++++++ .../tests/acceptance/authentication-test.js | 41 +++++++++++++++++-- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/ui/desktop/app/routes/application.js b/ui/desktop/app/routes/application.js index 009d73daf..45c73b24a 100644 --- a/ui/desktop/app/routes/application.js +++ b/ui/desktop/app/routes/application.js @@ -98,4 +98,30 @@ export default class ApplicationRoute extends Route.extend( } return true; } + + /** + * Applies the specified color theme to the root ember element. + * @param {string} theme - "light", "dark", or nullish (system default) + */ + @action + toggleTheme(theme) { + const rootElementSelector = getOwner(this).rootElement; + const rootEl = getOwner(this) + .lookup('service:-document') + .querySelector(rootElementSelector); + this.session.set('data.theme', theme); + switch (theme) { + case 'light': + rootEl.classList.add('rose-theme-light'); + rootEl.classList.remove('rose-theme-dark'); + break; + case 'dark': + rootEl.classList.add('rose-theme-dark'); + rootEl.classList.remove('rose-theme-light'); + break; + default: + rootEl.classList.remove('rose-theme-dark'); + rootEl.classList.remove('rose-theme-light'); + } + } } diff --git a/ui/desktop/app/templates/application.hbs b/ui/desktop/app/templates/application.hbs index 9c504be7b..7101dd522 100644 --- a/ui/desktop/app/templates/application.hbs +++ b/ui/desktop/app/templates/application.hbs @@ -22,6 +22,29 @@ > {{t 'actions.deauthenticate'}} + + + + + + + + + + + + + + + + + + + {{/if}} diff --git a/ui/desktop/tests/acceptance/authentication-test.js b/ui/desktop/tests/acceptance/authentication-test.js index 703ca0ce9..d0f0e3fa6 100644 --- a/ui/desktop/tests/acceptance/authentication-test.js +++ b/ui/desktop/tests/acceptance/authentication-test.js @@ -3,19 +3,20 @@ import { visit, currentURL, //fillIn, - //click, + click, find, //findAll, - //getRootElement + getRootElement, //setupOnerror, } from '@ember/test-helpers'; +import { run, later } from '@ember/runloop'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; //import { Response } from 'miragejs'; //import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { currentSession, - //authenticateSession, + authenticateSession, invalidateSession, } from 'ember-simple-auth/test-support'; @@ -159,4 +160,38 @@ module('Acceptance | authentication', function (hooks) { assert.equal(currentURL(), urls.authenticate.global); assert.ok(find('.rose-message')); }); + + test('color theme is applied from session data', async function (assert) { + assert.expect(12); + authenticateSession({ + scope: { + id: instances.scopes.global.id, + type: instances.scopes.global.type + }, + }); + later(async () => { + run.cancelTimers(); + // system default + assert.notOk(currentSession().get('data.theme')); + assert.notOk(getRootElement().classList.contains('rose-theme-light')); + assert.notOk(getRootElement().classList.contains('rose-theme-dark')); + // toggle light mode + await click('[name="theme"][value="light"]'); + assert.equal(currentSession().get('data.theme'), 'light'); + assert.ok(getRootElement().classList.contains('rose-theme-light')); + assert.notOk(getRootElement().classList.contains('rose-theme-dark')); + // toggle dark mode + await click('[name="theme"][value="dark"]'); + assert.equal(currentSession().get('data.theme'), 'dark'); + assert.notOk(getRootElement().classList.contains('rose-theme-light')); + assert.ok(getRootElement().classList.contains('rose-theme-dark')); + // toggle system default + await click('[name="theme"][value=""]'); + assert.notOk(currentSession().get('data.theme')); + assert.notOk(getRootElement().classList.contains('rose-theme-light')); + assert.notOk(getRootElement().classList.contains('rose-theme-dark')); + }, 750); + + await visit(urls.scopes.org); + }); });