Skip to content

Commit

Permalink
chore: keeping UI test simple and testing it fails in 5.6.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonfournier committed Nov 30, 2023
1 parent 8f18e07 commit 05a3dc4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 107 deletions.
79 changes: 0 additions & 79 deletions frontend/cypress/oss/feature/feature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ describe('feature', () => {
const randomId = String(Math.random()).split('.')[1];
const featureToggleName = `unleash-e2e-${randomId}`;

const variant1 = 'variant1';
const variant2 = 'variant2';

before(() => {
cy.runBefore();
});
Expand All @@ -24,80 +21,4 @@ describe('feature', () => {
cy.createFeature_UI(featureToggleName, true, 'default', true);
cy.url().should('include', featureToggleName);
});

it('gives an error if a toggle exists with the same name', () => {
cy.createFeature_UI(featureToggleName, false, 'default', true);
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,
'default',
true,
);
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,
}).then(() => {
cy.get("[data-testid='CloseIcon']").click(); // Close splash
cy.updateFlexibleRolloutStrategy_UI(featureToggleName).then(() =>
cy.deleteFeatureStrategy_UI(featureToggleName),
);
});
});

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='CloseIcon']").click(); // Close splash
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);
});
});
3 changes: 1 addition & 2 deletions frontend/cypress/oss/import/import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('imports', () => {

it('can import data', () => {
cy.visit('/projects/default');
cy.get("[data-testid='CloseIcon']").click(); // Close splash
cy.get("[data-testid='IMPORT_BUTTON']").click({ force: true });
cy.get("[data-testid='IMPORT_BUTTON']").click();

const exportText = {
features: [
Expand Down
16 changes: 0 additions & 16 deletions frontend/cypress/oss/segments/segments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe('segments', () => {
const randomId = String(Math.random()).split('.')[1];
const segmentName = `unleash-e2e-${randomId}`;
let segmentId: string;

before(() => {
cy.runBefore();
Expand All @@ -15,25 +14,10 @@ describe('segments', () => {
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
cy.get("[data-testid='CLOSE_SPLASH']").click();
}
cy.get("[data-testid='CloseIcon']").click(); // Close splash
});

it('can create a segment', () => {
cy.createSegment_UI(segmentName);
cy.contains(segmentName);
});

it('gives an error if a segment exists with the same name', () => {
cy.get("[data-testid='NAVIGATE_TO_CREATE_SEGMENT']").click();
cy.get("[data-testid='SEGMENT_NAME_ID']").type(segmentName);
cy.get("[data-testid='SEGMENT_NEXT_BTN_ID']").should('be.disabled');
cy.get("[data-testid='INPUT_ERROR_TEXT']").contains(
'Segment name already exists',
);
});

it('can delete a segment', () => {
cy.deleteSegment_UI(segmentName, segmentId);
cy.contains(segmentName).should('not.exist');
});
});
21 changes: 11 additions & 10 deletions frontend/cypress/support/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@ export const createFeature_UI = (
name: string,
shouldWait?: boolean,
project?: string,
closeSplash?: boolean,
forceInteractions?: boolean,
): Chainable<any> => {
const projectName = project || 'default';
const uiOpts = forceInteractions ? { force: true } : undefined;
cy.visit(`/projects/${projectName}`);
if (closeSplash ?? false) {
cy.get("[data-testid='CloseIcon']").click(); // Close splash
}
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click();
cy.get('[data-testid=NAVIGATE_TO_CREATE_FEATURE').click(uiOpts);

cy.intercept('POST', `/api/admin/projects/${projectName}/features`).as(
'createFeature',
);

cy.wait(300);

cy.get("[data-testid='CF_NAME_ID'").type(name);
cy.get("[data-testid='CF_DESC_ID'").type('hello-world');
if (!shouldWait) return cy.get("[data-testid='CF_CREATE_BTN_ID']").click();
else cy.get("[data-testid='CF_CREATE_BTN_ID']").click();
cy.get("[data-testid='CF_NAME_ID'] input").type(name, uiOpts);
cy.get("[data-testid='CF_DESC_ID'] textarea")
.first()
.type('hello-world', uiOpts);
if (!shouldWait)
return cy.get("[data-testid='CF_CREATE_BTN_ID']").click(uiOpts);
else cy.get("[data-testid='CF_CREATE_BTN_ID']").click(uiOpts);
return cy.wait('@createFeature');
};

Expand Down Expand Up @@ -288,7 +289,7 @@ export const addVariantsToFeature_UI = (
const project = projectName || 'default';
cy.visit(`/projects/${project}/features/${featureToggleName}/variants`);
cy.wait(200);
cy.get("[data-testid='CloseIcon']").click(); // Close splash

cy.intercept(
'PATCH',
`/api/admin/projects/${project}/features/${featureToggleName}/environments/development/variants`,
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"fmt:check": "biome check src",
"ts:check": "tsc",
"e2e": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" yarn run cypress open --config baseUrl='http://localhost:3000' --env AUTH_USER=admin,AUTH_PASSWORD=unleash4all",
"e2e:oss": "yarn --cwd frontend run cypress run --spec \"cypress/oss/**/*.spec.ts\" --config baseUrl='http://localhost:4242' --env AUTH_USER=admin,AUTH_PASSWORD=unleash4all",
"e2e:heroku": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" yarn run cypress open --config baseUrl='https://unleash.herokuapp.com' --env AUTH_USER=admin,AUTH_PASSWORD=unleash4all",
"gen:api": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" orval --config orval.config.js",
"gen:api:demo": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" UNLEASH_OPENAPI_URL=https://app.unleash-hosted.com/demo/docs/openapi.json yarn run gen:api",
Expand Down

0 comments on commit 05a3dc4

Please sign in to comment.