Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove very outdated loading-test.tsx #27588

Merged
merged 2 commits into from
Jun 20, 2024
Merged

Remove very outdated loading-test.tsx #27588

merged 2 commits into from
Jun 20, 2024

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jun 17, 2024

This test suite attempted to fire up a complete Element Web instance inside a jest environment. I created it way back in 2016, before Cypress, Playwright, or react-testing-library existed, and everything it does is now much better tested by our playwright tests.

It's now getting in my way for fixing #27560. It's time to put it out of its misery.

@richvdh richvdh requested a review from a team as a code owner June 17, 2024 18:15
@richvdh richvdh requested review from t3chguy and MidhunSureshR June 17, 2024 18:15
@richvdh richvdh added the T-Task Tasks for the team like planning label Jun 17, 2024
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of these aren't covered by playwright, e.g. guest registration, please replace them rather than remove them.

@richvdh
Copy link
Member Author

richvdh commented Jun 18, 2024

I'll have a look, but may end up having to pursue option B of just disabling crypto when running in an environment that doesn't support structuredClone.

});
});

it.skip("should not register as a guest when using a #/login link", function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled by #23474. Guess it can't have been that important!

Comment on lines -218 to -269
it("should follow the original link after successful login", function () {
loadApp({
uriFragment: "#/room/!room:id",
});

// Pass the liveliness checks
httpBackend.when("GET", "/versions").respond(200, { versions: SERVER_SUPPORTED_MATRIX_VERSIONS });
httpBackend.when("GET", "/_matrix/identity/v2").respond(200, {});
httpBackend
.when("GET", "/_matrix/client/unstable/org.matrix.msc2965/auth_issuer")
.respond(404, { errcode: "M_UNRECOGNIZED", error: "Unrecognized request" });

return sleep(1)
.then(async () => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
await waitForLoadingSpinner();

httpBackend
.when("POST", "/register")
.check(function (req) {
expect(req.queryParams?.kind).toEqual("guest");
})
.respond(403, "Guest access is disabled");

return httpBackend.flush(undefined);
})
.then(() => {
// Wait for another trip around the event loop for the UI to update
return sleep(10);
})
.then(() => {
return moveFromWelcomeToLogin(matrixChat);
})
.then(() => {
return completeLogin(matrixChat!);
})
.then(() => {
// once the sync completes, we should have a room view
return awaitRoomView(matrixChat);
})
.then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation?.hash).toEqual("#/room/!room:id");

// and the localstorage should have been updated
expect(localStorage.getItem("mx_user_id")).toEqual("@user:id");
expect(localStorage.getItem("mx_access_token")).toEqual("access_token");
expect(localStorage.getItem("mx_hs_url")).toEqual(DEFAULT_HS_URL);
expect(localStorage.getItem("mx_is_url")).toEqual(DEFAULT_IS_URL);
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -321 to -337
it("shows the last known room by default", function () {
loadApp();

return awaitLoggedIn(matrixChat!)
.then(() => {
// we are logged in - let the sync complete
return expectAndAwaitSync();
})
.then(() => {
// once the sync completes, we should have a room view
return awaitRoomView(matrixChat);
})
.then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation?.hash).toEqual("#/room/!last_room:id");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -339 to -355
it("shows a home page by default if we have no joined rooms", function () {
localStorage.removeItem("mx_last_room_id");

loadApp();

return awaitLoggedIn(matrixChat!)
.then(() => {
// we are logged in - let the sync complete
return expectAndAwaitSync();
})
.then(() => {
// once the sync completes, we should have a home page
httpBackend.verifyNoOutstandingExpectation();
expect(matrixChat?.container.querySelector(".mx_HomePage")).toBeTruthy();
expect(windowLocation?.hash).toEqual("#/home");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -357 to -375
it("shows a room view if we followed a room link", function () {
loadApp({
uriFragment: "#/room/!room:id",
});

return awaitLoggedIn(matrixChat!)
.then(() => {
// we are logged in - let the sync complete
return expectAndAwaitSync();
})
.then(() => {
// once the sync completes, we should have a room view
return awaitRoomView(matrixChat);
})
.then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation?.hash).toEqual("#/room/!room:id");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -434 to -472
it("uses the default homeserver to register with", function () {
loadApp();

return sleep(1)
.then(async () => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
await waitForLoadingSpinner();

httpBackend
.when("POST", "/register")
.check(function (req) {
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);
expect(req.queryParams?.kind).toEqual("guest");
})
.respond(200, {
user_id: "@guest:localhost",
access_token: "secret_token",
});

return httpBackend.flush(undefined);
})
.then(() => {
return awaitLoggedIn(matrixChat!);
})
.then(() => {
return expectAndAwaitSync({ isGuest: true });
})
.then((req) => {
expect(req.path.startsWith(DEFAULT_HS_URL)).toBe(true);

// once the sync completes, we should have a welcome page
httpBackend.verifyNoOutstandingExpectation();
expect(matrixChat?.container.querySelector(".mx_Welcome")).toBeTruthy();
expect(windowLocation?.hash).toEqual("#/welcome");
expect(MatrixClientPeg.safeGet().baseUrl).toEqual(DEFAULT_HS_URL);
expect(MatrixClientPeg.safeGet().idBaseUrl).toEqual(DEFAULT_IS_URL);
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -474 to -510
it("shows a room view if we followed a room link", function () {
loadApp({
uriFragment: "#/room/!room:id",
});
return sleep(1)
.then(async () => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
await waitForLoadingSpinner();

httpBackend
.when("POST", "/register")
.check(function (req) {
expect(req.queryParams?.kind).toEqual("guest");
})
.respond(200, {
user_id: "@guest:localhost",
access_token: "secret_token",
});

return httpBackend.flush(undefined);
})
.then(() => {
return awaitLoggedIn(matrixChat!);
})
.then(() => {
return expectAndAwaitSync({ isGuest: true });
})
.then(() => {
// once the sync completes, we should have a room view
return awaitRoomView(matrixChat);
})
.then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation?.hash).toEqual("#/room/!room:id");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -512 to -562
describe("Login as user", function () {
beforeEach(function () {
// first we have to load the homepage
loadApp();

httpBackend
.when("POST", "/register")
.check(function (req) {
expect(req.queryParams?.kind).toEqual("guest");
})
.respond(200, {
user_id: "@guest:localhost",
access_token: "secret_token",
});

return httpBackend
.flush(undefined)
.then(() => {
return awaitLoggedIn(matrixChat!);
})
.then(() => {
// we got a sync spinner - let the sync complete
return expectAndAwaitSync();
})
.then(async () => {
// once the sync completes, we should have a home page
await waitFor(() => matrixChat?.container.querySelector(".mx_HomePage"));

// we simulate a click on the 'login' button by firing off
// the relevant dispatch.
//
// XXX: is it an anti-pattern to access the react-sdk's
// dispatcher in this way? Is it better to find the login
// button and simulate a click? (we might have to arrange
// for it to be shown - it's not always, due to the
// collapsing left panel

dis.dispatch({ action: "start_login" });

return awaitLoginComponent(matrixChat);
});
});

it("should give us a login page", async function () {
// we expect a single <Login> component
await screen.findByRole("main");
screen.getAllByText("Sign in");

expect(windowLocation?.hash).toEqual("#/login");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't bothered to replicate this test. I don't think that poking things into the dispatcher is something worth testing at this level.

Comment on lines -565 to -614
describe("Token login:", function () {
it("logs in successfully", function () {
localStorage.setItem("mx_sso_hs_url", "https://homeserver");
localStorage.setItem("mx_sso_is_url", "https://idserver");
loadApp({
queryString: "?loginToken=secretToken",
});

return sleep(1)
.then(async () => {
// we expect a spinner while we're logging in
await waitForLoadingSpinner();

httpBackend
.when("POST", "/login")
.check(function (req) {
expect(req.path).toMatch(new RegExp("^https://homeserver/"));
expect(req.data.type).toEqual("m.login.token");
expect(req.data.token).toEqual("secretToken");
})
.respond(200, {
user_id: "@user:localhost",
device_id: "DEVICE_ID",
access_token: "access_token",
});

return httpBackend.flush(undefined);
})
.then(() => {
// at this point, MatrixChat should fire onTokenLoginCompleted, which
// makes index.js reload the app. We're not going to attempt to
// simulate the reload - just check that things are left in the
// right state for the reloaded app.

return tokenLoginCompletePromise;
})
.then(() => {
return expectAndAwaitSync().catch((e) => {
throw new Error("Never got /sync after login: did the client start?");
});
})
.then(() => {
// check that the localstorage has been set up in such a way that
// the reloaded app can pick up where we leave off.
expect(localStorage.getItem("mx_user_id")).toEqual("@user:localhost");
expect(localStorage.getItem("mx_access_token")).toEqual("access_token");
expect(localStorage.getItem("mx_hs_url")).toEqual("https://homeserver");
expect(localStorage.getItem("mx_is_url")).toEqual("https://idserver");
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines -191 to -216
it("gives a welcome page by default", function () {
loadApp();

return sleep(1)
.then(async () => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
await waitForLoadingSpinner();

httpBackend
.when("POST", "/register")
.check(function (req) {
expect(req.queryParams?.kind).toEqual("guest");
})
.respond(403, "Guest access is disabled");

return httpBackend.flush(undefined);
})
.then(() => {
// Wait for another trip around the event loop for the UI to update
return waitForWelcomeComponent(matrixChat);
})
.then(() => {
return waitFor(() => expect(windowLocation?.hash).toEqual("#/welcome"));
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richvdh richvdh requested a review from t3chguy June 20, 2024 11:17
@richvdh richvdh added this pull request to the merge queue Jun 20, 2024
Merged via the queue into develop with commit 9f9cd6f Jun 20, 2024
25 checks passed
@richvdh richvdh deleted the rav/kill_loading_tests branch June 20, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants