2024-01-08 15:23:39 +05:30
|
|
|
/*
|
|
|
|
* Copyright 2023 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.
|
|
|
|
*/
|
2024-01-26 17:09:03 +05:30
|
|
|
import { interceptURL, uuid, verifyResponseStatusCode } from '../common';
|
2024-03-15 03:02:42 +05:30
|
|
|
import { getToken } from './LocalStorage';
|
2024-01-08 15:23:39 +05:30
|
|
|
|
|
|
|
const userURL =
|
|
|
|
'/api/v1/search/query?q=**%20AND%20isBot:false&from=0&size=0&index=user_search_index';
|
|
|
|
const teamURL =
|
2024-01-22 21:11:55 +05:30
|
|
|
'/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=10&index=team_search_index&sort_field=displayName.keyword&sort_order=asc';
|
2024-01-08 15:23:39 +05:30
|
|
|
|
2024-01-26 17:09:03 +05:30
|
|
|
export const generateRandomUser = () => {
|
|
|
|
return {
|
|
|
|
firstName: `firstName-${uuid()}`,
|
|
|
|
lastName: `lastName-${uuid()}`,
|
|
|
|
email: `user${uuid()}@example.com`,
|
|
|
|
password: 'User@OMD123',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-08 15:23:39 +05:30
|
|
|
export const validateOwnerAndTeamCounts = () => {
|
|
|
|
cy.getAllLocalStorage().then((data) => {
|
2024-03-15 03:02:42 +05:30
|
|
|
const token = getToken(data);
|
2024-01-08 15:23:39 +05:30
|
|
|
|
|
|
|
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"]').click();
|
|
|
|
|
|
|
|
// check for teams count
|
|
|
|
cy.get('@TeamCount').then((response) => {
|
|
|
|
const teamCount = response.body.hits.total.value;
|
|
|
|
cy.get('.user-team-select-popover [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('.user-team-select-popover [data-testid="filter-count"]')
|
|
|
|
.eq(1)
|
|
|
|
.contains(`${userCount}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
cy.clickOutside();
|
|
|
|
};
|
|
|
|
|
2024-06-11 19:57:11 +05:30
|
|
|
export const addOwner = (
|
|
|
|
ownerName: string,
|
|
|
|
dataTestId?: string,
|
|
|
|
verifyPatchResponse = true
|
|
|
|
) => {
|
2024-06-19 19:45:56 +05:30
|
|
|
interceptURL(
|
|
|
|
'GET',
|
|
|
|
'/api/v1/search/query?q=*&index=team_search_index*',
|
|
|
|
'getTeams'
|
|
|
|
);
|
2024-05-26 14:12:27 +05:30
|
|
|
interceptURL('GET', '/api/v1/users?*isBot=false*', 'getUsers');
|
2024-06-13 15:47:09 +05:30
|
|
|
cy.get('[data-testid="edit-owner"]')
|
|
|
|
.scrollIntoView()
|
|
|
|
.click({ waitForAnimations: false });
|
2024-01-08 15:23:39 +05:30
|
|
|
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
2024-06-19 19:45:56 +05:30
|
|
|
|
|
|
|
verifyResponseStatusCode('@getTeams', 200); // wait for teams to load before switching the tab
|
|
|
|
|
2024-06-13 15:47:09 +05:30
|
|
|
cy.get('.ant-tabs [id*=tab-users]')
|
|
|
|
.scrollIntoView()
|
|
|
|
.click({ waitForAnimations: false });
|
|
|
|
|
2024-05-26 14:12:27 +05:30
|
|
|
verifyResponseStatusCode('@getUsers', 200);
|
2024-01-08 15:23:39 +05:30
|
|
|
interceptURL(
|
|
|
|
'GET',
|
2024-02-07 19:49:57 +05:30
|
|
|
`api/v1/search/query?q=*&index=user_search_index*`,
|
2024-01-08 15:23:39 +05:30
|
|
|
'searchOwner'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get('[data-testid="owner-select-users-search-bar"]').type(ownerName);
|
|
|
|
|
|
|
|
verifyResponseStatusCode('@searchOwner', 200);
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
|
|
|
cy.get(`.ant-popover [title="${ownerName}"]`).click();
|
2024-06-11 19:57:11 +05:30
|
|
|
|
|
|
|
if (verifyPatchResponse) {
|
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
}
|
2024-01-08 15:23:39 +05:30
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'contain',
|
|
|
|
ownerName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
export const updateOwner = (ownerName: string, dataTestId?: string) => {
|
2024-01-08 15:23:39 +05:30
|
|
|
cy.get('[data-testid="edit-owner"]').click();
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
|
|
|
cy.log('/api/v1/users?limit=*&isBot=false*');
|
|
|
|
cy.get('.ant-tabs [id*=tab-users]').click();
|
|
|
|
|
|
|
|
interceptURL(
|
|
|
|
'GET',
|
|
|
|
`api/v1/search/query?q=*${encodeURI(ownerName)}*&index=user_search_index`,
|
|
|
|
'searchOwner'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get('[data-testid="owner-select-users-search-bar"]')
|
|
|
|
.clear()
|
|
|
|
.type(ownerName);
|
|
|
|
|
|
|
|
verifyResponseStatusCode('@searchOwner', 200);
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
|
|
|
cy.get(`.ant-popover [title="${ownerName}"]`).click();
|
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'contain',
|
|
|
|
ownerName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
export const removeOwner = (ownerName: string, dataTestId?: string) => {
|
2024-02-07 19:49:57 +05:30
|
|
|
cy.get('[data-testid="edit-owner"]').scrollIntoView().click();
|
2024-01-08 15:23:39 +05:30
|
|
|
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
2024-03-27 00:56:02 +05:30
|
|
|
cy.get(
|
|
|
|
'[data-testid="select-owner-tabs"] [data-testid="remove-owner"]'
|
2024-05-26 14:12:27 +05:30
|
|
|
).should('be.visible');
|
2024-03-27 00:56:02 +05:30
|
|
|
|
|
|
|
cy.get(
|
|
|
|
'[data-testid="select-owner-tabs"] [data-testid="remove-owner"]'
|
|
|
|
).click();
|
2024-01-08 15:23:39 +05:30
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'not.contain',
|
|
|
|
ownerName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
export const addTeamAsOwner = (teamName: string, dataTestId?: string) => {
|
2024-01-08 15:23:39 +05:30
|
|
|
interceptURL(
|
|
|
|
'GET',
|
2024-01-22 21:11:55 +05:30
|
|
|
'/api/v1/search/query?q=*&from=0&size=*&index=team_search_index&sort_field=displayName.keyword&sort_order=asc',
|
2024-01-08 15:23:39 +05:30
|
|
|
'getTeams'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get('[data-testid="edit-owner"]').click();
|
|
|
|
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
|
|
|
|
|
|
|
verifyResponseStatusCode('@getTeams', 200);
|
|
|
|
|
|
|
|
interceptURL(
|
|
|
|
'GET',
|
|
|
|
`api/v1/search/query?q=*${encodeURI(teamName)}*`,
|
|
|
|
'searchTeams'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get('[data-testid="owner-select-teams-search-bar"]').type(teamName);
|
|
|
|
|
|
|
|
verifyResponseStatusCode('@searchTeams', 200);
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
|
|
|
cy.get(`.ant-popover [title="${teamName}"]`).click();
|
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'contain',
|
|
|
|
teamName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
export const updateTeamAsOwner = (teamName: string, dataTestId?: string) => {
|
2024-01-08 15:23:39 +05:30
|
|
|
cy.get('[data-testid="edit-owner"]').click();
|
|
|
|
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
|
|
|
|
|
|
|
interceptURL(
|
|
|
|
'GET',
|
|
|
|
`api/v1/search/query?q=*${encodeURI(teamName)}*`,
|
|
|
|
'searchTeams'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get('[data-testid="owner-select-teams-search-bar"]')
|
|
|
|
.clear()
|
|
|
|
.type(teamName);
|
|
|
|
|
|
|
|
verifyResponseStatusCode('@searchTeams', 200);
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
|
|
|
cy.get(`.ant-popover [title="${teamName}"]`).click();
|
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'contain',
|
|
|
|
teamName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|
|
|
|
|
2024-01-24 20:47:05 +05:30
|
|
|
export const removeTeamAsOwner = (teamName: string, dataTestId?: string) => {
|
2024-01-08 15:23:39 +05:30
|
|
|
cy.get('[data-testid="edit-owner"]').click();
|
|
|
|
|
|
|
|
cy.get("[data-testid='select-owner-tabs']").should('be.visible');
|
|
|
|
|
|
|
|
interceptURL('PATCH', `/api/v1/**`, 'patchOwner');
|
|
|
|
|
2024-01-30 17:00:08 +05:30
|
|
|
cy.get('[data-testid="remove-owner"]').scrollIntoView().click();
|
2024-01-08 15:23:39 +05:30
|
|
|
verifyResponseStatusCode('@patchOwner', 200);
|
|
|
|
|
|
|
|
cy.get('[data-testid="owner-link"]').should('not.contain', teamName);
|
2024-01-24 20:47:05 +05:30
|
|
|
|
|
|
|
cy.get(`[data-testid=${dataTestId ?? 'owner-link'}]`).should(
|
|
|
|
'not.contain',
|
|
|
|
teamName
|
|
|
|
);
|
2024-01-08 15:23:39 +05:30
|
|
|
};
|