Skip to content

Commit

Permalink
Adjusting authForm spinner to use session.busy (#3218)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcottner authored Apr 17, 2024
1 parent 910d046 commit 3a95325
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/components/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export default function AuthForm({
const { schema: currentSchema, uiSchema: curentUiSchema } =
authSchemas(authType);

const [showSpinner, setshowSpinner] = useState(false);
const [schema, setSchema] = useState(currentSchema);
const [uiSchema, setUiSchema] = useState(curentUiSchema);
const [formData, setFormData] = useState({
Expand All @@ -305,7 +304,6 @@ export default function AuthForm({

const serverInfoCallback = async auth => {
await getServerInfo(auth);
setshowSpinner(false);
};

const authMethods = getSupportedAuthMethods(session);
Expand All @@ -322,7 +320,6 @@ export default function AuthForm({

const onChange = ({ formData: updatedData }: RJSFSchema) => {
if (formData.server !== updatedData.server) {
setshowSpinner(true);
const newServer = servers.find(x => x.server === updatedData.server);
updatedData.authType = newServer?.authType || ANONYMOUS_AUTH;
}
Expand Down Expand Up @@ -382,7 +379,7 @@ export default function AuthForm({
formData={formData}
onChange={onChange}
onSubmit={onSubmit}
showSpinner={showSpinner}
showSpinner={session.busy}
>
<button type="submit" className="btn btn-info">
{"Sign in using "}
Expand Down
1 change: 1 addition & 0 deletions src/sagas/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function* getServerInfo(
action: ActionType<typeof actions.getServerInfo>
): SagaGen {
const { auth } = action;
yield put(actions.sessionBusy(true));

let processedAuth: AuthData = auth;
if (auth.authType.startsWith("openid-")) {
Expand Down
2 changes: 0 additions & 2 deletions test/components/AuthForm_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ describe("AuthForm component", () => {
fireEvent.change(screen.queryByLabelText("Server*"), {
target: { value: "http://test.server/v1" },
});
await screen.findByTestId("spinner"); // spinner should show up
await waitFor(() => new Promise(resolve => setTimeout(resolve, 500))); // debounce wait
expect(screen.queryByTestId("spinner")).toBeNull(); // spinner should be gone by now

fireEvent.click(screen.getByLabelText("Basic Auth"));
fireEvent.change(screen.getByLabelText("Username*"), {
Expand Down
11 changes: 11 additions & 0 deletions test/sagas/session_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ describe("session sagas", () => {

describe("Success", () => {
it("should call client.fetchServerInfo", () => {
// ensure that sessionBusy is called
expect(getServerInfo.next().value).toStrictEqual(
put(actions.sessionBusy(true))
);

const fetchServerInfoCall = getServerInfo.next().value;
client = getClient();
expect(fetchServerInfoCall).toStrictEqual(
Expand Down Expand Up @@ -105,6 +110,7 @@ describe("session sagas", () => {
action = actions.getServerInfo(authData);
getServerInfo = saga.getServerInfo(getState, action);
getServerInfo.next();
getServerInfo.next();
expect(setupClient).toHaveBeenCalledWith({
authType: "openid",
provider: "google",
Expand All @@ -121,6 +127,7 @@ describe("session sagas", () => {
// the new server fails.
getServerInfo = saga.getServerInfo(getState, action);
getServerInfo.next();
getServerInfo.next();
expect(getServerInfo.throw().value).toStrictEqual(
put(actions.serverInfoSuccess(DEFAULT_SERVERINFO))
);
Expand Down Expand Up @@ -154,6 +161,8 @@ describe("session sagas", () => {

it("should ignore the success of the oldest", () => {
getServerInfo1.next();
getServerInfo1.next();
getServerInfo2.next();
getServerInfo2.next();
// Latest to have started is getServerInfo2, it's taken into account.
expect(getServerInfo2.next(serverInfo).value).toStrictEqual(
Expand All @@ -165,6 +174,8 @@ describe("session sagas", () => {

it("should ignore the error of the oldest", () => {
getServerInfo1.next();
getServerInfo1.next();
getServerInfo2.next();
getServerInfo2.next();
// Latest to have started is getServerInfo2, it's taken into account.
expect(getServerInfo2.next(serverInfo).value).toStrictEqual(
Expand Down

0 comments on commit 3a95325

Please sign in to comment.