1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/cypress/integration/feature/feature.spec.ts

111 lines
3.6 KiB
TypeScript
Raw Normal View History

///<reference path="../../global.d.ts" />
describe('feature', () => {
const randomId = String(Math.random()).split('.')[1];
const featureToggleName = `unleash-e2e-${randomId}`;
const variant1 = 'variant1';
const variant2 = 'variant2';
let strategyId = '';
before(() => {
cy.runBefore();
});
after(() => {
cy.deleteFeature_API(featureToggleName);
});
beforeEach(() => {
cy.login_UI();
cy.visit('/features');
});
it('can create a feature toggle', () => {
cy.createFeature_UI(featureToggleName, true);
cy.url().should('include', featureToggleName);
});
it('gives an error if a toggle exists with the same name', () => {
cy.createFeature_UI(featureToggleName, false);
cy.get("[data-testid='INPUT_ERROR_TEXT']").contains(
'A toggle with that name already exists'
);
});
it('gives an error if a toggle name is url unsafe', () => {
cy.createFeature_UI('featureToggleUnsafe####$#//', false);
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', async () => {
cy.addFlexibleRolloutStrategyToFeature_UI({
featureToggleName,
}).then(value => {
strategyId = value;
cy.updateFlexibleRolloutStrategy_UI(
featureToggleName,
strategyId
).then(() =>
cy.deleteFeatureStrategy_UI(featureToggleName, strategyId)
);
});
});
feat: add new feature strategy create/edit pages (#739) * refactor: add param helper hooks * refactor: remove first add strategy link * refactor: add more types to useStrategies * refactor: port strategy utils to TS * refactor: replace rollout strategy icon * refactor: use a named export for useFeature * refactor: add more types to useFeature * refactor: adjust code box styles * refactor: add missing PermissionButton variant prop * refactor: add missing button icon label * refactor: move common feature components * refactor: fix StrategyConstraints error prop types * refactor: fix GeneralStrategy prop types * feat: add new feature strategy create/edit pages * refactor: remove feature strategies page * refactor: fix types in GeneralStrategy * refactor: use ConstraintAccordion on the new pages * refactor: use ConditionallyRender for remove button * refactor: rename FeatureStrategyForm component * refactor: use the Edit icon for feature strategies * refactor: fix initial edit mode for new constraints * refactor: add FeatureStrategyMenu to closed accordions * refactor: allow editing multiple constraints * refactor: show single-valued constraint value * refactor: increase feature overview strategy width * refactor: add remove button to feature overview strategies * refactor: move createEmptyConstraint to own file * refactor: disable submit button for invalid constraints * refactor: fix nested paragraphs on the metrics page * refactor: move create/edit feature strategy to modal * refactor: always open new constraints in edit mode * refactor: use a PermissionButton for the save button * refactor: remvoe unsaved constraints on cancel * refactor: clarify useConstraintsValidation logic * refactor: remove unused strategy descriptions * refactor: restore Rollout icon * refactor: remove sidebar modal slide animation * refactor: avoid constraint accordion toggle on edit/delete * refactor: truncate long strategy names * refactor: find the correct remove button
2022-03-09 14:59:24 +01:00
it('can add a userId strategy to the development environment', () => {
cy.addUserIdStrategyToFeature_UI(featureToggleName, strategyId).then(
value => {
cy.deleteFeatureStrategy_UI(featureToggleName, value, false);
}
);
});
it('can add variants to the development environment', () => {
cy.addVariantsToFeature_UI(featureToggleName, [variant1, variant2]);
});
it('can update variants', () => {
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
cy.get('[data-testid=EDIT_VARIANTS_BUTTON]').click();
cy.get('[data-testid=VARIANT_NAME_INPUT]')
.last()
.children()
.find('input')
.should('have.attr', 'disabled');
cy.get('[data-testid=VARIANT_WEIGHT_CHECK]')
.last()
.find('input')
.check();
cy.get('[data-testid=VARIANT_WEIGHT_INPUT]').last().clear().type('15');
cy.intercept(
'PATCH',
`/api/admin/projects/default/features/${featureToggleName}/environments/development/variants`,
req => {
expect(req.body[0].op).to.equal('replace');
expect(req.body[0].path).to.equal('/1/weightType');
expect(req.body[0].value).to.equal('fix');
expect(req.body[1].op).to.equal('replace');
expect(req.body[1].path).to.equal('/1/weight');
expect(req.body[1].value).to.equal(150);
expect(req.body[2].op).to.equal('replace');
expect(req.body[2].path).to.equal('/0/weight');
expect(req.body[2].value).to.equal(850);
}
).as('variantUpdate');
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
cy.get(`[data-testid=VARIANT_WEIGHT_${variant2}]`).should(
'have.text',
'15 %'
);
});
it('can delete variants', () => {
cy.deleteVariant_UI(featureToggleName, variant2);
});
});