feat: 12594 - added cypress test of form login on admin setting page (#13178)

* added cypress test of form login on admin setting page

* resotre setting after checked

* added a check if signup form is enabled for all users

* minor fix

Co-authored-by: Ankita Kinger <ankita@appsmith.com>
This commit is contained in:
haojin111 2022-05-06 22:51:08 +08:00 committed by GitHub
parent 4934fc9066
commit b6d2f971c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 179 additions and 3 deletions

View File

@ -0,0 +1,154 @@
const adminSettings = require("../../../../locators/AdminsSettings");
const commonlocators = require("../../../../locators/commonlocators.json");
import homePage from "../../../../locators/HomePage";
describe("Form Login test functionality", function() {
it("1. Go to admin settings and disable Form Signup", function() {
cy.LogOut();
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.visit("/applications");
cy.openAuthentication();
cy.get(adminSettings.formloginButton)
.should("be.visible")
.should("contain", "EDIT");
cy.get(adminSettings.formloginButton).click();
cy.wait(2000);
// disable form signup
cy.get(adminSettings.formSignupDisabled)
.get("input")
.should("have.value", "true");
cy.get(adminSettings.formSignupDisabled).click({ force: true });
cy.wait(2000);
// assert server is restarting
cy.get(adminSettings.saveButton).should("be.visible");
cy.get(adminSettings.saveButton).should("not.be.disabled");
cy.get(adminSettings.saveButton).click();
cy.get(adminSettings.restartNotice).should("be.visible");
// adding wait for server to restart
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.get(homePage.profileMenu).click();
cy.get(homePage.signOutIcon).click();
cy.wait(500);
// validating form signup is disabled
cy.get(".t--sign-up").click({ force: true });
cy.generateUUID().then((uid) => {
cy.get("[type='email']").type(uid + "@appsmith.com");
cy.get("[type='password']").type(uid);
cy.get("[type='submit']").click({ force: true });
cy.get(".form-message-container").should(
"contain",
"Signup is restricted on this instance of Appsmith",
);
// restore setting
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.visit("/applications");
cy.get(".t--profile-menu-icon").click();
cy.get(".t--admin-settings-menu").click();
cy.get(adminSettings.authenticationTab).click();
cy.get(adminSettings.formloginButton).click();
cy.wait(2000);
cy.get(adminSettings.formSignupDisabled).click({ force: true });
cy.wait(2000);
cy.get(adminSettings.saveButton).click();
cy.get(adminSettings.restartNotice).should("be.visible");
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.get(homePage.profileMenu).click();
cy.get(homePage.signOutIcon).click();
});
cy.wait(500);
// validating form signup is disabled
cy.get(".t--sign-up").click({ force: true });
cy.generateUUID().then((uid) => {
cy.get("[type='email']").type(uid + "@appsmith.com");
cy.get("[type='password']").type(uid);
cy.get("[type='submit']").click({ force: true });
cy.get(".form-message-container").should("not.exist");
});
});
it("2. Go to admin settings and disable Form Login", function() {
cy.LogOut();
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.visit("/applications");
cy.openAuthentication();
cy.get(adminSettings.formloginButton)
.should("be.visible")
.should("contain", "EDIT");
// enable github login
cy.get(adminSettings.githubButton).click();
cy.wait(2000);
// fill github form
cy.fillGithubForm();
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.wait(5000);
cy.reload();
cy.get(adminSettings.authenticationTab).click();
cy.get(adminSettings.formloginButton).click();
cy.wait(2000);
// disable form signup
cy.get(adminSettings.formLoginDisabled)
.get("input")
.should("have.value", "true");
cy.get(adminSettings.formLoginDisabled).click({ force: true });
cy.wait(2000);
// assert server is restarting
cy.get(adminSettings.saveButton).should("be.visible");
cy.get(adminSettings.saveButton).should("not.be.disabled");
cy.get(adminSettings.saveButton).click();
cy.get(adminSettings.restartNotice).should("be.visible");
// adding wait for server to restart
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.get(homePage.profileMenu).click();
cy.get(homePage.signOutIcon).click();
cy.wait(500);
cy.reload();
cy.wait(5000);
// validating form signup is disabled
cy.get("form").should("not.exist");
cy.get(".t--sign-up").should("not.exist");
// cy.wait(30000); // restart nginx docker
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
cy.visit("/applications");
cy.openAuthentication();
// enable form login
cy.get(adminSettings.formloginButton)
.should("be.visible")
.should("contain", "ENABLE");
cy.get(adminSettings.formloginButton).click();
cy.get(adminSettings.formLoginDisabled).click({ force: true });
cy.wait(2000);
// assert server is restarting
cy.get(adminSettings.saveButton).should("be.visible");
cy.get(adminSettings.saveButton).should("not.be.disabled");
cy.get(adminSettings.saveButton).click();
cy.get(adminSettings.restartNotice).should("be.visible");
// adding wait for server to restart
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.reload();
// disable github
cy.get(adminSettings.authenticationTab).click();
cy.get(adminSettings.githubButton).click();
cy.wait(2000);
cy.get(adminSettings.disconnectBtn)
.click()
.should("contain", "Are you sure?");
cy.get(adminSettings.disconnectBtn).click();
cy.wait(120000);
cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible"));
cy.reload();
cy.get(homePage.profileMenu).click();
cy.get(homePage.signOutIcon).click();
cy.wait(500);
cy.get(adminSettings.loginWithGithub).should("not.exist");
cy.get("form").should("exist");
cy.get(".t--sign-up").should("exist");
});
});

View File

@ -23,4 +23,6 @@ export default {
loginWithGoogle: "[data-testid='login-with-Google']",
loginWithGithub: "[data-testid='login-with-Github']",
disconnectBtn: "[data-testid='disconnect-service-button']",
formSignupDisabled: "[data-cy='APPSMITH_SIGNUP_DISABLED']",
formLoginDisabled: "[data-cy='APPSMITH_FORM_LOGIN_DISABLED']",
};

View File

@ -7,6 +7,7 @@ require("cypress-file-upload");
const googleForm = require("../locators/GoogleForm.json");
const googleData = require("../fixtures/googleSource.json");
const githubForm = require("../locators/GithubForm.json");
const adminSettings = require("../locators/AdminsSettings");
Cypress.Commands.add("fillGoogleFormPartly", () => {
cy.get(googleForm.googleClientId).type(
@ -43,3 +44,15 @@ Cypress.Commands.add("fillGithubForm", () => {
);
cy.get(githubForm.saveBtn).click({ force: true });
});
// open authentication page
Cypress.Commands.add("openAuthentication", () => {
cy.get(".t--profile-menu-icon").should("be.visible");
cy.get(".t--profile-menu-icon").click();
cy.get(".t--admin-settings-menu").should("be.visible");
cy.get(".t--admin-settings-menu").click();
cy.url().should("contain", "/settings/general");
// click authentication tab
cy.get(adminSettings.authenticationTab).click();
cy.url().should("contain", "/settings/authentication");
});

View File

@ -19,7 +19,10 @@ const ToggleStatus = styled.span`
margin-left: 64px;
`;
function FieldToggleWithToggleText(toggleText?: (value: boolean) => string) {
function FieldToggleWithToggleText(
toggleText?: (value: boolean) => string,
id?: string,
) {
return function FieldToggle(
componentProps: FormTextFieldProps & {
meta: Partial<WrappedFieldMetaProps>;
@ -35,7 +38,11 @@ function FieldToggleWithToggleText(toggleText?: (value: boolean) => string) {
*/
return (
<ToggleWrapper>
<Toggle onToggle={onToggle} value={!componentProps.input.value} />
<Toggle
cypressSelector={id}
onToggle={onToggle}
value={!componentProps.input.value}
/>
<ToggleStatus>
{typeof toggleText == "function"
? createMessage(() => toggleText(!componentProps.input.value))
@ -57,7 +64,7 @@ export function ToggleComponent({ setting }: SettingComponentProps) {
<StyledFieldToggleGroup>
<FormGroup setting={setting}>
<Field
component={FieldToggleWithToggleText(setting.toggleText)}
component={FieldToggleWithToggleText(setting.toggleText, setting.id)}
name={setting.name}
/>
</FormGroup>