mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Feat/notifications cypress (#3244)
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # [1-743](https://linear.app/unleash/issue/1-743/add-cypress-test-for-notifications-happy-path) <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
dfe068ee33
commit
068c55a925
137
frontend/cypress/integration/projects/notifications.spec.ts
Normal file
137
frontend/cypress/integration/projects/notifications.spec.ts
Normal file
@ -0,0 +1,137 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
type UserCredentials = { email: string; password: string };
|
||||
const ENTERPRISE = Boolean(Cypress.env('ENTERPRISE'));
|
||||
const randomId = String(Math.random()).split('.')[1];
|
||||
const featureToggleName = `notifications_test-${randomId}`;
|
||||
const baseUrl = Cypress.config().baseUrl;
|
||||
let strategyId = '';
|
||||
const userIds: number[] = [];
|
||||
const userCredentials: UserCredentials[] = [];
|
||||
const userName = `notifications_user-${randomId}`;
|
||||
const projectName = `default`;
|
||||
const password = Cypress.env(`AUTH_PASSWORD`) + '_A';
|
||||
const EDITOR = 2;
|
||||
const PROJECT_MEMBER = 5;
|
||||
|
||||
// Disable all active splash pages by visiting them.
|
||||
const disableActiveSplashScreens = () => {
|
||||
cy.visit(`/splash/operators`);
|
||||
};
|
||||
|
||||
const createUser = () => {
|
||||
const name = `${userName}`;
|
||||
const email = `${name}@test.com`;
|
||||
cy.request('POST', `${baseUrl}/api/admin/user-admin`, {
|
||||
name: name,
|
||||
email: `${name}@test.com`,
|
||||
username: `${name}@test.com`,
|
||||
sendEmail: false,
|
||||
rootRole: EDITOR,
|
||||
})
|
||||
.as(name)
|
||||
.then(response => {
|
||||
const id = response.body.id;
|
||||
updateUserPassword(id).then(() => {
|
||||
addUserToProject(id).then(() => {
|
||||
userIds.push(id);
|
||||
userCredentials.push({ email, password });
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const updateUserPassword = async (id: number) => {
|
||||
cy.request(
|
||||
'POST',
|
||||
`${baseUrl}/api/admin/user-admin/${id}/change-password`,
|
||||
{
|
||||
password,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const addUserToProject = async (id: number) => {
|
||||
cy.request(
|
||||
'POST',
|
||||
`${baseUrl}/api/admin/projects/${projectName}/role/${PROJECT_MEMBER}/access`,
|
||||
{
|
||||
groups: [],
|
||||
users: [{ id }],
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
describe('notifications', () => {
|
||||
before(() => {
|
||||
disableActiveSplashScreens();
|
||||
cy.login();
|
||||
createUser();
|
||||
});
|
||||
|
||||
after(() => {
|
||||
// We need to login as admin for cleanup
|
||||
cy.login();
|
||||
userIds.forEach(id =>
|
||||
cy.request('DELETE', `${baseUrl}/api/admin/user-admin/${id}`)
|
||||
);
|
||||
|
||||
cy.request(
|
||||
'DELETE',
|
||||
`${baseUrl}/api/admin/features/${featureToggleName}`
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.login();
|
||||
cy.visit(`/projects/${projectName}`);
|
||||
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
||||
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cy.logout();
|
||||
});
|
||||
|
||||
const createFeature = () => {
|
||||
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
|
||||
|
||||
cy.intercept('POST', `/api/admin/projects/${projectName}/features`).as(
|
||||
'createFeature'
|
||||
);
|
||||
|
||||
cy.get("[data-testid='CF_NAME_ID'").type(featureToggleName);
|
||||
cy.get("[data-testid='CF_DESC_ID'").type('hello-world');
|
||||
cy.get("[data-testid='CF_CREATE_BTN_ID']").click();
|
||||
cy.wait('@createFeature');
|
||||
};
|
||||
|
||||
it('should create a notification when a feature is created in a project', () => {
|
||||
createFeature();
|
||||
|
||||
//Should not show own notifications
|
||||
cy.get("[data-testid='NOTIFICATIONS_BUTTON']").click();
|
||||
|
||||
//then
|
||||
cy.get("[data-testid='NOTIFICATIONS_MODAL']").should('exist');
|
||||
cy.get("[data-testid='UNREAD_NOTIFICATIONS']").should('not.exist');
|
||||
|
||||
const credentials = userCredentials[0];
|
||||
|
||||
//Sign in as a different user
|
||||
cy.login(credentials.email, credentials.password);
|
||||
cy.visit(`/projects/${projectName}`);
|
||||
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
||||
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
||||
}
|
||||
cy.get("[data-testid='NOTIFICATIONS_BUTTON']").click();
|
||||
|
||||
//then
|
||||
cy.get("[data-testid='UNREAD_NOTIFICATIONS']").should('exist');
|
||||
cy.get("[data-testid='NOTIFICATIONS_LIST']")
|
||||
.should('have.length', 1)
|
||||
.eq(0)
|
||||
.should('contain.text', 'New feature');
|
||||
});
|
||||
});
|
@ -43,3 +43,7 @@ Cypress.Commands.add('login', (user = AUTH_USER, password = AUTH_PASSWORD) =>
|
||||
cy.get("[data-testid='HEADER_USER_AVATAR']");
|
||||
})
|
||||
);
|
||||
|
||||
Cypress.Commands.add('logout', () => {
|
||||
cy.visit('/logout');
|
||||
});
|
||||
|
@ -23,6 +23,7 @@ declare global {
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
login(user?: string, password?: string): Chainable<null>;
|
||||
logout(user?: string): Chainable<null>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,7 @@ export const Notifications = () => {
|
||||
<StyledPrimaryContainerBox>
|
||||
<IconButton
|
||||
onClick={() => setShowNotifications(!showNotifications)}
|
||||
data-testid="NOTIFICATIONS_BUTTON"
|
||||
>
|
||||
<ConditionallyRender
|
||||
condition={hasUnreadNotifications}
|
||||
@ -178,7 +179,10 @@ export const Notifications = () => {
|
||||
<ClickAwayListener
|
||||
onClickAway={() => setShowNotifications(false)}
|
||||
>
|
||||
<StyledPaper onKeyDown={onKeyDown}>
|
||||
<StyledPaper
|
||||
onKeyDown={onKeyDown}
|
||||
data-testid="NOTIFICATIONS_MODAL"
|
||||
>
|
||||
<NotificationsHeader>
|
||||
<StyledHeaderBox>
|
||||
<StyledHeaderTypography>
|
||||
@ -194,7 +198,7 @@ export const Notifications = () => {
|
||||
<ConditionallyRender
|
||||
condition={hasUnreadNotifications}
|
||||
show={
|
||||
<StyledInnerContainerBox>
|
||||
<StyledInnerContainerBox data-testid="UNREAD_NOTIFICATIONS">
|
||||
<Button onClick={onMarkAllAsRead}>
|
||||
<StyledTypography>
|
||||
Mark all as read (
|
||||
|
@ -6,5 +6,9 @@ const StyledListContainer = styled(List)(({ theme }) => ({
|
||||
}));
|
||||
|
||||
export const NotificationsList: FC = ({ children }) => {
|
||||
return <StyledListContainer>{children}</StyledListContainer>;
|
||||
return (
|
||||
<StyledListContainer data-testid="NOTIFICATIONS_LIST">
|
||||
{children}
|
||||
</StyledListContainer>
|
||||
);
|
||||
};
|
||||
|
@ -583,6 +583,7 @@ export const ProjectFeatureToggles = ({
|
||||
Icon={Add}
|
||||
projectId={projectId}
|
||||
permission={CREATE_FEATURE}
|
||||
data-testid="NAVIGATE_TO_CREATE_FEATURE"
|
||||
>
|
||||
New feature toggle
|
||||
</StyledResponsiveButton>
|
||||
|
@ -84,3 +84,7 @@ export const IMPORT_ENVIRONMENT = 'IMPORT_ENVIRONMENT';
|
||||
export const CODE_TEXT_FIELD = 'CODE_TEXT_FIELD';
|
||||
export const VALIDATE_BUTTON = 'VALIDATE_BUTTON';
|
||||
export const IMPORT_CONFIGURATION_BUTTON = 'IMPORT_CONFIGURATION_BUTTON';
|
||||
|
||||
/* NOTIFICATIONS FEATURES */
|
||||
|
||||
export const NOTIFICATIONS_BUTTON = 'NOTIFICATIONS_BUTTON';
|
||||
|
@ -362,7 +362,8 @@ export default class UserAdminController extends Controller {
|
||||
req: IAuthRequest<unknown, unknown, CreateUserSchema>,
|
||||
res: Response<UserSchema>,
|
||||
): Promise<void> {
|
||||
const { username, email, name, rootRole, sendEmail } = req.body;
|
||||
const { username, email, name, rootRole, sendEmail, password } =
|
||||
req.body;
|
||||
const { user } = req;
|
||||
|
||||
const createdUser = await this.userService.createUser(
|
||||
@ -370,6 +371,7 @@ export default class UserAdminController extends Controller {
|
||||
username,
|
||||
email,
|
||||
name,
|
||||
password,
|
||||
rootRole,
|
||||
},
|
||||
user,
|
||||
|
Loading…
Reference in New Issue
Block a user