This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dominik Henneke <[email protected]>
- Loading branch information
Showing
8 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
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"; | ||
|
||
describe("RoomViewLifecycle", () => { | ||
let homeserver: HomeserverInstance; | ||
|
||
beforeEach(() => { | ||
cy.window().then((win) => { | ||
win.localStorage.setItem("mx_local_settings", '{"language":"en"}'); // Ensure the language is set to a consistent value | ||
}); | ||
cy.startHomeserver("default").then((data) => { | ||
homeserver = data; | ||
|
||
cy.intercept( | ||
{ method: "GET", pathname: "/config.json" }, | ||
{ body: { default_server_config: { "m.homeserver": { base_url: data.baseUrl } } } }, | ||
); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopHomeserver(homeserver); | ||
}); | ||
|
||
it("should show login without the PreviewRoomNotLoggedIn lifecycle", () => { | ||
cy.visit(`/#/room/!example:localhost`); | ||
|
||
cy.contains("Join the conversation with an account"); | ||
cy.contains("Sign Up"); | ||
cy.contains("Sign In"); | ||
}); | ||
|
||
it("should show login with the PreviewRoomNotLoggedIn lifecycle", () => { | ||
// we must reload the page first, otherwise, the module system settings get lost... | ||
cy.visit("/"); | ||
cy.contains("Welcome"); | ||
|
||
// we need to set the data to local storage again because of the reload | ||
cy.window().then((win) => { | ||
win.localStorage.setItem("mx_local_settings", '{"language":"en"}'); // Ensure the language is set to a consistent value | ||
}); | ||
cy.enableModuleSystem(); | ||
cy.moduleSystemPreviewRoom("!example:localhost"); | ||
|
||
cy.visit(`/#/room/!example:localhost`); | ||
cy.reload(); | ||
|
||
cy.contains("Join the room to participate"); | ||
cy.contains("Join"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
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"; | ||
|
||
describe("Custom translations module", () => { | ||
let homeserver: HomeserverInstance; | ||
|
||
beforeEach(() => { | ||
cy.enableModuleSystem(); | ||
|
||
cy.window().then((win) => { | ||
win.localStorage.setItem("mx_lhs_size", "0"); // Collapse left panel for these tests | ||
}); | ||
cy.startHomeserver("default").then((data) => { | ||
homeserver = data; | ||
|
||
cy.initTestUser(homeserver, "Tom"); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopHomeserver(homeserver); | ||
}); | ||
|
||
it("should override the 'Welcome' translation", () => { | ||
cy.get("Howdy Tom (Changed by the Module System)"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 Nordeck IT + Consulting GmbH | ||
* | ||
* 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. | ||
*/ | ||
|
||
import { ModuleApi } from "@matrix-org/react-sdk-module-api/lib/ModuleApi"; | ||
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule"; | ||
import { | ||
RoomPreviewListener, | ||
RoomViewLifecycle, | ||
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle"; | ||
|
||
export default class ExampleModule extends RuntimeModule { | ||
public constructor(moduleApi: ModuleApi) { | ||
super(moduleApi); | ||
|
||
// Only apply the module when it is activated so we don't interfere with | ||
// other tests that should not be affected by this module. | ||
if (window.localStorage.getItem("cypress_module_system_enable") !== "true") { | ||
return; | ||
} | ||
|
||
this.moduleApi.registerTranslations({ | ||
"Welcome %(name)s": { | ||
en: "Howdy %(name)s (Changed by the Module System)", | ||
}, | ||
}); | ||
|
||
this.on(RoomViewLifecycle.PreviewRoomNotLoggedIn, this.onRoomPreview); | ||
} | ||
|
||
protected onRoomPreview: RoomPreviewListener = (opts, roomId) => { | ||
if (window.localStorage.getItem("cypress_module_system_preview_room_id") === roomId) { | ||
opts.canJoin = true; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file is included by the `yarn start:e2e` task in element-web. It will | ||
# register the module in this folder as a module in the dev mode so that the | ||
# Cypress tests can be executed correctly. | ||
modules: | ||
- "file:node_modules/matrix-react-sdk/cypress/example_module" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "example_module", | ||
"version": "1.0.0", | ||
"main": "ExampleModule.ts", | ||
"dependencies": { | ||
"@matrix-org/react-sdk-module-api": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,5 @@ suppress_key_server_warning: true | |
|
||
ui_auth: | ||
session_timeout: "300s" | ||
|
||
allow_guest_access: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
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" /> | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace Cypress { | ||
interface Chainable { | ||
// Enables the module system for the current session. | ||
enableModuleSystem(): void; | ||
moduleSystemPreviewRoom(roomId: string): void; | ||
} | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
cy.window().then((win) => { | ||
win.localStorage.removeItem("cypress_module_system_enable"); | ||
win.localStorage.removeItem("cypress_module_system_preview_room_id"); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add("enableModuleSystem", (): void => { | ||
cy.window().then((win) => { | ||
win.localStorage.setItem("cypress_module_system_enable", "true"); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add("moduleSystemPreviewRoom", (roomId: string): void => { | ||
cy.window().then((win) => { | ||
win.localStorage.setItem("cypress_module_system_preview_room_id", roomId); | ||
}); | ||
}); | ||
|
||
// Needed to make this file a module | ||
export {}; |