1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/frontend/cypress/integration/feature/feature.spec.ts
Nuno Góis ca5c03ed17
test: fix feature e2e test by checking flag name in a td instead of url (#8863)
https://linear.app/unleash/issue/2-3028/fix-create-feature-flag-e2e-test

Fixes our failing [create feature e2e
test](https://github.com/Unleash/unleash/actions/runs/12027120576/job/33527490303?pr=8843).

We were looking for the feature flag name in the URL, not the DOM.
Previously, whenever we created a new feature flag, this would
automatically redirect us to that flag's page. This is no longer the
case if you use the "Create flag" button you see in the onboarding
header, which is the one the test is now using.

I agree it makes sense not to redirect in this case, but the test should
be adapted accordingly, and instead look for the feature flag name in
the table.
2024-11-26 16:13:30 +00:00

84 lines
2.8 KiB
TypeScript

///<reference path="../../global.d.ts" />
describe('feature', () => {
const baseUrl = Cypress.config().baseUrl;
const randomId = String(Math.random()).split('.')[1];
const featureToggleName = `unleash-e2e-${randomId}`;
const projectName = `unleash-e2e-project-${randomId}`;
before(() => {
cy.runBefore();
cy.login_UI();
cy.createProject_API(projectName);
});
after(() => {
cy.on('uncaught:exception', (err) => {
if (
err.message.includes(
'ResizeObserver loop completed with undelivered notifications',
)
) {
console.log(
'Ignored an uncaught resize observer error:',
err.message,
);
// ignore resize observer errors
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
// returning false here prevents Cypress from failing the test
return false;
}
});
cy.deleteFeature_API(featureToggleName, projectName);
cy.deleteProject_API(projectName);
});
beforeEach(() => {
cy.login_UI();
cy.visit('/features');
cy.intercept('GET', `${baseUrl}/api/admin/ui-config`, (req) => {
req.headers['cache-control'] =
'no-cache, no-store, must-revalidate';
req.on('response', (res) => {
if (res.body) {
res.body.flags = {
...res.body.flags,
flagOverviewRedesign: true,
};
}
});
});
});
it('can create a feature flag', () => {
cy.createFeature_UI(featureToggleName, true, projectName);
cy.contains('td', featureToggleName).should('exist');
});
it('gives an error if a toggle exists with the same name', () => {
cy.createFeature_UI(featureToggleName, false, projectName);
cy.get("[data-testid='INPUT_ERROR_TEXT']").contains(
'A flag with that name already exists',
);
});
it('gives an error if a toggle name is url unsafe', () => {
cy.createFeature_UI('featureToggleUnsafe####$#//', false, projectName);
cy.get("[data-testid='INPUT_ERROR_TEXT']").contains(
`"name" must be URL friendly`,
);
});
it('can add, update and delete a gradual rollout strategy to the development environment', () => {
cy.addFlexibleRolloutStrategyToFeature_UI({
featureToggleName,
project: projectName,
});
cy.updateFlexibleRolloutStrategy_UI(featureToggleName, projectName);
cy.deleteFeatureStrategy_UI(featureToggleName, false, projectName);
});
});