mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 18:36:08 +00:00
Improve Cypress test coverage Part 1 (#7751)
* Improve Cypress test coverage Part 1 * Test Add role and assign it to the user * Address review comments
This commit is contained in:
parent
cd5c143011
commit
48c5320abb
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2021 Collate
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { descriptionBox, interceptURL, login, uuid, verifyResponseStatusCode } from "../../common/common";
|
||||
import { LOGIN } from "../../constants/constants";
|
||||
|
||||
const roleName = `Role-test-${uuid()}`;
|
||||
const userName = `Usercttest${uuid()}`;
|
||||
const userEmail = `${userName}@gmail.com`;
|
||||
|
||||
describe("Test Add role and assign it to the user", () => {
|
||||
beforeEach(() => {
|
||||
login(LOGIN.username, LOGIN.password);
|
||||
cy.goToHomePage();
|
||||
|
||||
interceptURL('GET', '*api/v1/roles*', 'getRoles');
|
||||
|
||||
cy.get('[data-testid="appbar-item-settings"]').should('be.visible').click();
|
||||
|
||||
cy.get('[data-menu-id*="roles"]').should('be.visible').click();
|
||||
|
||||
verifyResponseStatusCode('@getRoles', 200);
|
||||
|
||||
cy.url().should('eq', 'http://localhost:8585/settings/access/roles');
|
||||
});
|
||||
|
||||
it("Create and Assign role to user", () => {
|
||||
cy.get('[data-testid="add-role"]')
|
||||
.contains('Add Role')
|
||||
.should('be.visible')
|
||||
.click();
|
||||
|
||||
//Asserting navigation
|
||||
cy.get('[data-testid="inactive-link"]')
|
||||
.should('contain', 'Add New Role')
|
||||
.should('be.visible');
|
||||
//Entering name
|
||||
cy.get('#name').should('be.visible').type(roleName);
|
||||
//Entering descrription
|
||||
cy.get(descriptionBox).type("description");
|
||||
//Select the policies
|
||||
cy.get('.ant-select').should('be.visible').click();
|
||||
|
||||
cy.get('[title="Data Consumer Policy"]')
|
||||
.scrollIntoView()
|
||||
.should('be.visible')
|
||||
.click();
|
||||
|
||||
cy.get('[title="Data Steward Policy"]')
|
||||
.scrollIntoView()
|
||||
.should('be.visible')
|
||||
.click();
|
||||
//Clicking outside to close the dropdown
|
||||
cy.get('.ant-card-body').click();
|
||||
//Save the role
|
||||
cy.get('[data-testid="submit-btn"]')
|
||||
.scrollIntoView()
|
||||
.should('be.visible')
|
||||
.click();
|
||||
|
||||
//Verify the role is added successfully
|
||||
cy.url().should(
|
||||
'eq',
|
||||
`http://localhost:8585/settings/access/roles/${roleName}`
|
||||
);
|
||||
cy.get('[data-testid="inactive-link"]').should('contain', roleName);
|
||||
|
||||
//Verify added description
|
||||
cy.get('[data-testid="description"] > [data-testid="viewer-container"]')
|
||||
.should('be.visible')
|
||||
.should('contain', "description");
|
||||
|
||||
// Create user and assign newly created role to the user
|
||||
cy.get('[data-menu-id*="users"]').should('be.visible').click();
|
||||
|
||||
cy.get('[data-testid="add-user"]').contains('Add User').click();
|
||||
|
||||
cy.get('[data-testid="email"]')
|
||||
.scrollIntoView()
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.type(userEmail);
|
||||
|
||||
cy.get('[data-testid="displayName"]')
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.type(userName);
|
||||
|
||||
cy.get(descriptionBox)
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.type('Adding user');
|
||||
|
||||
cy.get(`[id="menu-button-Roles"]`).should("exist").should("be.visible").click()
|
||||
|
||||
cy.get(`[data-testid="${roleName}"]`).should("be.visible").click()
|
||||
|
||||
cy.get('body').click()
|
||||
|
||||
cy.get('[data-testid="save-user"]').scrollIntoView().click();
|
||||
|
||||
|
||||
})
|
||||
})
|
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2021 Collate
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { addTeam, interceptURL, login, searchEntity, uuid, verifyResponseStatusCode } from "../../common/common";
|
||||
import { LOGIN } from "../../constants/constants";
|
||||
|
||||
|
||||
const teamName = `team-group-test-${uuid()}`;
|
||||
const TEAM_DETAILS = {
|
||||
name: teamName,
|
||||
displayName: teamName,
|
||||
teamType: 'Group',
|
||||
description: `This is ${teamName} description`,
|
||||
assetName: 'fact_sale',
|
||||
};
|
||||
|
||||
|
||||
describe("Create a team and add that team as a owner of the entity", () => {
|
||||
beforeEach(() => {
|
||||
login(LOGIN.username, LOGIN.password);
|
||||
cy.goToHomePage();
|
||||
});
|
||||
|
||||
/**
|
||||
* Here we are adding team of type group as
|
||||
* Only team of type group can own the entities
|
||||
*/
|
||||
it("Add a group team type and assign it as a owner of the entity", () => {
|
||||
|
||||
cy.get('[data-testid="appbar-item-settings"]').should('be.visible').click();
|
||||
interceptURL('GET', '/api/v1/users*', 'getTeams');
|
||||
|
||||
//Clicking on teams
|
||||
cy.get('[data-menu-id*="teams"]')
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.click();
|
||||
|
||||
verifyResponseStatusCode('@getTeams', 200);
|
||||
|
||||
addTeam(TEAM_DETAILS);
|
||||
|
||||
cy.reload();
|
||||
|
||||
/**
|
||||
* Check for added team details
|
||||
*/
|
||||
cy.get('table').find('.ant-table-row').should('contain', TEAM_DETAILS.name);
|
||||
cy.get('table')
|
||||
.find('.ant-table-row')
|
||||
.should('contain', TEAM_DETAILS.description);
|
||||
|
||||
searchEntity(TEAM_DETAILS.assetName);
|
||||
|
||||
interceptURL('GET', 'api/v1/tables/name/*', 'getEntityDetails');
|
||||
|
||||
cy.get('[data-testid="table-link"]').first().should('be.visible').click();
|
||||
|
||||
verifyResponseStatusCode('@getEntityDetails', 200);
|
||||
|
||||
interceptURL(
|
||||
'GET',
|
||||
'/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=10&index=team_search_index',
|
||||
'waitForTeams'
|
||||
);
|
||||
|
||||
cy.get('[data-testid="edit-Owner-icon"]').should('be.visible').click();
|
||||
|
||||
verifyResponseStatusCode('@waitForTeams', 200);
|
||||
|
||||
interceptURL('PATCH', '/api/v1/tables/*', 'validateOwner');
|
||||
|
||||
cy.get('[data-testid="searchInputText"]').should("be.visible").type(TEAM_DETAILS.displayName)
|
||||
|
||||
//Selecting the team
|
||||
cy.get(`[title="${TEAM_DETAILS.displayName}"]`)
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
.click();
|
||||
|
||||
verifyResponseStatusCode('@validateOwner', 200);
|
||||
|
||||
cy.get('[data-testid="owner-link"]')
|
||||
.scrollIntoView()
|
||||
.invoke('text')
|
||||
.then((text) => {
|
||||
expect(text).equal(TEAM_DETAILS.displayName);
|
||||
});
|
||||
})
|
||||
|
||||
})
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2021 Collate
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { interceptURL, login, searchEntity, verifyResponseStatusCode } from "../../common/common";
|
||||
import { LOGIN } from "../../constants/constants";
|
||||
|
||||
const assetName = "fact_sale"
|
||||
const token = localStorage.getItem("oidcIdToken")
|
||||
const userURL = "/api/v1/search/query?q=***&from=0&size=10&index=user_search_index"
|
||||
const teamURL = "/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=10&index=team_search_index"
|
||||
|
||||
|
||||
describe("Test if the total count of users and teams is correctly displayed in the assign owner widget", () => {
|
||||
beforeEach(() => {
|
||||
login(LOGIN.username, LOGIN.password);
|
||||
cy.goToHomePage();
|
||||
});
|
||||
|
||||
it("Check total count of users and teams", () => {
|
||||
searchEntity(assetName);
|
||||
|
||||
cy.get('[data-testid="table-link"]').first().should('be.visible').click();
|
||||
|
||||
interceptURL('GET', 'api/v1/tables/name/*', 'getEntityDetails');
|
||||
|
||||
verifyResponseStatusCode('@getEntityDetails', 200);
|
||||
|
||||
cy.request({method:"GET",url:userURL,headers:{Authorization:`Bearer ${token}`}}).as("UserCount")
|
||||
cy.request({method:"GET",url:teamURL,headers:{Authorization:`Bearer ${token}`}}).as("TeamCount")
|
||||
|
||||
|
||||
cy.get('[data-testid="edit-Owner-icon"]').should('be.visible').click();
|
||||
|
||||
// check for teams count
|
||||
cy.get('@TeamCount').then((response) => {
|
||||
const teamCount = response.body.hits.total.value
|
||||
cy.get('[data-testid="filter-count"]').eq(0).contains(`${teamCount}`)
|
||||
})
|
||||
|
||||
// check for user count
|
||||
cy.get('@UserCount').then((response) => {
|
||||
const userCount = response.body.hits.total.value
|
||||
cy.get('[data-testid="filter-count"]').eq(1).contains(`${userCount}`)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
@ -198,7 +198,7 @@ const UserListV1: FC<UserListV1Props> = ({
|
||||
buttons={
|
||||
<Button
|
||||
ghost
|
||||
// data-testid="add-user"
|
||||
data-testid="add-user"
|
||||
disabled={!createPermission}
|
||||
type="primary"
|
||||
onClick={handleAddNewUser}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user