Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 5 additions & 17 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import "../src/@types/global";
import "../src/@types/svg";
import "../src/@types/raw-loader";
// eslint-disable-next-line no-restricted-imports
import "matrix-js-sdk/src/@types/global";
import type {
Expand All @@ -31,20 +28,19 @@ import type {
RoomMemberEvent,
ICreateClientOpts,
} from "matrix-js-sdk/src/matrix";
import type { MatrixDispatcher } from "../src/dispatcher/dispatcher";
import type PerformanceMonitor from "../src/performance";
import type SettingsStore from "../src/settings/SettingsStore";
import type { SettingLevel } from "../src/settings/SettingLevel";

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface ApplicationWindow {
mxSettingsStore: typeof SettingsStore;
// XXX: Importing SettingsStore causes a bunch of type lint errors
mxSettingsStore: {
setValue(settingName: string, roomId: string | null, level: SettingLevel, value: any): Promise<void>;
};
mxMatrixClientPeg: {
matrixClient?: MatrixClient;
};
mxDispatcher: MatrixDispatcher;
mxPerformanceMonitor: PerformanceMonitor;
beforeReload?: boolean; // for detecting reloads
// Partial type for the matrix-js-sdk module, exported by browser-matrix
matrixcs: {
Expand All @@ -61,14 +57,6 @@ declare global {
};
}
}

interface Window {
// to appease the MatrixDispatcher import
mxDispatcher: MatrixDispatcher;
// to appease the PerformanceMonitor import
mxPerformanceMonitor: PerformanceMonitor;
mxPerformanceEntryNames: any;
}
}

export { MatrixClient };
93 changes: 4 additions & 89 deletions cypress/support/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Timeoutable = Cypress.Timeoutable;
import Withinable = Cypress.Withinable;
import Shadow = Cypress.Shadow;
import type { SettingLevel } from "../../src/settings/SettingLevel";
import type SettingsStore from "../../src/settings/SettingsStore";
import ApplicationWindow = Cypress.ApplicationWindow;

