adding preliminary cypress tests

This commit is contained in:
mfrances 2021-02-15 14:35:25 -05:00
parent 1a78540c8f
commit cf8451fe9d
8 changed files with 243 additions and 4 deletions

View file

@ -67,7 +67,7 @@ export const KeycloakCard = ({
/> />
)} )}
</CardActions> </CardActions>
<CardTitle>{title}</CardTitle> <CardTitle data-cy="keycloak-card-title">{title}</CardTitle>
</CardHeader> </CardHeader>
<CardBody /> <CardBody />
<CardFooter> <CardFooter>

View file

@ -170,12 +170,13 @@ export const UserFederationKerberosSettings = () => {
<SettingsCache form={form} showSectionHeading /> <SettingsCache form={form} showSectionHeading />
<Form onSubmit={form.handleSubmit(save)}> <Form onSubmit={form.handleSubmit(save)}>
<ActionGroup> <ActionGroup>
<Button variant="primary" type="submit"> <Button variant="primary" type="submit" data-cy="kerberos-save">
{t("common:save")} {t("common:save")}
</Button> </Button>
<Button <Button
variant="link" variant="link"
onClick={() => history.push(`/${realm}/user-federation`)} onClick={() => history.push(`/${realm}/user-federation`)}
data-cy="kerberos-cancel"
> >
{t("common:cancel")} {t("common:cancel")}
</Button> </Button>

View file

@ -47,7 +47,7 @@ export const UserFederationSection = () => {
() => { () => {
const testParams: { [name: string]: string | number } = { const testParams: { [name: string]: string | number } = {
parentId: realm, parentId: realm,
type: "org.keycloak.storage.UserStorageProvider", // MF note that this is providerType in the output, but API call is still type type: "org.keycloak.storage.UserStorageProvider",
}; };
return adminClient.components.find(testParams); return adminClient.components.find(testParams);
}, },
@ -172,7 +172,11 @@ export const UserFederationSection = () => {
</TextContent> </TextContent>
<hr className="pf-u-mb-lg" /> <hr className="pf-u-mb-lg" />
<Gallery hasGutter> <Gallery hasGutter>
<Card isHoverable> <Card
isHoverable
onClick={() => history.push(`${url}/kerberos/new`)}
data-cy="kerberos-card"
>
<CardTitle> <CardTitle>
<Split hasGutter> <Split hasGutter>
<SplitItem> <SplitItem>

View file

@ -107,6 +107,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateName")}`, message: `${t("validateName")}`,
}, },
})} })}
data-cy="kerberos-name"
/> />
{form.errors.name && ( {form.errors.name && (
<div className="error">{form.errors.name.message}</div> <div className="error">{form.errors.name.message}</div>
@ -136,6 +137,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateRealm")}`, message: `${t("validateRealm")}`,
}, },
})} })}
data-cy="kerberos-realm"
/> />
{form.errors.config && {form.errors.config &&
form.errors.config.kerberosRealm && form.errors.config.kerberosRealm &&
@ -169,6 +171,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateServerPrincipal")}`, message: `${t("validateServerPrincipal")}`,
}, },
})} })}
data-cy="kerberos-principal"
/> />
{form.errors.config && {form.errors.config &&
form.errors.config.serverPrincipal && form.errors.config.serverPrincipal &&
@ -202,6 +205,7 @@ export const KerberosSettingsRequired = ({
message: `${t("validateKeyTab")}`, message: `${t("validateKeyTab")}`,
}, },
})} })}
data-cy="kerberos-keytab"
/> />
{form.errors.config && {form.errors.config &&
form.errors.config.keyTab && form.errors.config.keyTab &&

View file

@ -126,6 +126,7 @@ export const SettingsCache = ({
}} }}
selections={value} selections={value}
variant={SelectVariant.single} variant={SelectVariant.single}
data-cy="kerberos-cache-policy"
> >
<SelectOption key={0} value={["DEFAULT"]} isPlaceholder /> <SelectOption key={0} value={["DEFAULT"]} isPlaceholder />
<SelectOption key={1} value={["EVICT_DAILY"]} /> <SelectOption key={1} value={["EVICT_DAILY"]} />
@ -292,6 +293,7 @@ export const SettingsCache = ({
id="kc-max-lifespan" id="kc-max-lifespan"
name="config.maxLifespan[0]" name="config.maxLifespan[0]"
ref={form.register} ref={form.register}
data-cy="kerberos-cache-lifespan"
/> />
</FormGroup> </FormGroup>
) : ( ) : (

View file

@ -0,0 +1,85 @@
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
// import ListingPage from "../support/pages/admin_console/ListingPage";
import CreateKerberosProviderPage from "../support/pages/admin_console/manage/providers/CreateKerberosProviderPage";
// import Masthead from "../support/pages/admin_console/Masthead";
// import { wait } from "@testing-library/react";
const loginPage = new LoginPage();
// const masthead = new Masthead();
const sidebarPage = new SidebarPage();
// const listingPage = new ListingPage();
const providersPage = new CreateKerberosProviderPage();
// config info
const kerberosName = "my-kerberos";
const kerberosRealm = "my-realm";
const kerberosPrincipal = "my-principal";
const kerberosKeytab = "my-keytab";
// const kerberosSecondName = "my-kerberos-2";
const policy = "EVICT_WEEKLY"
const kerberosDay = "Tuesday";
const kerberosHour = "11";
const kerberosMinute = "45";
// const kerberosLifespan = "24";
describe('User Fed Kerberos test', () => {
it('Kerberos provider creation from empty state', () => {
cy.visit("");
loginPage.logIn();
// CREATE FROM EMPTY STATE CARD PAGE
sidebarPage.goToUserFederation();
cy.get('[data-cy=kerberos-card]').click();
// cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider");
providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab);
providersPage.save();
// TODO verify save message
// UPDATE
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]').contains("my-kerberos").click();
providersPage.selectCacheType(policy);
// cy.get('[data-cy="kerberos-cache-policy"]').select(policy);
providersPage.fillCachedData( kerberosHour, kerberosMinute)
// TODO verify update message
// CREATE FROM USER FED CARD PAGE
})
// Messages:
// User federation provider successfully created
// The user federation provider has been deleted.
// it("should open kerberos empty settings page by clicking card", function () {
// // // listingPage.goToCreateItem();
// // cy.get('[data-cy=kerberos-card]').click();
// // cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider");
// // // providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab);
// // // providersPage.save();
// // // The error should inform about duplicated name/id (THIS MESSAGE DOES NOT HAVE QUOTES AS THE OTHERS)
// // // masthead.checkNotificationMessage(
// // // "Could not create role: Role with name admin already exists"
// // // );
// });
})

