diff --git a/cypress/integration/theme_switcher_dialog.js b/cypress/integration/theme_switcher_dialog.js new file mode 100644 index 0000000000..b4297e5674 --- /dev/null +++ b/cypress/integration/theme_switcher_dialog.js @@ -0,0 +1,30 @@ +context('Theme Switcher Shortcut', () => { + before(() => { + cy.login(); + cy.visit('/app'); + }); + beforeEach(() => { + cy.reload(); + }); + it('Check Toggle', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('exist'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{ctrl+shift+g}'); + cy.get('.modal-backdrop').should('not.exist'); + }); + it('Check Enter', () => { + cy.open_theme_dialog('{ctrl+shift+g}'); + cy.get('.theme-grid > div').first().click(); + cy.close_theme('{enter}'); + cy.get('.modal-backdrop').should('not.exist'); + }); + +}); + +Cypress.Commands.add('open_theme_dialog', (shortcut_keys) => { + cy.get('body').type(shortcut_keys); +}); +Cypress.Commands.add('close_theme', (shortcut_keys) => { + cy.get('.modal-header').type(shortcut_keys); +}); \ No newline at end of file diff --git a/frappe/public/js/frappe/desk.js b/frappe/public/js/frappe/desk.js index 51ada70948..72e8010605 100644 --- a/frappe/public/js/frappe/desk.js +++ b/frappe/public/js/frappe/desk.js @@ -59,8 +59,12 @@ frappe.Application = class Application { shortcut: 'shift+ctrl+g', description: __('Switch Theme'), action: () => { - frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); - frappe.theme_switcher.show(); + if (frappe.theme_switcher && frappe.theme_switcher.dialog.is_visible) { + frappe.theme_switcher.hide(); + } else { + frappe.theme_switcher = new frappe.ui.ThemeSwitcher(); + frappe.theme_switcher.show(); + } } }); diff --git a/frappe/public/js/frappe/ui/theme_switcher.js b/frappe/public/js/frappe/ui/theme_switcher.js index 16ba16e5d5..d20afae529 100644 --- a/frappe/public/js/frappe/ui/theme_switcher.js +++ b/frappe/public/js/frappe/ui/theme_switcher.js @@ -25,6 +25,8 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher { increment_by = 1; } else if (key === "left") { increment_by = -1; + } else if (e.keyCode === 13) { // keycode 13 is for 'enter' + this.hide(); } else { return; }