export enum Filter {
People = "people",
Expand All @@ -36,7 +36,7 @@ declare global {
/**
* Returns the SettingsStore
*/
getSettingsStore(): Chainable<typeof SettingsStore | undefined>; // XXX: Importing SettingsStore causes a bunch of type lint errors
getSettingsStore(): Chainable<ApplicationWindow["mxSettingsStore"] | undefined>;
/**
* Open the top left user menu, returning a handle to the resulting context menu.
*/
Expand All @@ -48,17 +48,6 @@ declare global {
*/
openUserSettings(tab?: string): Chainable<JQuery<HTMLElement>>;

/**
* Open room creation dialog.
*/
openCreateRoomDialog(): Chainable<JQuery<HTMLElement>>;

/**
* Open room settings (via room header menu), returning a handle to the resulting dialog.
* @param tab the name of the tab to switch to after opening, optional.
*/
openRoomSettings(tab?: string): Chainable<JQuery<HTMLElement>>;

/**
* Switch settings tab to the one by the given name, ideally call this in the context of the dialog.
* @param tab the name of the tab to switch to.
Expand All @@ -70,20 +59,6 @@ declare global {
*/
closeDialog(): Chainable<JQuery<HTMLElement>>;

/**
* Join the given beta, the `Labs` tab must already be opened,
* ideally call this in the context of the dialog.
* @param name the name of the beta to join.
*/
joinBeta(name: string): Chainable<JQuery<HTMLElement>>;

/**
* Leave the given beta, the `Labs` tab must already be opened,
* ideally call this in the context of the dialog.
* @param name the name of the beta to leave.
*/
leaveBeta(name: string): Chainable<JQuery<HTMLElement>>;

/**
* Sets the value for a setting. The room ID is optional if the
* setting is not being set for a particular room, otherwise it
Expand All @@ -98,20 +73,6 @@ declare global {
*/
setSettingValue(settingName: string, roomId: string, level: SettingLevel, value: any): Chainable<void>;

/**
* Gets the value of a setting. The room ID is optional if the
* setting is not to be applied to any particular room, otherwise it
* should be supplied.
* @param {string} settingName The name of the setting to read the
* value of.
* @param {String} roomId The room ID to read the setting value in,
* may be null.
* @param {boolean} excludeDefault True to disable using the default
* value.
* @return {*} The value, or null if not found
*/
getSettingValue<T>(settingName: string, roomId?: string, excludeDefault?: boolean): Chainable<T>;

/**
* Opens the spotlight dialog
*/
Expand All @@ -135,29 +96,19 @@ declare global {
}
}

Cypress.Commands.add("getSettingsStore", (): Chainable<typeof SettingsStore> => {
Cypress.Commands.add("getSettingsStore", (): Chainable<ApplicationWindow["mxSettingsStore"]> => {
return cy.window({ log: false }).then((win) => win.mxSettingsStore);
});

Cypress.Commands.add(
"setSettingValue",
(name: string, roomId: string, level: SettingLevel, value: any): Chainable<void> => {
return cy.getSettingsStore().then((store: typeof SettingsStore) => {
return cy.getSettingsStore().then((store: ApplicationWindow["mxSettingsStore"]) => {
return cy.wrap(store.setValue(name, roomId, level, value));
});
},
);

// eslint-disable-next-line max-len
Cypress.Commands.add(
"getSettingValue",
<T = any>(name: string, roomId?: string, excludeDefault?: boolean): Chainable<T> => {
return cy.getSettingsStore().then((store: typeof SettingsStore) => {
return store.getValue(name, roomId, excludeDefault);
});
},
);

Cypress.Commands.add("openUserMenu", (): Chainable<JQuery<HTMLElement>> => {
cy.findByRole("button", { name: "User menu" }).click();
return cy.get(".mx_ContextualMenu");
Expand All @@ -174,24 +125,6 @@ Cypress.Commands.add("openUserSettings", (tab?: string): Chainable<JQuery<HTMLEl
});
});

Cypress.Commands.add("openCreateRoomDialog", (): Chainable<JQuery<HTMLElement>> => {
cy.findByRole("button", { name: "Add room" }).click();
cy.findByRole("menuitem", { name: "New room" }).click();
return cy.get(".mx_CreateRoomDialog");
});

Cypress.Commands.add("openRoomSettings", (tab?: string): Chainable<JQuery<HTMLElement>> => {
cy.findByRole("button", { name: "Room options" }).click();
cy.get(".mx_RoomTile_contextMenu").within(() => {
cy.findByRole("menuitem", { name: "Settings" }).click();
});
return cy.get(".mx_RoomSettingsDialog").within(() => {
if (tab) {
cy.switchTab(tab);
}
});
});

Cypress.Commands.add("switchTab", (tab: string): Chainable<JQuery<HTMLElement>> => {
return cy.get(".mx_TabbedView_tabLabels").within(() => {
cy.contains(".mx_TabbedView_tabLabel", tab).click();
Expand All @@ -202,24 +135,6 @@ Cypress.Commands.add("closeDialog", (): Chainable<JQuery<HTMLElement>> => {
return cy.findByRole("button", { name: "Close dialog" }).click();
});

Cypress.Commands.add("joinBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
return cy
.contains(".mx_BetaCard_title", name)
.closest(".mx_BetaCard")
.within(() => {
return cy.get(".mx_BetaCard_buttons").findByRole("button", { name: "Join the beta" }).click();
});
});

Cypress.Commands.add("leaveBeta", (name: string): Chainable<JQuery<HTMLElement>> => {
return cy
.contains(".mx_BetaCard_title", name)
.closest(".mx_BetaCard")
.within(() => {
return cy.get(".mx_BetaCard_buttons").findByRole("button", { name: "Leave the beta" }).click();
});
});

Cypress.Commands.add(
"openSpotlightDialog",
(options?: Partial<Loggable & Timeoutable & Withinable & Shadow>): Chainable<JQuery<HTMLElement>> => {
Expand Down