1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/frontend/cypress/integration/projects/settings.spec.ts
andreas-unleash 32e1ad44ed
Feat/add cypress tests for project scoped stickiness (#3340)
<!-- 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 #

<!-- (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>
2023-03-17 14:41:59 +02:00

118 lines
3.7 KiB
TypeScript

/// <reference types="cypress" />
type UserCredentials = { email: string; password: string };
const ENTERPRISE = Boolean(Cypress.env('ENTERPRISE'));
const randomId = String(Math.random()).split('.')[1];
const featureToggleName = `settings-${randomId}`;
const baseUrl = Cypress.config().baseUrl;
let strategyId = '';
const userName = `settings-user-${randomId}`;
const projectName = `stickiness-project-${randomId}`;
// Disable all active splash pages by visiting them.
const disableActiveSplashScreens = () => {
cy.visit(`/splash/operators`);
};
const disableFeatureStrategiesProdGuard = () => {
localStorage.setItem(
'useFeatureStrategyProdGuardSettings:v2',
JSON.stringify({ hide: true })
);
};
describe('notifications', () => {
before(() => {
disableFeatureStrategiesProdGuard();
disableActiveSplashScreens();
cy.login();
});
after(() => {
cy.request(
'DELETE',
`${baseUrl}/api/admin/features/${featureToggleName}`
);
cy.request('DELETE', `${baseUrl}/api/admin/projects/${projectName}`);
});
beforeEach(() => {
cy.login();
cy.visit(`/projects`);
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
cy.get("[data-testid='CLOSE_SPLASH']").click();
}
});
afterEach(() => {
cy.request('DELETE', `${baseUrl}/api/admin/projects/${projectName}`);
});
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');
};
const createProject = () => {
cy.get('[data-testid=NAVIGATE_TO_CREATE_PROJECT').click();
cy.get("[data-testid='PROJECT_ID_INPUT']").type(projectName);
cy.get("[data-testid='PROJECT_NAME_INPUT']").type(projectName);
cy.get("[id='stickiness-select']")
.first()
.click()
.get('[data-testid=SELECT_ITEM_ID-userId')
.first()
.click();
cy.get("[data-testid='CREATE_PROJECT_BTN']").click();
};
it('should store default project stickiness when creating, retrieve it when editing a project', () => {
createProject();
cy.visit(`/projects/${projectName}`);
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
cy.get("[data-testid='CLOSE_SPLASH']").click();
}
cy.get("[data-testid='NAVIGATE_TO_EDIT_PROJECT']").click();
//then
cy.get("[id='stickiness-select']")
.first()
.should('have.text', 'userId');
});
it('should respect the default project stickiness when creating a Gradual Rollout Strategy', () => {
createProject();
createFeature();
cy.visit(
`/projects/default/features/${featureToggleName}/strategies/create?environmentId=development&strategyName=flexibleRollout`
);
//then
cy.get("[id='stickiness-select']")
.first()
.should('have.text', 'userId');
});
it('should respect the default project stickiness when creating a variant', () => {
createProject();
createFeature();
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
cy.get("[data-testid='EDIT_VARIANTS_BUTTON']").click();
//then
cy.get('#menu-stickiness').first().should('have.text', 'userId');
});
});