complete suite of kerberos cypress tests

This commit is contained in:
mfrances 2021-02-16 14:42:30 -05:00
parent cf8451fe9d
commit 8c4d6d4eb4
7 changed files with 213 additions and 112 deletions

View file

@ -64,6 +64,7 @@ export const KeycloakCard = ({
onClick={(e) => handleCardMenuClick(e)} onClick={(e) => handleCardMenuClick(e)}
isOpen={isDropdownOpen} isOpen={isDropdownOpen}
dropdownItems={dropdownItems} dropdownItems={dropdownItems}
data-cy={`${title}-dropdown`}
/> />
)} )}
</CardActions> </CardActions>

View file

@ -112,6 +112,7 @@ export const ViewHeader = ({
} }
isOpen={isDropdownOpen} isOpen={isDropdownOpen}
dropdownItems={dropdownItems} dropdownItems={dropdownItems}
data-cy="action-dropdown"
/> />
</ToolbarItem> </ToolbarItem>
)} )}

View file

@ -57,7 +57,11 @@ const KerberosSettingsHeader = ({
titleKey="Kerberos" titleKey="Kerberos"
subKey="" subKey=""
dropdownItems={[ dropdownItems={[
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}> <DropdownItem
key="delete"
onClick={() => toggleDeleteDialog()}
data-cy="delete-provider-cmd"
>
{t("deleteProvider")} {t("deleteProvider")}
</DropdownItem>, </DropdownItem>,
]} ]}

View file

@ -110,6 +110,7 @@ export const UserFederationSection = () => {
onClick={() => { onClick={() => {
toggleDeleteForCard(userFederation.id!); toggleDeleteForCard(userFederation.id!);
}} }}
data-cy="card-delete"
> >
{t("common:delete")} {t("common:delete")}
</DropdownItem>, </DropdownItem>,

View file

@ -156,6 +156,7 @@ export const SettingsCache = ({
control={form.control} control={form.control}
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<Select <Select
data-cy="cache-day"
toggleId="kc-eviction-day" toggleId="kc-eviction-day"
required required
onToggle={() => onToggle={() =>

View file

@ -1,85 +1,224 @@
import LoginPage from "../support/pages/LoginPage"; import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage"; 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 CreateKerberosProviderPage from "../support/pages/admin_console/manage/providers/CreateKerberosProviderPage";
// import Masthead from "../support/pages/admin_console/Masthead"; import Masthead from "../support/pages/admin_console/Masthead";
// import { wait } from "@testing-library/react"; import ModalUtils from "../support/util/ModalUtils";
const loginPage = new LoginPage(); const loginPage = new LoginPage();
// const masthead = new Masthead(); const masthead = new Masthead();
const sidebarPage = new SidebarPage(); const sidebarPage = new SidebarPage();
// const listingPage = new ListingPage();
const providersPage = new CreateKerberosProviderPage(); const providersPage = new CreateKerberosProviderPage();
const modalUtils = new ModalUtils();
// config info const firstKerberosName = "my-kerberos";
const kerberosName = "my-kerberos"; const firstKerberosRealm = "my-realm";
const kerberosRealm = "my-realm"; const firstKerberosPrincipal = "my-principal";
const kerberosPrincipal = "my-principal"; const firstKerberosKeytab = "my-keytab";
const kerberosKeytab = "my-keytab";
// const kerberosSecondName = "my-kerberos-2";
const policy = "EVICT_WEEKLY" const secondKerberosName = `${firstKerberosName}-2`;
const kerberosDay = "Tuesday"; const secondKerberosRealm = `${firstKerberosRealm}-2`;
const kerberosHour = "11"; const secondKerberosPrincipal = `${firstKerberosPrincipal}-2`;
const kerberosMinute = "45"; const secondKerberosKeytab = `${firstKerberosKeytab}-2`;
// const kerberosLifespan = "24";
describe('User Fed Kerberos test', () => { const defaultPolicy = "DEFAULT";
it('Kerberos provider creation from empty state', () => { const newPolicy = "EVICT_WEEKLY";
cy.visit(""); const defaultKerberosDay = "Sunday";
loginPage.logIn(); const defaultKerberosHour = "00";
const defaultKerberosMinute = "00";
const newKerberosDay = "Wednesday";
const newKerberosHour = "15";
const newKerberosMinute = "55";
// CREATE FROM EMPTY STATE CARD PAGE const createdSuccessMessage = "User federation provider successfully created";
sidebarPage.goToUserFederation(); const savedSuccessMessage = "User federation provider successfully saved";
cy.get('[data-cy=kerberos-card]').click(); const deletedSuccessMessage = "The user federation provider has been deleted.";
// cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider"); const deleteModalTitle = "Delete user federation provider?";
providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab); const disableModalTitle = "Disable user federation provider?";
providersPage.save();
// TODO verify save message
describe("User Fed Kerberos tests", () => {
it("Create Kerberos provider from empty state", () => {
cy.visit("");
loginPage.logIn();
// UPDATE sidebarPage.goToUserFederation();
sidebarPage.goToUserFederation(); cy.get("[data-cy=kerberos-card]").click();
cy.get('[data-cy="keycloak-card-title"]').contains("my-kerberos").click();
providersPage.fillKerberosRequiredData(
firstKerberosName,
firstKerberosRealm,
firstKerberosPrincipal,
firstKerberosKeytab
);
providersPage.save();
providersPage.selectCacheType(policy); masthead.checkNotificationMessage(createdSuccessMessage);
// cy.get('[data-cy="kerberos-cache-policy"]').select(policy); sidebarPage.goToUserFederation();
providersPage.fillCachedData( kerberosHour, kerberosMinute) });
it("Update an existing Kerberos provider and save", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(defaultKerberosDay).click();
cy.contains(newKerberosDay).click();
// TODO verify update message cy.contains(defaultKerberosHour).click();
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosMinute).click();
cy.contains(newKerberosMinute).click();
// CREATE FROM USER FED CARD PAGE providersPage.save();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
expect(cy.contains(newPolicy).should("exist"));
expect(cy.contains(defaultPolicy).should("not.exist"));
});
it("Change existing Kerberos provider and click button to cancel", () => {
}) cy.visit("");
loginPage.logIn();
// Messages: sidebarPage.goToUserFederation();
// User federation provider successfully created
// The user federation provider has been deleted.
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy);
cy.contains(newKerberosDay).click();
cy.contains(defaultKerberosDay).click();
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosHour).click();
// it("should open kerberos empty settings page by clicking card", function () { cy.contains(newKerberosMinute).click();
cy.contains(defaultKerberosMinute).click();
// // // listingPage.goToCreateItem(); providersPage.cancel();
// // cy.get('[data-cy=kerberos-card]').click();
// // cy.get('[data-cy=kerberos-name]').type("my-kerberos-provider"); cy.wait(1000);
// // // providersPage.fillKerberosRequiredData(kerberosName, kerberosRealm, kerberosPrincipal, kerberosKeytab); cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
// // // providersPage.save(); .click();
cy.wait(1000);
// // // The error should inform about duplicated name/id (THIS MESSAGE DOES NOT HAVE QUOTES AS THE OTHERS) providersPage.selectCacheType(newPolicy);
// // // masthead.checkNotificationMessage(
// // // "Could not create role: Role with name admin already exists" expect(cy.contains(newKerberosDay).should("exist"));
// // // ); expect(cy.contains(newKerberosHour).should("exist"));
// }); expect(cy.contains(newKerberosMinute).should("exist"));
})
expect(cy.contains(defaultKerberosMinute).should("not.exist"));
sidebarPage.goToUserFederation();
});
it("Disable an existing Kerberos provider", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.disableEnabledSwitch();
modalUtils.checkModalTitle(disableModalTitle).confirmModal();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Disabled").should("exist"));
});
it("Enable an existing previously-disabled Kerberos provider", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.enableEnabledSwitch();
masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Enabled").should("exist"));
});
it("Create new Kerberos provider using the New Provider dropdown", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.contains("Add new provider").click();
cy.contains("Kerberos").click();
providersPage.fillKerberosRequiredData(
secondKerberosName,
secondKerberosRealm,
secondKerberosPrincipal,
secondKerberosKeytab
);
providersPage.save();
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation();
});
it("Delete a Kerberos provider from card view using the card's menu", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="my-kerberos-2-dropdown"]').click();
cy.get('[data-cy="card-delete"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
it("Delete a Kerberos provider using the Settings view's Action menu", () => {
cy.visit("");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-cy="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
cy.get('[data-cy="action-dropdown"]').click();
cy.get('[data-cy="delete-provider-cmd"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage);
});
});

