test(policies): add cypress test for managing policies (#8554)

This commit is contained in:
Kos Korchak 2023-08-04 07:07:39 -04:00 committed by GitHub
parent b8681a7129
commit faa368c2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 173 additions and 17 deletions

View File

@ -285,6 +285,7 @@ export default function PolicyActorForm({ policyType, actors, setActors }: Props
users. users.
</Typography.Paragraph> </Typography.Paragraph>
<Select <Select
data-testid="users"
value={usersSelectValue} value={usersSelectValue}
mode="multiple" mode="multiple"
filterOption={false} filterOption={false}
@ -306,6 +307,7 @@ export default function PolicyActorForm({ policyType, actors, setActors }: Props
all groups. all groups.
</Typography.Paragraph> </Typography.Paragraph>
<Select <Select
data-testid="groups"
value={groupsSelectValue} value={groupsSelectValue}
mode="multiple" mode="multiple"
placeholder="Search for groups..." placeholder="Search for groups..."

View File

@ -374,6 +374,7 @@ export default function PolicyPrivilegeForm({
<Form.Item label={<Typography.Text strong>Privileges</Typography.Text>}> <Form.Item label={<Typography.Text strong>Privileges</Typography.Text>}>
<Typography.Paragraph>Select a set of privileges to permit.</Typography.Paragraph> <Typography.Paragraph>Select a set of privileges to permit.</Typography.Paragraph>
<Select <Select
data-testid="privileges"
value={privilegesSelectValue} value={privilegesSelectValue}
mode="multiple" mode="multiple"
onSelect={(value: string) => onSelectPrivilege(value)} onSelect={(value: string) => onSelectPrivilege(value)}

View File

@ -42,15 +42,24 @@ export default function PolicyTypeForm({
<Typography.Paragraph>A name for your new policy.</Typography.Paragraph> <Typography.Paragraph>A name for your new policy.</Typography.Paragraph>
<Input <Input
placeholder="Your policy name" placeholder="Your policy name"
data-testid="policy-name"
value={policyName} value={policyName}
onChange={(event) => updatePolicyName(event.target.value)} onChange={(event) => updatePolicyName(event.target.value)}
/> />
</Form.Item> </Form.Item>
<Form.Item name="policyType" label={<Typography.Text strong>Type</Typography.Text>}> <Form.Item name="policyType" label={<Typography.Text strong>Type</Typography.Text>}>
<Typography.Paragraph>The type of policy you would like to create.</Typography.Paragraph> <Typography.Paragraph>The type of policy you would like to create.</Typography.Paragraph>
<Select defaultValue={policyType} onSelect={(value) => setPolicyType(value as PolicyType)}> <Select
<Select.Option value={PolicyType.Platform}>Platform</Select.Option> data-testid="policy-type"
<Select.Option value={PolicyType.Metadata}>Metadata</Select.Option> defaultValue={policyType}
onSelect={(value) => setPolicyType(value as PolicyType)}
>
<Select.Option data-testid="platform" value={PolicyType.Platform}>
Platform
</Select.Option>
<Select.Option data-testid="metadata" value={PolicyType.Metadata}>
Metadata
</Select.Option>
</Select> </Select>
<TypeDescriptionParagraph type="secondary"> <TypeDescriptionParagraph type="secondary">
The <b>Platform</b> policy type allows you to assign top-level DataHub Platform privileges to users. The <b>Platform</b> policy type allows you to assign top-level DataHub Platform privileges to users.
@ -70,6 +79,7 @@ export default function PolicyTypeForm({
<Typography.Paragraph>An optional description for your new policy.</Typography.Paragraph> <Typography.Paragraph>An optional description for your new policy.</Typography.Paragraph>
<Input <Input
placeholder="Your policy description" placeholder="Your policy description"
data-testid="policy-description"
value={policyDescription} value={policyDescription}
onChange={(event) => setPolicyDescription(event.target.value)} onChange={(event) => setPolicyDescription(event.target.value)}
/> />

View File

@ -5,7 +5,7 @@ const test_domain_urn = `urn:li:domain:${test_domain_id}`
describe("add remove domain", () => { describe("add remove domain", () => {
it("create domain", () => { it("create domain", () => {
cy.login(); cy.loginWithCredentials();
cy.goToDomainList(); cy.goToDomainList();
cy.clickOptionWithText("New Domain"); cy.clickOptionWithText("New Domain");
cy.waitTextVisible("Create new Domain"); cy.waitTextVisible("Create new Domain");
@ -17,30 +17,22 @@ describe("add remove domain", () => {
}) })
it("add entities to domain", () => { it("add entities to domain", () => {
cy.login(); cy.loginWithCredentials();
cy.goToDomainList(); cy.goToDomainList();
cy.clickOptionWithText(test_domain); cy.clickOptionWithText(test_domain);
cy.waitTextVisible("Add assets") cy.waitTextVisible("Add assets")
cy.clickOptionWithText("Add assets") cy.clickOptionWithText("Add assets")
cy.get(".ant-modal-content").within(() => { cy.get(".ant-modal-content").within(() => {
cy.get('[data-testid="search-input"]').click().invoke("val", "cypress_project.jaffle_shop.").type("customer") cy.get('[data-testid="search-input"]').click().invoke("val", "cypress_project.jaffle_shop.").type("customer")
cy.contains("BigQuery") cy.contains("BigQuery", {timeout: 30000 })
cy.get(".ant-checkbox-input").first().click() cy.get(".ant-checkbox-input").first().click()
cy.get("#continueButton").click() cy.get("#continueButton").click()
}) })
cy.waitTextVisible("Added assets to Domain!") cy.waitTextVisible("Added assets to Domain!")
}) })
it("search filter by domain", () => {
cy.login();
cy.goToStarSearchList()
cy.waitTextVisible(test_domain)
cy.get('[data-testid="facet-domains-' + test_domain_urn + '"]').click()
cy.waitTextVisible("customers")
})
it("remove entity from domain", () => { it("remove entity from domain", () => {
cy.login(); cy.loginWithCredentials();
cy.goToDomainList(); cy.goToDomainList();
cy.removeDomainFromDataset( cy.removeDomainFromDataset(
"urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.customers,PROD)", "urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.customers,PROD)",
@ -50,13 +42,12 @@ describe("add remove domain", () => {
}) })
it("delete a domain and ensure dangling reference is deleted on entities", () => { it("delete a domain and ensure dangling reference is deleted on entities", () => {
cy.login(); cy.loginWithCredentials();
cy.goToDomainList(); cy.goToDomainList();
cy.get('[data-testid="dropdown-menu-' + test_domain_urn + '"]').click(); cy.get('[data-testid="dropdown-menu-' + test_domain_urn + '"]').click();
cy.clickOptionWithText("Delete"); cy.clickOptionWithText("Delete");
cy.clickOptionWithText("Yes"); cy.clickOptionWithText("Yes");
cy.ensureTextNotPresent(test_domain) cy.ensureTextNotPresent(test_domain)
cy.goToContainer("urn:li:container:348c96555971d3f5c1ffd7dd2e7446cb") cy.goToContainer("urn:li:container:348c96555971d3f5c1ffd7dd2e7446cb")
cy.waitTextVisible("customers") cy.waitTextVisible("customers")
cy.ensureTextNotPresent(test_domain) cy.ensureTextNotPresent(test_domain)

View File

@ -0,0 +1,152 @@
const test_id = Math.floor(Math.random() * 100000);
const platform_policy_name = `Platform test policy ${test_id}`;
const platform_policy_edited = `Platform test policy ${test_id} EDITED`;
const metadata_policy_name = `Metadata test policy ${test_id}`;
const metadata_policy_edited = `Metadata test policy ${test_id} EDITED`;
describe("create and manage platform and metadata policies", () => {
it("create platform policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.waitTextVisible("Manage Permissions");
cy.clickOptionWithText("Create new policy");
cy.clickOptionWithTestId("policy-name")
.focused()
.type(platform_policy_name);
cy.get('[data-testid="policy-type"] [title="Metadata"]').click();
cy.clickOptionWithTestId("platform");
cy.clickOptionWithTestId("policy-description")
.focused()
.type(`Platform policy description ${test_id}`);
cy.get("#nextButton").click();
cy.get('[data-testid="privileges"]').type("All");
cy.clickOptionWithText("All Privileges").focused().blur();
cy.get("#nextButton").click();
cy.get('[data-testid="users"]').type("All");
cy.get("[title='All Users']").click();
cy.focused().blur();
cy.get('[data-testid="groups"]').type("All");
cy.get("[title='All Groups']").click();
cy.focused().blur();
cy.get("#saveButton").click();
cy.waitTextVisible("Successfully saved policy.");
cy.waitTextVisible(platform_policy_name);
});
it("edit platform policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.contains('tr', `${platform_policy_name}` )
.contains('EDIT')
.click();
cy.clickOptionWithTestId("policy-name");
cy.focused().clear().type(platform_policy_edited);
cy.clickOptionWithTestId("policy-description");
cy.focused().clear().type(`Platform policy description ${test_id} EDITED`);
cy.get("#nextButton").click();
cy.get("#nextButton").click();
cy.get("#saveButton").click();
cy.waitTextVisible("Successfully saved policy.");
cy.waitTextVisible(platform_policy_edited);
cy.waitTextVisible(`Platform policy description ${test_id} EDITED`);
});
it("deactivate and activate platform policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.contains('tr', `${platform_policy_edited}` )
.contains('DEACTIVATE')
.click();
cy.waitTextVisible("Successfully deactivated policy.")
cy.contains('tr', `${platform_policy_edited}` )
.contains('INACTIVE')
.should("be.visible");
cy.contains('tr', `${platform_policy_edited}` )
.contains('ACTIVATE')
.click();
cy.waitTextVisible("Successfully activated policy.")
cy.contains('tr', `${platform_policy_edited}` )
.contains('ACTIVE')
.should("be.visible");
cy.contains('tr', `${platform_policy_edited}` )
.find("[data-icon='delete']")
.click();
cy.waitTextVisible(`Delete ${platform_policy_edited}`);
cy.clickOptionWithText("Yes");
cy.waitTextVisible("Successfully removed policy.");
cy.ensureTextNotPresent(`${platform_policy_edited}`);
});
it("create metadata policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.clickOptionWithText("Create new policy");
cy.clickOptionWithTestId("policy-name")
.focused()
.type(metadata_policy_name);
cy.get('[data-testid="policy-type"]').should('have.text', 'Metadata');
cy.clickOptionWithTestId("policy-description")
.focused()
.type(`Metadata policy description ${test_id}`);
cy.get("#nextButton").click();
cy.get('[data-testid="privileges"]').type("All");
cy.clickOptionWithText("All Privileges").focused().blur();
cy.get("#nextButton").click();
cy.get('[data-testid="users"]').type("All");
cy.get("[title='All Users']").click();
cy.focused().blur();
cy.get('[data-testid="groups"]').type("All");
cy.get("[title='All Groups']").click();
cy.focused().blur();
cy.get("#saveButton").click();
cy.waitTextVisible("Successfully saved policy.");
cy.waitTextVisible(metadata_policy_name);
});
it("edit metadata policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.contains('tr', `${metadata_policy_name}` )
.contains('EDIT')
.click();
cy.clickOptionWithTestId("policy-name")
cy.focused().clear().type(metadata_policy_edited);
cy.clickOptionWithTestId("policy-description");
cy.focused().clear().type(`Metadata policy description ${test_id} EDITED`);
cy.get("#nextButton").click();
cy.get("#nextButton").click();
cy.get("#saveButton").click();
cy.waitTextVisible("Successfully saved policy.");
cy.waitTextVisible(metadata_policy_edited);
cy.waitTextVisible(`Metadata policy description ${test_id} EDITED`);
});
it("deactivate and activate metadata policy", () => {
cy.loginWithCredentials();
cy.visit("/settings/permissions/policies");
cy.contains('tr', `${metadata_policy_edited}` )
.contains('DEACTIVATE')
.click();
cy.waitTextVisible("Successfully deactivated policy.")
cy.contains('tr', `${metadata_policy_edited}` )
.contains('INACTIVE')
.should("be.visible");
cy.contains('tr', `${metadata_policy_edited}` )
.contains('ACTIVATE')
.click();
cy.waitTextVisible("Successfully activated policy.")
cy.contains('tr', `${metadata_policy_edited}` )
.contains('ACTIVE')
.should("be.visible");
cy.contains('tr', `${metadata_policy_edited}` )
.find("[data-icon='delete']")
.click();
cy.waitTextVisible(`Delete ${metadata_policy_edited}`);
cy.clickOptionWithText("Yes");
cy.waitTextVisible("Successfully removed policy.");
cy.ensureTextNotPresent(`${metadata_policy_edited}`);
});
});