optimized realm loading and added current realm (#1891)

This commit is contained in:
Erik Jan de Wit 2022-01-20 11:20:35 +01:00 committed by GitHub
parent d5ecda9e74
commit bd28a912dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View file

@ -3,7 +3,10 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage";
import CreateRealmPage from "../support/pages/admin_console/CreateRealmPage";
import Masthead from "../support/pages/admin_console/Masthead";
import AdminClient from "../support/util/AdminClient";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
const masthead = new Masthead();
const loginPage = new LoginPage();
@ -13,11 +16,15 @@ const createRealmPage = new CreateRealmPage();
describe("Realms test", () => {
const testRealmName = "Test realm";
describe("Realm creation", () => {
beforeEach(() => {
before(() => {
keycloakBefore();
loginPage.logIn();
});
beforeEach(() => {
keycloakBeforeEach();
});
after(async () => {
const client = new AdminClient();
[testRealmName, "one", "two"].map(
@ -45,7 +52,7 @@ describe("Realms test", () => {
sidebarPage.goToCreateRealm();
createRealmPage.fillRealmName("one").createRealm();
const fetchUrl = "/auth/admin/realms";
const fetchUrl = "/auth/admin/realms?briefRepresentation=true";
cy.intercept(fetchUrl).as("fetch");
masthead.checkNotificationMessage("Realm created");
@ -61,7 +68,7 @@ describe("Realms test", () => {
});
it("should change to Test realm", () => {
sidebarPage.getCurrentRealm().should("eq", "Master");
sidebarPage.getCurrentRealm().should("eq", "Two");
sidebarPage
.goToRealm(testRealmName)

View file

@ -20,7 +20,7 @@ export default class CreateRealmPage {
}
fillRealmName(realmName: string) {
cy.get(this.realmNameInput).type(realmName);
cy.get(this.realmNameInput).clear().type(realmName);
return this;
}

View file

@ -41,7 +41,7 @@ export const RealmSelector = () => {
})
.concat(
realms
.filter((r) => !recentUsed.used.includes(r.realm!))
.filter((r) => !recentUsed.used.includes(r.realm!) || r.realm === realm)
.map((r) => {
return { name: r.realm!, used: false };
})
@ -132,9 +132,11 @@ export const RealmSelector = () => {
onSearchInputChange={(value) => setSearch(value)}
className="keycloak__realm_selector__context_selector"
footer={
<ContextSelectorItem key="add">
<AddRealm />
</ContextSelectorItem>
whoAmI.canCreateRealm() && (
<ContextSelectorItem key="add">
<AddRealm />
</ContextSelectorItem>
)
}
>
{(filteredItems || all).map((item) => (

View file

@ -33,7 +33,7 @@ export const RealmsProvider: FunctionComponent = ({ children }) => {
}
useFetch(
() => adminClient.realms.find(),
() => adminClient.realms.find({ briefRepresentation: true }),
(realms) => updateRealms(realms),
[]
);
@ -42,7 +42,7 @@ export const RealmsProvider: FunctionComponent = ({ children }) => {
//this is needed otherwise the realm find function will not return
//new or renamed realms because of the cached realms in the token (perhaps?)
await adminClient.keycloak?.updateToken(Number.MAX_VALUE);
updateRealms(await adminClient.realms.find());
updateRealms(await adminClient.realms.find({ briefRepresentation: true }));
}, []);
const value = useMemo<RealmsContextProps>(