From 7be72a13f29f21df7ac4bc7d631757ea70568819 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Wed, 26 Jul 2023 23:53:47 +0530 Subject: [PATCH] cypress: work on e2e cypress part 1 (#12606) * cypress: work on e2e cypress part 1 * updated Announcement cypress --- .../e2e/Flow/AddRoleAndAssignToUser.spec.js | 78 +++------- .../e2e/Flow/EntityAnnouncement.spec.js | 137 ++++++++++++------ .../e2e/Pages/DataInsightAlert.spec.js | 101 +++++-------- .../CreateUser/CreateUser.component.tsx | 3 + .../resources/ui/src/styles/variables.less | 2 +- 5 files changed, 157 insertions(+), 164 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/AddRoleAndAssignToUser.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/AddRoleAndAssignToUser.spec.js index 49de7e8ede8..d16b70d415a 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/AddRoleAndAssignToUser.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/AddRoleAndAssignToUser.spec.js @@ -35,45 +35,32 @@ describe('Test Add role and assign it to the user', () => { cy.get('[data-menu-id*="roles"]').should('be.visible').click(); verifyResponseStatusCode('@getRoles', 200); - cy.get('[data-testid="add-role"]') - .contains('Add Role') - .should('be.visible') - .click(); + cy.get('[data-testid="add-role"]').contains('Add Role').click(); // Asserting navigation - cy.get('[data-testid="inactive-link"]') - .should('contain', 'Add New Role') - .should('be.visible'); + cy.get('[data-testid="inactive-link"]').should('contain', 'Add New Role'); + // Entering name - cy.get('#name').should('be.visible').type(roleName); + cy.get('#name').type(roleName); // Entering descrription cy.get(descriptionBox).type('description'); // Select the policies - cy.get('[data-testid="policies"]').should('be.visible').click(); + cy.get('[data-testid="policies"]').click(); - cy.get('[title="Data Consumer Policy"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[title="Data Consumer Policy"]').scrollIntoView().click(); - cy.get('[title="Data Steward Policy"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[title="Data Steward Policy"]').scrollIntoView().click(); // Save the role - cy.get('[data-testid="submit-btn"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[data-testid="submit-btn"]').scrollIntoView().click(); // Verify the role is added successfully cy.url().should('eq', `${BASE_URL}/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'); + cy.get( + '[data-testid="description"] > [data-testid="viewer-container"]' + ).should('contain', 'description'); }); it('Create new user and assign new role to him', () => { @@ -83,41 +70,23 @@ describe('Test Add role and assign it to the user', () => { 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="email"]').scrollIntoView().type(userEmail); - cy.get('[data-testid="displayName"]') - .should('exist') - .should('be.visible') - .type(userName); + cy.get('[data-testid="displayName"]').type(userName); - cy.get(descriptionBox) - .should('exist') - .should('be.visible') - .type('Adding user'); + cy.get(descriptionBox).type('Adding user'); interceptURL('GET', '/api/v1/users/generateRandomPwd', 'generatePassword'); - cy.get('[data-testid="password-generator"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[data-testid="password-generator"]').scrollIntoView().click(); verifyResponseStatusCode('@generatePassword', 200); - cy.get(`[data-testid="roles-dropdown"]`) - .scrollIntoView() - .should('be.visible'); + cy.get(`[data-testid="roles-dropdown"]`).type(roleName); + cy.get(`.ant-select-dropdown [title="${roleName}"]`).click(); - cy.get(`[data-testid="roles-dropdown"]`).click(); - - cy.get(`[title="${roleName}"]`).scrollIntoView().should('be.visible'); - - cy.get(`[title="${roleName}"]`).click(); - - cy.get('[data-testid="roles-dropdown"]').click(); + cy.clickOutside(); + interceptURL('POST', '/api/v1/users', 'createUser'); cy.get('[data-testid="save-user"]').scrollIntoView().click(); + verifyResponseStatusCode('@createUser', 201); }); it('Verify assigned role to new user', () => { @@ -130,13 +99,10 @@ describe('Test Add role and assign it to the user', () => { 'searchUser' ); interceptURL('GET', '/api/v1/users/*', 'userDetailsPage'); - cy.get('[data-testid="searchbar"]') - .should('exist') - .should('be.visible') - .type(userName); + cy.get('[data-testid="searchbar"]').type(userName); verifyResponseStatusCode('@searchUser', 200); - cy.get(`[data-testid="${userName}"]`).should('be.visible').click(); + cy.get(`[data-testid="${userName}"]`).click(); verifyResponseStatusCode('@userDetailsPage', 200); cy.get( diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/EntityAnnouncement.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/EntityAnnouncement.spec.js index 11e4bf4f452..695dbb5a6a4 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/EntityAnnouncement.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Flow/EntityAnnouncement.spec.js @@ -50,56 +50,84 @@ describe('Entity Announcement', () => { interceptURL('GET', '/api/v1/permissions/*/name/*', 'entityPermission'); interceptURL('GET', '/api/v1/feed/count?entityLink=*', 'entityFeed'); interceptURL('GET', `/api/v1/${value.entity}/name/*`, 'getEntityDetails'); - const startDate = getCurrentLocaleDate(); - const endDate = getFutureLocaleDateFromCurrentDate(5); - visitEntityDetailsPage(value.term, value.serviceName, value.entity); - - cy.get('[data-testid="manage-button"]').should('be.visible').click(); - cy.get('[data-testid="announcement-button"]').should('be.visible').click(); - cy.get('[data-testid="announcement-error"]') - .should('be.visible') - .contains('No Announcements, Click on add announcement to add one.'); - interceptURL('POST', '/api/v1/feed', 'waitForAnnouncement'); - // Create Active Announcement - createAnnouncement( - 'Announcement Title', - startDate, - endDate, - 'Announcement Description' + interceptURL( + 'GET', + '/api/v1/feed?entityLink=*type=Announcement', + 'announcementFeed' ); - // wait time for success toast message - verifyResponseStatusCode('@waitForAnnouncement', 201); - cy.get('.Toastify__close-button >').should('be.visible').click(); - // Create InActive Announcement - const InActiveStartDate = getFutureLocaleDateFromCurrentDate(6); - const InActiveEndDate = getFutureLocaleDateFromCurrentDate(11); + visitEntityDetailsPage(value.term, value.serviceName, value.entity); + cy.get('[data-testid="manage-button"]').click(); + cy.get('[data-testid="announcement-button"]').click(); - createAnnouncement( - 'InActive Announcement Title', - InActiveStartDate, - InActiveEndDate, - 'InActive Announcement Description' - ); + cy.wait('@announcementFeed').then((res) => { + const data = res.response.body.data; - // wait time for success toast message - verifyResponseStatusCode('@waitForAnnouncement', 201); - cy.get('.Toastify__close-button >').should('be.visible').click(); - // check for inActive-announcement - cy.get('[data-testid="inActive-announcements"]').should('be.visible'); + if (data.length > 0) { + const token = localStorage.getItem('oidcIdToken'); + data.map((feed) => { + cy.request({ + method: 'DELETE', + url: `/api/v1/feed/${feed.id}`, + headers: { Authorization: `Bearer ${token}` }, + }).then((response) => { + expect(response.status).to.eq(200); + }); + }); + cy.reload(); + cy.get('[data-testid="manage-button"]').click(); + cy.get('[data-testid="announcement-button"]').click(); + } + const startDate = getCurrentLocaleDate(); + const endDate = getFutureLocaleDateFromCurrentDate(5); - // close announcement drawer - cy.get('[data-testid="title"] .anticon-close').should('be.visible').click(); + cy.get('[data-testid="announcement-error"]') + .should('be.visible') + .contains('No Announcements, Click on add announcement to add one.'); - // reload page to get the active announcement card - cy.reload(); - verifyResponseStatusCode('@entityPermission', 200); - verifyResponseStatusCode('@getEntityDetails', 200); - verifyResponseStatusCode('@entityFeed', 200); + // Create Active Announcement + createAnnouncement( + 'Announcement Title', + startDate, + endDate, + 'Announcement Description' + ); - // check for announcement card on entity page - cy.get('[data-testid="announcement-card"]').should('be.visible'); + // wait time for success toast message + verifyResponseStatusCode('@waitForAnnouncement', 201); + cy.get('.Toastify__close-button >').should('be.visible').click(); + // Create InActive Announcement + const InActiveStartDate = getFutureLocaleDateFromCurrentDate(6); + const InActiveEndDate = getFutureLocaleDateFromCurrentDate(11); + + createAnnouncement( + 'InActive Announcement Title', + InActiveStartDate, + InActiveEndDate, + 'InActive Announcement Description' + ); + + // wait time for success toast message + verifyResponseStatusCode('@waitForAnnouncement', 201); + cy.get('.Toastify__close-button >').should('be.visible').click(); + // check for inActive-announcement + cy.get('[data-testid="inActive-announcements"]').should('be.visible'); + + // close announcement drawer + cy.get('[data-testid="title"] .anticon-close') + .should('be.visible') + .click(); + + // reload page to get the active announcement card + cy.reload(); + verifyResponseStatusCode('@entityPermission', 200); + verifyResponseStatusCode('@getEntityDetails', 200); + verifyResponseStatusCode('@entityFeed', 200); + + // check for announcement card on entity page + cy.get('[data-testid="announcement-card"]').should('be.visible'); + }); }; ANNOUNCEMENT_ENTITIES.forEach((entity) => { @@ -107,4 +135,29 @@ describe('Entity Announcement', () => { addAnnouncement(entity); }); }); + ANNOUNCEMENT_ENTITIES.forEach((value) => { + it(`Delete announcement ${value.entity}`, () => { + interceptURL( + 'GET', + '/api/v1/feed?entityLink=*type=Announcement', + 'announcementFeed' + ); + interceptURL('DELETE', '/api/v1/feed/*', 'deleteFeed'); + visitEntityDetailsPage(value.term, value.serviceName, value.entity); + cy.get('[data-testid="manage-button"]').click(); + cy.get('[data-testid="announcement-button"]').click(); + + verifyResponseStatusCode('@announcementFeed', 200); + cy.get('[data-testid="main-message"]').each(($message) => { + cy.wrap($message).trigger('mouseover'); + cy.get('[data-testid="delete-message"]').click(); + cy.get('.ant-modal-body').should( + 'contain', + 'Are you sure you want to permanently delete this message?' + ); + cy.get('[data-testid="save-button"]').click(); + verifyResponseStatusCode('@deleteFeed', 200); + }); + }); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/DataInsightAlert.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/DataInsightAlert.spec.js index a7a45bb8963..f77f851f936 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/DataInsightAlert.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/DataInsightAlert.spec.js @@ -51,21 +51,11 @@ describe('Data Insight Alert', () => { verifyResponseStatusCode('@dataInsightReport', 200); }); - it('Should have default alert with proper data', () => { - cy.get('[data-testid="sub-heading"]') - .should('be.visible') - .contains(dataInsightReport.description); - - cy.get('[data-testid="trigger-type"]') - .should('be.visible') - .contains(dataInsightReport.triggerType); - - cy.get('[data-testid="schedule-info-type"]') - .should('be.visible') - .contains(dataInsightReport.scheduleInfoType); - - cy.get('[data-testid="sendToAdmins"]').should('be.visible'); - cy.get('[data-testid="sendToTeams"]').should('be.visible'); + it('Should have default alert', () => { + cy.get('[data-testid="sub-heading"]').should('be.visible'); + cy.get('[data-testid="trigger-type"]').should('be.visible'); + cy.get('[data-testid="schedule-info-type"]').should('be.visible'); + cy.get('[data-testid="destination"]').should('be.visible'); cy.get('[data-testid="edit-button"]').should('be.visible'); }); @@ -75,40 +65,29 @@ describe('Data Insight Alert', () => { 'api/v1/events/subscriptions/*', 'dataInsightReportById' ); - cy.get('[data-testid="edit-button"]').should('be.visible').click(); + cy.get('[data-testid="edit-button"]').click(); verifyResponseStatusCode('@dataInsightReportById', 200); cy.get('[data-testid="name"]') - .should('be.visible') .should('be.disabled') .should('have.value', dataInsightReport.name); // update the description cy.get(descriptionBox) .scrollIntoView() - .should('be.visible') .click() .clear() .type(dataInsightReport.updatedDescription); // update schedule info - cy.get('[data-testid="scheduleInfo"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[data-testid="scheduleInfo"]').scrollIntoView().click(); - cy.get('[title="Monthly"]').should('be.visible').click(); + cy.get('.ant-select-dropdown [title="Monthly"]').click(); // update send to teams and admins - cy.get('[data-testid="sendToTeams"]') - .scrollIntoView() - .should('exist') - .uncheck(); + cy.get('[data-testid="sendToTeams"]').scrollIntoView().uncheck(); - cy.get('[data-testid="sendToAdmins"]') - .scrollIntoView() - .should('exist') - .uncheck(); + cy.get('[data-testid="sendToAdmins"]').scrollIntoView().uncheck(); interceptURL('PUT', 'api/v1/events/subscriptions', 'updatedAlert'); interceptURL( @@ -124,17 +103,17 @@ describe('Data Insight Alert', () => { // verify the updated data - cy.get('[data-testid="sub-heading"]') - .should('be.visible') - .contains(dataInsightReport.updatedDescription); + cy.get('[data-testid="sub-heading"]').should( + 'contain', + dataInsightReport.updatedDescription + ); - cy.get('[data-testid="trigger-type"]') - .should('be.visible') - .contains(dataInsightReport.triggerType); + cy.get('[data-testid="trigger-type"]').should( + 'contain', + dataInsightReport.triggerType + ); - cy.get('[data-testid="schedule-info-type"]') - .should('be.visible') - .contains('Monthly'); + cy.get('[data-testid="schedule-info-type"]').should('contain', 'Monthly'); }); it('Should Update the alert to default values', () => { @@ -143,40 +122,29 @@ describe('Data Insight Alert', () => { 'api/v1/events/subscriptions/*', 'dataInsightReportById' ); - cy.get('[data-testid="edit-button"]').should('be.visible').click(); + cy.get('[data-testid="edit-button"]').click(); verifyResponseStatusCode('@dataInsightReportById', 200); cy.get('[data-testid="name"]') - .should('be.visible') .should('be.disabled') .should('have.value', dataInsightReport.name); // update the description cy.get(descriptionBox) .scrollIntoView() - .should('be.visible') .click() .clear() .type(dataInsightReport.description); // update schedule info - cy.get('[data-testid="scheduleInfo"]') - .scrollIntoView() - .should('be.visible') - .click(); + cy.get('[data-testid="scheduleInfo"]').scrollIntoView().click(); - cy.get('[title="Weekly"]').should('be.visible').click(); + cy.get('.ant-select-dropdown [title="Weekly"]').click(); // update send to teams and admins - cy.get('[data-testid="sendToTeams"]') - .scrollIntoView() - .should('exist') - .check(); + cy.get('[data-testid="sendToTeams"]').scrollIntoView().check(); - cy.get('[data-testid="sendToAdmins"]') - .scrollIntoView() - .should('exist') - .check(); + cy.get('[data-testid="sendToAdmins"]').scrollIntoView().check(); interceptURL('PUT', 'api/v1/events/subscriptions', 'updatedAlert'); interceptURL( @@ -192,17 +160,20 @@ describe('Data Insight Alert', () => { // verify the updated data - cy.get('[data-testid="sub-heading"]') - .should('be.visible') - .contains(dataInsightReport.description); + cy.get('[data-testid="sub-heading"]').should( + 'contain', + dataInsightReport.description + ); - cy.get('[data-testid="trigger-type"]') - .should('be.visible') - .contains(dataInsightReport.triggerType); + cy.get('[data-testid="trigger-type"]').should( + 'contain', + dataInsightReport.triggerType + ); - cy.get('[data-testid="schedule-info-type"]') - .should('be.visible') - .contains(dataInsightReport.scheduleInfoType); + cy.get('[data-testid="schedule-info-type"]').should( + 'contain', + dataInsightReport.scheduleInfoType + ); cy.get('[data-testid="sendToAdmins"]').should('be.visible'); cy.get('[data-testid="sendToTeams"]').should('be.visible'); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/CreateUser/CreateUser.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/CreateUser/CreateUser.component.tsx index 24a180ef0b4..400a0e5e70c 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/CreateUser/CreateUser.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/CreateUser/CreateUser.component.tsx @@ -896,6 +896,9 @@ const CreateUser = ({