-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WD-11588 - refactor: Remove nested components in components/Login (#1762
- Loading branch information
1 parent
c07c3ef
commit f5d2751
Showing
9 changed files
with
245 additions
and
193 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/components/LogIn/IdentityProviderForm/IdentityProviderForm.test.tsx
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,42 @@ | ||
import { screen, within } from "@testing-library/react"; | ||
|
||
import { generalStateFactory } from "testing/factories/general"; | ||
import { rootStateFactory } from "testing/factories/root"; | ||
import { renderComponent } from "testing/utils"; | ||
|
||
import { Label } from "../types"; | ||
|
||
import IdentityProviderForm from "./IdentityProviderForm"; | ||
|
||
describe("IdentityProviderForm", () => { | ||
it("should render a 'connecting' message if the user is logged in", () => { | ||
renderComponent(<IdentityProviderForm userIsLoggedIn={true} />); | ||
expect( | ||
within(screen.getByRole("button")).getByText("Connecting..."), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render a 'connecting' message if the user is not logged in and there is no visitURLs", () => { | ||
const state = rootStateFactory.build({ | ||
general: generalStateFactory.withConfig().build({ | ||
visitURLs: null, | ||
}), | ||
}); | ||
renderComponent(<IdentityProviderForm userIsLoggedIn={false} />, { state }); | ||
expect( | ||
within(screen.getByRole("button")).getByText("Connecting..."), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render a login message if the user is not logged in and there is visitURLs", () => { | ||
const state = rootStateFactory.build({ | ||
general: generalStateFactory.withConfig().build({ | ||
visitURLs: ["I am a url"], | ||
}), | ||
}); | ||
renderComponent(<IdentityProviderForm userIsLoggedIn={false} />, { state }); | ||
expect( | ||
screen.getByRole("link", { name: Label.LOGIN_TO_DASHBOARD }), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/components/LogIn/IdentityProviderForm/IdentityProviderForm.tsx
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,34 @@ | ||
import { Spinner } from "@canonical/react-components"; | ||
import { useSelector } from "react-redux"; | ||
|
||
import AuthenticationButton from "components/AuthenticationButton"; | ||
import type { RootState } from "store/store"; | ||
|
||
import { Label } from "../types"; | ||
|
||
type Props = { | ||
userIsLoggedIn: boolean; | ||
}; | ||
|
||
const IdentityProviderForm = ({ userIsLoggedIn }: Props) => { | ||
const visitURL = useSelector((state: RootState) => { | ||
if (!userIsLoggedIn) { | ||
// This form only gets displayed on the main login page, at which point | ||
// there can only be one authentication request, so just return the | ||
// first one. | ||
return state?.general?.visitURLs?.[0]; | ||
} | ||
}); | ||
|
||
return visitURL ? ( | ||
<AuthenticationButton appearance="positive" visitURL={visitURL}> | ||
{Label.LOGIN_TO_DASHBOARD} | ||
</AuthenticationButton> | ||
) : ( | ||
<button className="p-button--neutral" disabled> | ||
<Spinner text="Connecting..." /> | ||
</button> | ||
); | ||
}; | ||
|
||
export default IdentityProviderForm; |
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 @@ | ||
export { default } from "./IdentityProviderForm"; |
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
Oops, something went wrong.