-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
There was a problem hiding this 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.
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 |
}); | ||
}); | ||
|
||
it.skip("should not register as a guest when using a #/login link", function () { |
There was a problem hiding this comment.
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!
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by matrix-org/matrix-react-sdk#12657
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.
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"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a subset of https://github.com/matrix-org/matrix-react-sdk/blob/v3.101.0/playwright/e2e/login/login.spec.ts#L81-L102.
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")); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by matrix-org/matrix-react-sdk#12660
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.