View file

@ -0,0 +1,133 @@
export default class CreateKerberosProviderPage {
kerberosNameInput: string;
kerberosRealmInput: string;
kerberosPrincipalInput: string;
kerberosKeytabInput: string;
// clientScopeTypeDrpDwn: string;
// this.clientScopeTypeDrpDwn = "#kc-protocol";
// selectClientScopeType(clientScopeType: string) {
// cy.get(this.clientScopeTypeDrpDwn).click();
// cy.get(this.clientScopeTypeList).contains(clientScopeType).click();
// return this;
// }
// kerberosCachePolicyInput: string;
kerberosCacheDayInput: string;
kerberosCacheDayList: string;
kerberosCacheHourInput: string;
kerberosCacheHourList: string;
kerberosCacheMinuteInput: string;
kerberosCacheMinuteList: string;
// kerberosCacheLifespanInput: string;
kerberosCachePolicyInput: string;
kerberosCachePolicyList: string;
realmRoleNameError: string;
realmRoleDescriptionInput: string;
saveBtn: string;
cancelBtn: string;
constructor() {
// cypress IDs
this.kerberosNameInput = "data-cy=kerberos-name";
this.kerberosRealmInput = "data-cy=kerberos-realm";
this.kerberosPrincipalInput = "data-cy=kerberos-principal";
this.kerberosKeytabInput = "data-cy=kerberos-keytab";
this.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.kerberosCacheDayInput = "#kc-eviction-day";
this.kerberosCacheDayList = "#kc-eviction-day + ul";
this.kerberosCacheHourInput = "#kc-eviction-hour";
this.kerberosCacheHourList = "#kc-eviction-hour + ul";
this.kerberosCacheMinuteInput = "#kc-eviction-minute";
this.kerberosCacheMinuteList = "#kc-eviction-minute + ul";
// this.kerberosCacheLifespanInput = "data-cy=kerberos-cache-lifespan";
this.realmRoleNameError = "#kc-name-helper";
this.realmRoleDescriptionInput = "#kc-role-description";
this.saveBtn = "data-cy=kerberos-save";
this.cancelBtn = "data-cy=kerberos-cancel";
// this.cardTitle = "keycloak-card-title";
}
//#region Required Settings
fillKerberosRequiredData(
name: string,
realm: string,
principal: string,
keytab: string
) {
// cy.get(this.realmRoleNameInput).clear();
if (name) {
cy.get(`[${this.kerberosNameInput}]`).type(name);
}
if (realm) {
cy.get(`[${this.kerberosRealmInput}]`).type(realm);
}
if (principal) {
cy.get(`[${this.kerberosPrincipalInput}]`).type(principal);
}
if (keytab) {
cy.get(`[${this.kerberosKeytabInput}]`).type(keytab);
}
return this;
}
selectCacheType(cacheType: string) {
cy.get(this.kerberosCachePolicyInput).click();
cy.get(this.kerberosCachePolicyList).contains(cacheType).click();
return this;
}
// fillCachedData(day: string, hour: string, minute: string) {
fillCachedData(hour: string, minute: string) {
// cy.get(this.realmRoleNameInput).clear();
// if (policy) {
// cy.get(`[${this.kerberosNameInput}]`).type(policy);
// }
// if (day) {
// cy.get(this.kerberosCacheDayInput).click();
// // cy.get(this.kerberosCacheDayInput).contains(day).click();
// cy.get(this.kerberosCacheDayInput).contains().click();
// }
if (hour) {
cy.get(this.kerberosCacheHourInput).click();
cy.get(this.kerberosCacheHourInput).contains(hour).click();
}
if (minute) {
cy.get(this.kerberosCacheMinuteInput).click();
cy.get(this.kerberosCacheMinuteInput).contains(minute).click();
}
return this;
}
// checkRealmRoleNameRequiredMessage(exist = true) {
// cy.get(this.realmRoleNameError).should((!exist ? "not." : "") + "exist");
// return this;
// }
//#endregion
save() {
cy.get(`[${this.saveBtn}]`).click();
return this;
}
cancel() {
cy.get(this.cancelBtn).click();
return this;
}
}

View file

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
},
"include": [
"**/*.ts"
]
}