Add E2E test of ThemeChoicePanel
(#10469)
* Add E2E test of ThemeChoicePanel Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Edit a comment Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Apply feedback Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Remove obsolete data-testId attributes They has become obsolete with bfa8152538a3a0804ac14e231578d0cba73aa308. Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> * Update a jest snapshot Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com> --------- Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>
This commit is contained in:
parent
52017f62e1
commit
c4f59d4d56
4 changed files with 135 additions and 5 deletions
132
cypress/e2e/settings/theme-choice-panel.spec.ts
Normal file
132
cypress/e2e/settings/theme-choice-panel.spec.ts
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023 Suguru Hirahara
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
|
import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
||||||
|
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
||||||
|
|
||||||
|
const USER_NAME = "Hanako";
|
||||||
|
|
||||||
|
describe("Theme Choice Panel", () => {
|
||||||
|
let homeserver: HomeserverInstance;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.startHomeserver("default").then((data) => {
|
||||||
|
homeserver = data;
|
||||||
|
cy.initTestUser(homeserver, USER_NAME);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable the default theme for consistency in case ThemeWatcher automatically chooses it
|
||||||
|
cy.setSettingValue("use_system_theme", null, SettingLevel.DEVICE, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cy.stopHomeserver(homeserver);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be rendered with the light theme selected", () => {
|
||||||
|
cy.openUserSettings("Appearance")
|
||||||
|
.get(".mx_ThemeChoicePanel")
|
||||||
|
.within(() => {
|
||||||
|
cy.findByTestId("checkbox-use-system-theme").within(() => {
|
||||||
|
cy.findByText("Match system theme").should("be.visible");
|
||||||
|
|
||||||
|
// Assert that 'Match system theme' is not checked
|
||||||
|
// Note that mx_Checkbox_checkmark exists and is hidden by CSS if it is not checked
|
||||||
|
cy.get(".mx_Checkbox_checkmark").should("not.be.visible");
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.get(".mx_ThemeSelectors").within(() => {
|
||||||
|
cy.get(".mx_ThemeSelector_light").should("exist");
|
||||||
|
cy.get(".mx_ThemeSelector_dark").should("exist");
|
||||||
|
|
||||||
|
// Assert that the light theme is selected
|
||||||
|
cy.get(".mx_ThemeSelector_light.mx_StyledRadioButton_enabled").should("exist");
|
||||||
|
|
||||||
|
// Assert that the buttons for the light and dark theme are not enabled
|
||||||
|
cy.get(".mx_ThemeSelector_light.mx_StyledRadioButton_disabled").should("not.exist");
|
||||||
|
cy.get(".mx_ThemeSelector_dark.mx_StyledRadioButton_disabled").should("not.exist");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert that the checkbox for the high contrast theme is rendered
|
||||||
|
cy.findByLabelText("Use high contrast").should("exist");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(
|
||||||
|
"should disable the labels for themes and the checkbox for the high contrast theme if the checkbox for " +
|
||||||
|
"the system theme is clicked",
|
||||||
|
() => {
|
||||||
|
cy.openUserSettings("Appearance")
|
||||||
|
.get(".mx_ThemeChoicePanel")
|
||||||
|
.findByLabelText("Match system theme")
|
||||||
|
.click({ force: true }); // force click because the size of the checkbox is zero
|
||||||
|
|
||||||
|
cy.get(".mx_ThemeChoicePanel").within(() => {
|
||||||
|
// Assert that the labels for the light theme and dark theme are disabled
|
||||||
|
cy.get(".mx_ThemeSelector_light.mx_StyledRadioButton_disabled").should("exist");
|
||||||
|
cy.get(".mx_ThemeSelector_dark.mx_StyledRadioButton_disabled").should("exist");
|
||||||
|
|
||||||
|
// Assert that there does not exist a label for an enabled theme
|
||||||
|
cy.get("label.mx_StyledRadioButton_enabled").should("not.exist");
|
||||||
|
|
||||||
|
// Assert that the checkbox and label to enable the the high contrast theme should not exist
|
||||||
|
cy.findByLabelText("Use high contrast").should("not.exist");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it("should not render the checkbox and the label for the high contrast theme if the dark theme is selected", () => {
|
||||||
|
cy.openUserSettings("Appearance");
|
||||||
|
|
||||||
|
// Assert that the checkbox and the label to enable the high contrast theme should exist
|
||||||
|
cy.findByLabelText("Use high contrast").should("exist");
|
||||||
|
|
||||||
|
// Enable the dark theme
|
||||||
|
cy.get(".mx_ThemeSelector_dark").click();
|
||||||
|
|
||||||
|
// Assert that the checkbox and the label should not exist
|
||||||
|
cy.findByLabelText("Use high contrast").should("not.exist");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should support enabling the high contast theme", () => {
|
||||||
|
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
|
||||||
|
|
||||||
|
cy.get(".mx_GenericEventListSummary").within(() => {
|
||||||
|
// Assert that $primary-content is applied to GELS summary on the light theme
|
||||||
|
// $primary-content on the light theme = #17191c = rgb(23, 25, 28)
|
||||||
|
cy.get(".mx_TextualEvent.mx_GenericEventListSummary_summary")
|
||||||
|
.should("have.css", "color", "rgb(23, 25, 28)")
|
||||||
|
.should("have.css", "opacity", "0.5");
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.openUserSettings("Appearance")
|
||||||
|
.get(".mx_ThemeChoicePanel")
|
||||||
|
.findByLabelText("Use high contrast")
|
||||||
|
.click({ force: true }); // force click because the size of the checkbox is zero
|
||||||
|
|
||||||
|
cy.closeDialog();
|
||||||
|
|
||||||
|
cy.get(".mx_GenericEventListSummary").within(() => {
|
||||||
|
// Assert that $secondary-content is specified for GELS summary on the high contrast theme
|
||||||
|
// $secondary-content on the high contrast theme = #5e6266 = rgb(94, 98, 102)
|
||||||
|
cy.get(".mx_TextualEvent.mx_GenericEventListSummary_summary")
|
||||||
|
.should("have.css", "color", "rgb(94, 98, 102)")
|
||||||
|
.should("have.css", "opacity", "1");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -168,7 +168,7 @@ export default class ThemeChoicePanel extends React.Component<IProps, IState> {
|
||||||
(findHighContrastTheme(this.state.theme) || isHighContrastTheme(this.state.theme))
|
(findHighContrastTheme(this.state.theme) || isHighContrastTheme(this.state.theme))
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<div data-testid="theme-choice-panel-highcontrast">
|
<div>
|
||||||
<StyledCheckbox
|
<StyledCheckbox
|
||||||
checked={isHighContrastTheme(this.state.theme)}
|
checked={isHighContrastTheme(this.state.theme)}
|
||||||
onChange={(e) => this.highContrastThemeChanged(e.target.checked)}
|
onChange={(e) => this.highContrastThemeChanged(e.target.checked)}
|
||||||
|
@ -197,7 +197,7 @@ export default class ThemeChoicePanel extends React.Component<IProps, IState> {
|
||||||
let systemThemeSection: JSX.Element | undefined;
|
let systemThemeSection: JSX.Element | undefined;
|
||||||
if (themeWatcher.isSystemThemeSupported()) {
|
if (themeWatcher.isSystemThemeSupported()) {
|
||||||
systemThemeSection = (
|
systemThemeSection = (
|
||||||
<div>
|
<div data-testid="checkbox-use-system-theme">
|
||||||
<StyledCheckbox
|
<StyledCheckbox
|
||||||
checked={this.state.useSystemTheme}
|
checked={this.state.useSystemTheme}
|
||||||
onChange={(e) => this.onUseSystemThemeChanged(e.target.checked)}
|
onChange={(e) => this.onUseSystemThemeChanged(e.target.checked)}
|
||||||
|
@ -248,7 +248,7 @@ export default class ThemeChoicePanel extends React.Component<IProps, IState> {
|
||||||
<div className="mx_SettingsTab_section mx_ThemeChoicePanel">
|
<div className="mx_SettingsTab_section mx_ThemeChoicePanel">
|
||||||
<span className="mx_SettingsTab_subheading">{_t("Theme")}</span>
|
<span className="mx_SettingsTab_subheading">{_t("Theme")}</span>
|
||||||
{systemThemeSection}
|
{systemThemeSection}
|
||||||
<div className="mx_ThemeSelectors" data-testid="theme-choice-panel-selectors">
|
<div className="mx_ThemeSelectors">
|
||||||
<StyledRadioGroup
|
<StyledRadioGroup
|
||||||
name="theme"
|
name="theme"
|
||||||
definitions={orderedThemes.map((t) => ({
|
definitions={orderedThemes.map((t) => ({
|
||||||
|
|
|
@ -12,7 +12,6 @@ exports[`ThemeChoicePanel renders the theme choice UI 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<div
|
<div
|
||||||
class="mx_ThemeSelectors"
|
class="mx_ThemeSelectors"
|
||||||
data-testid="theme-choice-panel-selectors"
|
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
|
class="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
|
||||||
|
|
|
@ -25,7 +25,6 @@ exports[`AppearanceUserSettingsTab should render 1`] = `
|
||||||
</span>
|
</span>
|
||||||
<div
|
<div
|
||||||
class="mx_ThemeSelectors"
|
class="mx_ThemeSelectors"
|
||||||
data-testid="theme-choice-panel-selectors"
|
|
||||||
>
|
>
|
||||||
<label
|
<label
|
||||||
class="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
|
class="mx_StyledRadioButton mx_ThemeSelector_light mx_StyledRadioButton_disabled mx_StyledRadioButton_outlined"
|
||||||
|
|
Loading…
Reference in a new issue