PromucFlow_constructor/app/client/cypress/support/Pages/AdminSettings.ts
Jacques Ikot eca0daa1bb
fix: enable form login spec improvement (#40693)
## Description

- Convert entire test case to typescript
- Abstract repetitive code to functions
- Remove all waits and use UI assertions
- Better comments

## Automation

/ok-to-test tags="@tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/15601034361>
> Commit: 90c06c0accff37d8aaf61279df48ec8291010c4f
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=15601034361&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Thu, 12 Jun 2025 04:26:52 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Tests**
- Replaced existing Cypress tests with a new suite verifying toggling of
form login, signup, and GitHub authentication, including UI validations
and server restart handling.
- **New Features**
- Enhanced admin settings automation with navigation and controls for
authentication options, including GitHub OAuth configuration and form
login/signup toggles.
- **Chores**
	- Added a new locator for the login form to support UI testing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-06-11 23:01:13 -07:00

153 lines
5.3 KiB
TypeScript

import AdminsSettings from "../../locators/AdminsSettings";
import githubForm from "../../locators/GithubForm.json";
import HomePage from "../../locators/HomePage";
import { featureFlagIntercept } from "../Objects/FeatureFlags";
import { ObjectsRegistry } from "../Objects/Registry";
export class AdminSettings {
public agHelper = ObjectsRegistry.AggregateHelper;
public locator = ObjectsRegistry.CommonLocators;
public homePage = ObjectsRegistry.HomePage;
public assertHelper = ObjectsRegistry.AssertHelper;
public _adminSettingsBtn = ".admin-settings-menu-option";
public _authenticationTab = ".t--settings-category-authentication";
public _saveButton = ".t--admin-settings-save-button";
private _settingsList = ".t--settings-category-list";
public _usersTab = ".t--settings-category-users";
public _roles = (user: string) =>
"//span[contains(text(), '" +
user +
"')]/parent::div/parent::span/parent::a/parent::td/following-sibling::td[1]";
public _instanceName = '[name="instanceName"]';
public _googleMapsAPIField = '[name="googleMapsKey"]';
public rolesTab = ".t--settings-category-roles";
public auditLogsTab = ".t--settings-category-audit-logs";
public routes = {
APPLICATIONS: "/applications",
SETTINGS: "/settings",
PROFILE: "/settings/profile",
GENERAL: "/settings/general",
EMAIL: "/settings/email",
USER_SETTINGS: "/settings/user-settings",
INSTANCE_SETTINGS: "/settings/instance-settings",
CONFIGURATION: "/settings/configuration",
VERSION: "/settings/version",
AUTHENTICATION: "/settings/authentication",
GOOGLEAUTH: "/settings/authentication/google-auth",
GITHUBAUTH: "/settings/authentication/github-auth",
FORMLOGIN: "/settings/authentication/form-login",
BRANDING: "/settings/branding",
ACCESS_CONTROL: "/settings/access-control",
AUDIT_LOGS: "/settings/audit-logs",
PROVISIONING: "/settings/provisioning",
};
public NavigateToAdminSettings(toNavigateToHome = true) {
toNavigateToHome && this.homePage.NavigateToHome();
this.agHelper.AssertElementVisibility(this._adminSettingsBtn);
this.agHelper.GetNClick(this._adminSettingsBtn);
this.assertHelper.AssertNetworkStatus("getEnvVariables");
this.agHelper.AssertElementVisibility(this._settingsList);
}
public NavigateToAuthenticationSettings(toNavigateToHome = true) {
this.NavigateToAdminSettings(toNavigateToHome);
this.agHelper.GetNClick(this._authenticationTab);
}
public FillAndSaveGithubForm() {
this.agHelper.GetNClick(githubForm.githubClientId);
this.agHelper.TypeText(
githubForm.githubClientId,
Cypress.env("APPSMITH_OAUTH2_GITHUB_CLIENT_ID"),
);
this.agHelper.GetNClick(githubForm.githubClientSecret);
this.agHelper.TypeText(
githubForm.githubClientSecret,
Cypress.env("APPSMITH_OAUTH2_GITHUB_CLIENT_SECRET"),
);
this.agHelper.GetNClick(githubForm.saveBtn);
}
public fillSaveAndAssertGithubForm() {
this.FillAndSaveGithubForm();
this.agHelper.WaitUntilEleAppear(AdminsSettings.restartNotice);
this.agHelper.AssertElementAbsence(AdminsSettings.restartNotice, 200000);
}
public toggleFormSignupLoginAndSave(enable = true, type = "signup") {
const selector =
type === "signup"
? AdminsSettings.formSignupDisabled
: AdminsSettings.formLoginEnabled;
this.agHelper.GetNClick(AdminsSettings.formloginButton);
this.agHelper.WaitUntilEleAppear(selector);
if (enable) {
this.agHelper.GetElement(selector).then(($el) => {
if (!$el.prop("checked")) {
this.agHelper.GetNClick(selector);
}
});
} else {
this.agHelper.GetElement(selector).then(($el) => {
if ($el.prop("checked")) {
this.agHelper.GetNClick(selector);
}
});
}
this.agHelper.AssertElementVisibility(AdminsSettings.saveButton);
this.agHelper.GetNClick(AdminsSettings.saveButton);
this.agHelper.WaitUntilToastDisappear("Successfully saved");
}
public EnableGAC(
toNavigateToHome = true,
toNavigateBackToHome = true,
methodType: "adminSettings" | "home" = "adminSettings",
) {
switch (methodType) {
case "adminSettings":
this.NavigateToAdminSettings(toNavigateToHome);
this.enableGACFeatureFlag();
this.assertHelper.AssertDocumentReady();
this.agHelper.WaitUntilEleAppear(this.rolesTab);
this.agHelper.AssertElementExist(this.rolesTab);
this.agHelper.AssertElementVisibility(this.rolesTab);
toNavigateBackToHome && this.homePage.NavigateToHome();
break;
case "home":
toNavigateToHome && this.homePage.NavigateToHome();
this.enableGACFeatureFlag();
this.assertHelper.AssertDocumentReady();
this.agHelper.AssertElementExist(this.homePage._homePageContainer);
this.agHelper.AssertElementVisibility(this.homePage._homePageContainer);
break;
default:
break;
}
}
public logoutFromApp() {
this.agHelper.GetNClick(HomePage.profileMenu);
this.agHelper.GetNClick(HomePage.signOutIcon);
}
public verifyFormLogin() {
this.agHelper.AssertElementVisibility(AdminsSettings.formloginButton);
this.agHelper.AssertContains(
"Edit",
"exist",
AdminsSettings.formloginButton,
);
}
private enableGACFeatureFlag() {
featureFlagIntercept({ license_gac_enabled: true });
}
}