2021-09-30 11:44:30 +02:00
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
2022-03-28 10:49:59 +02:00
|
|
|
export {};
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-03-28 10:49:59 +02:00
|
|
|
const ENTERPRISE = Boolean(Cypress.env('ENTERPRISE'));
|
2022-02-25 10:21:28 +01:00
|
|
|
const randomId = String(Math.random()).split('.')[1];
|
|
|
|
const featureToggleName = `unleash-e2e-${randomId}`;
|
|
|
|
const baseUrl = Cypress.config().baseUrl;
|
2022-05-31 13:45:04 +02:00
|
|
|
const variant1 = 'variant1';
|
|
|
|
const variant2 = 'variant2';
|
2022-02-25 10:21:28 +01:00
|
|
|
let strategyId = '';
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-03-28 10:49:59 +02:00
|
|
|
// Disable the prod guard modal by marking it as seen.
|
|
|
|
const disableFeatureStrategiesProdGuard = () => {
|
|
|
|
localStorage.setItem(
|
|
|
|
'useFeatureStrategyProdGuardSettings:v2',
|
|
|
|
JSON.stringify({ hide: true })
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Disable all active splash pages by visiting them.
|
|
|
|
const disableActiveSplashScreens = () => {
|
|
|
|
cy.visit(`/splash/operators`);
|
|
|
|
};
|
2022-03-24 09:38:41 +01:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
describe('feature', () => {
|
2022-03-23 12:45:23 +01:00
|
|
|
before(() => {
|
2022-03-28 10:49:59 +02:00
|
|
|
disableFeatureStrategiesProdGuard();
|
|
|
|
disableActiveSplashScreens();
|
2022-03-23 12:45:23 +01:00
|
|
|
});
|
|
|
|
|
2021-09-30 11:44:30 +02:00
|
|
|
after(() => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
url: `${baseUrl}/api/admin/features/${featureToggleName}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
url: `${baseUrl}/api/admin/archive/${featureToggleName}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-05-25 10:14:22 +02:00
|
|
|
cy.login();
|
2022-11-28 11:12:45 +01:00
|
|
|
cy.visit('/features');
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can create a feature toggle', () => {
|
2022-04-08 13:13:45 +02:00
|
|
|
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
|
|
|
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
2021-11-26 11:12:37 +01:00
|
|
|
}
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2021-11-26 16:07:05 +01:00
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
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();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.wait('@createFeature');
|
|
|
|
cy.url().should('include', featureToggleName);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('gives an error if a toggle exists with the same name', () => {
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
|
2022-02-11 00:43:23 +01:00
|
|
|
|
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
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.get("[data-testid='INPUT_ERROR_TEXT']").contains(
|
2022-06-07 15:03:40 +02:00
|
|
|
'A toggle with that name already exists'
|
2022-02-11 00:43:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('gives an error if a toggle name is url unsafe', () => {
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
|
2022-02-11 00:43:23 +01:00
|
|
|
|
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get("[data-testid='CF_NAME_ID'").type('featureToggleUnsafe####$#//');
|
|
|
|
cy.get("[data-testid='CF_DESC_ID'").type('hello-world');
|
|
|
|
cy.get("[data-testid='CF_CREATE_BTN_ID']").click();
|
|
|
|
cy.get("[data-testid='INPUT_ERROR_TEXT']").contains(
|
2022-02-11 00:43:23 +01:00
|
|
|
`"name" must be URL friendly`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can add a gradual rollout strategy to the development environment', () => {
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.visit(
|
|
|
|
`/projects/default/features/${featureToggleName}/strategies/create?environmentId=development&strategyName=flexibleRollout`
|
|
|
|
);
|
|
|
|
|
2022-03-24 09:38:41 +01:00
|
|
|
if (ENTERPRISE) {
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_CONSTRAINT_ID]').click();
|
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'POST',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body.name).to.equal('flexibleRollout');
|
|
|
|
expect(req.body.parameters.groupId).to.equal(featureToggleName);
|
|
|
|
expect(req.body.parameters.stickiness).to.equal('default');
|
2022-08-04 13:34:30 +02:00
|
|
|
expect(req.body.parameters.rollout).to.equal('50');
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-03-24 09:38:41 +01:00
|
|
|
if (ENTERPRISE) {
|
2021-09-30 11:44:30 +02:00
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
strategyId = res.body.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('addStrategyToFeature');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get(`[data-testid=STRATEGY_FORM_SUBMIT_ID]`).first().click();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.wait('@addStrategyToFeature');
|
|
|
|
});
|
|
|
|
|
2022-01-27 17:31:44 +01:00
|
|
|
it('can update a strategy in the development environment', () => {
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.visit(
|
|
|
|
`/projects/default/features/${featureToggleName}/strategies/edit?environmentId=development&strategyId=${strategyId}`
|
|
|
|
);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=FLEXIBLE_STRATEGY_STICKINESS_ID]')
|
2021-09-30 11:44:30 +02:00
|
|
|
.first()
|
|
|
|
.click()
|
2022-04-08 13:13:45 +02:00
|
|
|
.get('[data-testid=SELECT_ITEM_ID-sessionId')
|
2021-09-30 11:44:30 +02:00
|
|
|
.first()
|
|
|
|
.click();
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=FLEXIBLE_STRATEGY_GROUP_ID]')
|
2021-09-30 11:44:30 +02:00
|
|
|
.first()
|
|
|
|
.clear()
|
|
|
|
.type('new-group-id');
|
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'PUT',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies/${strategyId}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
2022-02-25 10:21:28 +01:00
|
|
|
expect(req.body.parameters.groupId).to.equal('new-group-id');
|
2021-09-30 11:44:30 +02:00
|
|
|
expect(req.body.parameters.stickiness).to.equal('sessionId');
|
2022-08-04 13:34:30 +02:00
|
|
|
expect(req.body.parameters.rollout).to.equal('50');
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-03-24 09:38:41 +01:00
|
|
|
if (ENTERPRISE) {
|
2021-09-30 11:44:30 +02:00
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('updateStrategy');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get(`[data-testid=STRATEGY_FORM_SUBMIT_ID]`).first().click();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.wait('@updateStrategy');
|
|
|
|
});
|
|
|
|
|
2022-01-27 17:31:44 +01:00
|
|
|
it('can delete a strategy in the development environment', () => {
|
2022-03-11 13:46:00 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}`);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies/${strategyId}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
req.continue(res => {
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('deleteStrategy');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get(
|
|
|
|
'[data-testid=FEATURE_ENVIRONMENT_ACCORDION_development]'
|
|
|
|
).click();
|
|
|
|
cy.get('[data-testid=STRATEGY_FORM_REMOVE_ID]').click();
|
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.wait('@deleteStrategy');
|
|
|
|
});
|
|
|
|
|
2022-03-09 14:59:24 +01:00
|
|
|
it('can add a userId strategy to the development environment', () => {
|
|
|
|
cy.visit(
|
|
|
|
`/projects/default/features/${featureToggleName}/strategies/create?environmentId=development&strategyName=userWithId`
|
|
|
|
);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-03-24 09:38:41 +01:00
|
|
|
if (ENTERPRISE) {
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_CONSTRAINT_ID]').click();
|
|
|
|
cy.get('[data-testid=CONSTRAINT_AUTOCOMPLETE_ID]')
|
2021-09-30 11:44:30 +02:00
|
|
|
.type('{downArrow}'.repeat(1))
|
|
|
|
.type('{enter}');
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
}
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=STRATEGY_INPUT_LIST]')
|
2021-09-30 11:44:30 +02:00
|
|
|
.type('user1')
|
|
|
|
.type('{enter}')
|
|
|
|
.type('user2')
|
|
|
|
.type('{enter}');
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_TO_STRATEGY_INPUT_LIST]').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'POST',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body.name).to.equal('userWithId');
|
|
|
|
|
|
|
|
expect(req.body.parameters.userIds.length).to.equal(11);
|
|
|
|
|
2022-03-24 09:38:41 +01:00
|
|
|
if (ENTERPRISE) {
|
2021-09-30 11:44:30 +02:00
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
strategyId = res.body.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('addStrategyToFeature');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get(`[data-testid=STRATEGY_FORM_SUBMIT_ID]`).first().click();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.wait('@addStrategyToFeature');
|
|
|
|
});
|
2021-10-08 11:23:29 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can add two variant to the feature', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
|
|
|
if (req.body.length === 1) {
|
|
|
|
expect(req.body[0].op).to.equal('add');
|
2021-11-25 14:05:44 +01:00
|
|
|
expect(req.body[0].path).to.match(/\//);
|
2022-05-31 13:45:04 +02:00
|
|
|
expect(req.body[0].value.name).to.equal(variant1);
|
2021-10-08 11:23:29 +02:00
|
|
|
} else if (req.body.length === 2) {
|
|
|
|
expect(req.body[0].op).to.equal('replace');
|
|
|
|
expect(req.body[0].path).to.match(/weight/);
|
|
|
|
expect(req.body[0].value).to.equal(500);
|
|
|
|
expect(req.body[1].op).to.equal('add');
|
2021-11-25 14:05:44 +01:00
|
|
|
expect(req.body[1].path).to.match(/\//);
|
2022-05-31 13:45:04 +02:00
|
|
|
expect(req.body[1].value.name).to.equal(variant2);
|
2021-10-08 11:23:29 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-25 10:21:28 +01:00
|
|
|
).as('variantCreation');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_VARIANT_BUTTON]').click();
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.wait(1000);
|
2022-05-31 13:45:04 +02:00
|
|
|
cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variant1);
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantCreation');
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_VARIANT_BUTTON]').click();
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.wait(1000);
|
2022-05-31 13:45:04 +02:00
|
|
|
cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variant2);
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantCreation');
|
2021-10-08 11:23:29 +02:00
|
|
|
});
|
2021-10-28 13:32:29 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can set weight to fixed value for one of the variants', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2022-05-31 13:45:04 +02:00
|
|
|
cy.get(`[data-testid=VARIANT_EDIT_BUTTON_${variant1}]`).click();
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.wait(1000);
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=VARIANT_NAME_INPUT]')
|
2021-10-08 11:23:29 +02:00
|
|
|
.children()
|
|
|
|
.find('input')
|
|
|
|
.should('have.attr', 'disabled');
|
2022-05-02 15:52:41 +02:00
|
|
|
cy.get('[data-testid=VARIANT_WEIGHT_CHECK]').find('input').check();
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=VARIANT_WEIGHT_INPUT]').clear().type('15');
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body[0].op).to.equal('replace');
|
|
|
|
expect(req.body[0].path).to.match(/weight/);
|
|
|
|
expect(req.body[0].value).to.equal(850);
|
|
|
|
expect(req.body[1].op).to.equal('replace');
|
|
|
|
expect(req.body[1].path).to.match(/weightType/);
|
|
|
|
expect(req.body[1].value).to.equal('fix');
|
|
|
|
expect(req.body[2].op).to.equal('replace');
|
|
|
|
expect(req.body[2].path).to.match(/weight/);
|
|
|
|
expect(req.body[2].value).to.equal(150);
|
|
|
|
}
|
2022-02-25 10:21:28 +01:00
|
|
|
).as('variantUpdate');
|
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantUpdate');
|
2022-05-31 13:45:04 +02:00
|
|
|
cy.get(`[data-testid=VARIANT_WEIGHT_${variant1}]`).should(
|
|
|
|
'have.text',
|
|
|
|
'15 %'
|
|
|
|
);
|
2021-10-08 11:23:29 +02:00
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can delete variant', () => {
|
2021-10-08 11:23:29 +02:00
|
|
|
const variantName = 'to-be-deleted';
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=ADD_VARIANT_BUTTON]').click();
|
2022-03-09 14:59:24 +01:00
|
|
|
cy.wait(1000);
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variantName);
|
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
2022-03-09 14:59:24 +01:00
|
|
|
const patch = req.body.find(
|
|
|
|
(patch: Record<string, string>) => patch.op === 'remove'
|
|
|
|
);
|
|
|
|
expect(patch.path).to.match(/\//);
|
2021-10-08 11:23:29 +02:00
|
|
|
}
|
|
|
|
).as('delete');
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2022-04-08 13:13:45 +02:00
|
|
|
cy.get(`[data-testid=VARIANT_DELETE_BUTTON_${variantName}]`).click();
|
|
|
|
cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click();
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.wait('@delete');
|
|
|
|
});
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|