Factor out post-login splash screen to a new component (#12103)

* Factor out post-login splash screen to a new component

* Move CSS classes to per-component file

* Rename CSS classes

... to reflect the component that uses them

* code review
This commit is contained in:
Richard van der Hoff 2024-01-04 18:12:08 +00:00 committed by GitHub
parent baaf8ad68b
commit fd64eccd4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 220 additions and 37 deletions

View file

@ -0,0 +1,49 @@
/*
Copyright 2024 The Matrix.org Foundation C.I.C.
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 { render, RenderResult } from "@testing-library/react";
import React, { ComponentProps } from "react";
import { LoginSplashView } from "../../../../src/components/structures/auth/LoginSplashView";
describe("<LoginSplashView />", () => {
function getComponent(props: Partial<ComponentProps<typeof LoginSplashView>> = {}): RenderResult {
const defaultProps = {
onLogoutClick: () => {},
syncError: null,
};
return render(<LoginSplashView {...defaultProps} {...props} />);
}
it("Renders a spinner", () => {
const rendered = getComponent();
expect(rendered.getByTestId("spinner")).toBeInTheDocument();
expect(rendered.asFragment()).toMatchSnapshot();
});
it("Renders an error message", () => {
const rendered = getComponent({ syncError: new Error("boohoo") });
expect(rendered.asFragment()).toMatchSnapshot();
});
it("Calls onLogoutClick", () => {
const onLogoutClick = jest.fn();
const rendered = getComponent({ onLogoutClick });
expect(onLogoutClick).not.toHaveBeenCalled();
rendered.getByRole("button", { name: "Logout" }).click();
expect(onLogoutClick).toHaveBeenCalled();
});
});

View file

@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<LoginSplashView /> Renders a spinner 1`] = `
<DocumentFragment>
<div
class="mx_MatrixChat_splash"
>
<div
class="mx_Spinner"
>
<div
aria-label="Loading…"
class="mx_Spinner_icon"
data-testid="spinner"
role="progressbar"
style="width: 32px; height: 32px;"
/>
</div>
<div
class="mx_LoginSplashView_splashButtons"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
role="button"
tabindex="0"
>
Logout
</div>
</div>
</div>
</DocumentFragment>
`;
exports[`<LoginSplashView /> Renders an error message 1`] = `
<DocumentFragment>
<div
class="mx_MatrixChat_splash"
>
<div
class="mx_LoginSplashView_syncError"
>
<div>
Unable to connect to Homeserver. Retrying…
</div>
</div>
<div
class="mx_Spinner"
>
<div
aria-label="Loading…"
class="mx_Spinner_icon"
data-testid="spinner"
role="progressbar"
style="width: 32px; height: 32px;"
/>
</div>
<div
class="mx_LoginSplashView_splashButtons"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
role="button"
tabindex="0"
>
Logout
</div>
</div>
</div>
</DocumentFragment>
`;