View file

@ -4,41 +4,27 @@ export default class CreateKerberosProviderPage {
kerberosPrincipalInput: string; kerberosPrincipalInput: string;
kerberosKeytabInput: string; kerberosKeytabInput: string;
// clientScopeTypeDrpDwn: string; kerberosEnabledInput: 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; kerberosCacheDayInput: string;
kerberosCacheDayList: string; kerberosCacheDayList: string;
kerberosCacheHourInput: string; kerberosCacheHourInput: string;
kerberosCacheHourList: string; kerberosCacheHourList: string;
kerberosCacheMinuteInput: string; kerberosCacheMinuteInput: string;
kerberosCacheMinuteList: string; kerberosCacheMinuteList: string;
// kerberosCacheLifespanInput: string;
kerberosCachePolicyInput: string; kerberosCachePolicyInput: string;
kerberosCachePolicyList: string; kerberosCachePolicyList: string;
realmRoleNameError: string;
realmRoleDescriptionInput: string;
saveBtn: string; saveBtn: string;
cancelBtn: string; cancelBtn: string;
constructor() { constructor() {
// cypress IDs
this.kerberosNameInput = "data-cy=kerberos-name"; this.kerberosNameInput = "data-cy=kerberos-name";
this.kerberosRealmInput = "data-cy=kerberos-realm"; this.kerberosRealmInput = "data-cy=kerberos-realm";
this.kerberosPrincipalInput = "data-cy=kerberos-principal"; this.kerberosPrincipalInput = "data-cy=kerberos-principal";
this.kerberosKeytabInput = "data-cy=kerberos-keytab"; this.kerberosKeytabInput = "data-cy=kerberos-keytab";
this.kerberosCachePolicyInput = "#kc-cache-policy"; this.kerberosEnabledInput = "#Kerberos-switch";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.kerberosCacheDayInput = "#kc-eviction-day"; this.kerberosCacheDayInput = "#kc-eviction-day";
this.kerberosCacheDayList = "#kc-eviction-day + ul"; this.kerberosCacheDayList = "#kc-eviction-day + ul";
@ -46,15 +32,11 @@ export default class CreateKerberosProviderPage {
this.kerberosCacheHourList = "#kc-eviction-hour + ul"; this.kerberosCacheHourList = "#kc-eviction-hour + ul";
this.kerberosCacheMinuteInput = "#kc-eviction-minute"; this.kerberosCacheMinuteInput = "#kc-eviction-minute";
this.kerberosCacheMinuteList = "#kc-eviction-minute + ul"; this.kerberosCacheMinuteList = "#kc-eviction-minute + ul";
// this.kerberosCacheLifespanInput = "data-cy=kerberos-cache-lifespan"; this.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul";
this.realmRoleNameError = "#kc-name-helper";
this.realmRoleDescriptionInput = "#kc-role-description";
this.saveBtn = "data-cy=kerberos-save"; this.saveBtn = "data-cy=kerberos-save";
this.cancelBtn = "data-cy=kerberos-cancel"; this.cancelBtn = "data-cy=kerberos-cancel";
// this.cardTitle = "keycloak-card-title";
} }
//#region Required Settings //#region Required Settings
@ -64,7 +46,6 @@ export default class CreateKerberosProviderPage {
principal: string, principal: string,
keytab: string keytab: string
) { ) {
// cy.get(this.realmRoleNameInput).clear();
if (name) { if (name) {
cy.get(`[${this.kerberosNameInput}]`).type(name); cy.get(`[${this.kerberosNameInput}]`).type(name);
} }
@ -77,57 +58,30 @@ export default class CreateKerberosProviderPage {
if (keytab) { if (keytab) {
cy.get(`[${this.kerberosKeytabInput}]`).type(keytab); cy.get(`[${this.kerberosKeytabInput}]`).type(keytab);
} }
return this; return this;
} }
selectCacheType(cacheType: string) { selectCacheType(cacheType: string) {
cy.get(this.kerberosCachePolicyInput).click(); cy.get(this.kerberosCachePolicyInput).click();
cy.get(this.kerberosCachePolicyList).contains(cacheType).click(); cy.get(this.kerberosCachePolicyList).contains(cacheType).click();
return this; return this;
} }
// fillCachedData(day: string, hour: string, minute: string) { disableEnabledSwitch() {
fillCachedData(hour: string, minute: string) { cy.get(this.kerberosEnabledInput).uncheck({ force: true });
// 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) { enableEnabledSwitch() {
// cy.get(this.realmRoleNameError).should((!exist ? "not." : "") + "exist"); cy.get(this.kerberosEnabledInput).check({ force: true });
}
// return this;
// }
//#endregion
save() { save() {
cy.get(`[${this.saveBtn}]`).click(); cy.get(`[${this.saveBtn}]`).click();
return this; return this;
} }
cancel() { cancel() {
cy.get(this.cancelBtn).click(); cy.get(`[${this.cancelBtn}]`).click();
return this; return this;
} }
} }