Skip to content

Commit

Permalink
test: [M3-8526] - Update remaining Linode Create Cypress tests run ag…
Browse files Browse the repository at this point in the history
…ainst Linode Create v2 (#10889)

* run tests aginst linode create v2

* Added changeset: Update remaining Linode Create Cypress tests run against Linode Create v2

* extract  into new test files

* retain the linode create region select test

---------

Co-authored-by: Banks Nussman <banks@nussman.us>
  • Loading branch information
bnussman-akamai and bnussman authored Sep 9, 2024
1 parent 9e2a990 commit 4379494
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 832 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10889-tests-1725485099504.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Update remaining Linode Create Cypress tests run against Linode Create v2 ([#10889](https://github.com/linode/manager/pull/10889))
67 changes: 39 additions & 28 deletions packages/manager/cypress/e2e/core/general/gdpr-agreement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { ui } from 'support/ui';
import { fbtClick, getClick } from 'support/helpers';
import { regionFactory } from '@src/factories';
import { linodeFactory, regionFactory } from '@src/factories';
import { randomString, randomLabel } from 'support/util/random';
import { mockGetRegions } from 'support/intercepts/regions';
import { mockGetAccountAgreements } from 'support/intercepts/account';
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import { makeFeatureFlagData } from 'support/util/feature-flags';

import type { Region } from '@linode/api-v4';
import { mockCreateLinode } from 'support/intercepts/linodes';

const mockRegions: Region[] = [
regionFactory.build({
Expand Down Expand Up @@ -102,15 +97,7 @@ describe('GDPR agreement', () => {
cy.get('[data-testid="eu-agreement-checkbox"]').should('not.exist');
});

it('needs the agreement checked to validate the form', () => {
// This test does not apply to Linode Create v2 because
// Linode Create v2 allows you to press "Create Linode"
// without checking the GDPR checkbox. (The user will
// get a validation error if they have not agreed).
mockAppendFeatureFlags({
linodeCreateRefactor: makeFeatureFlagData(false),
});
mockGetFeatureFlagClientstream();
it('needs the agreement checked to submit the form', () => {
mockGetRegions(mockRegions).as('getRegions');
mockGetAccountAgreements({
privacy_policy: false,
Expand All @@ -120,26 +107,50 @@ describe('GDPR agreement', () => {
const linodeLabel = randomLabel();

cy.visitWithLogin('/linodes/create');
cy.wait(['@getAgreements', '@getRegions']);
cy.wait(['@getRegions']);

// Paris should have the agreement
ui.regionSelect.find().click();
ui.regionSelect.findItemByRegionId('fr-par').click();
cy.get('[data-testid="eu-agreement-checkbox"]').should('be.visible');

// Fill out the form
fbtClick('Shared CPU');
getClick('[id="g6-nanode-1"]');
getClick('#linode-label').clear().type(linodeLabel);
cy.get('#root-password').type(rootpass);
cy.wait('@getAgreements');

cy.findByText('Shared CPU').click();

cy.get('[id="g6-nanode-1"]').click();

cy.findByLabelText('Linode Label').clear().type(linodeLabel);

cy.findByLabelText('Root Password').type(rootpass);

// expect the button to be disabled
cy.get('[data-qa-deploy-linode="true"]').should('be.disabled');
cy.get('[data-testid="eu-agreement-checkbox"]')
.scrollIntoView()
.should('be.visible');

cy.findByText('Create Linode')
.scrollIntoView()
.should('be.enabled')
.should('be.visible')
.click();

cy.findByText(
'You must agree to the EU agreement to deploy to this region.'
).should('be.visible');

// check the agreement
getClick('#gdpr-checkbox');
cy.get('#gdpr-checkbox').click();

cy.findByText(
'You must agree to the EU agreement to deploy to this region.'
).should('not.exist');

mockCreateLinode(linodeFactory.build()).as('createLinode');

cy.findByText('Create Linode')
.should('be.enabled')
.should('be.visible')
.click();

// expect the button to be enabled
cy.get('[data-qa-deploy-linode="true"]').should('not.be.disabled');
cy.wait('@createLinode');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,10 @@ import { MOBILE_VIEWPORTS } from 'support/constants/environment';
import { linodeCreatePage } from 'support/ui/pages';
import { randomLabel, randomNumber, randomString } from 'support/util/random';
import { chooseRegion } from 'support/util/regions';
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import { makeFeatureFlagData } from 'support/util/feature-flags';
import { ui } from 'support/ui';
import { mockCreateLinode } from 'support/intercepts/linodes';

describe('Linode create mobile smoke', () => {
// TODO Remove feature flag mocks when `linodeCreateRefactor` flag is retired.
beforeEach(() => {
mockAppendFeatureFlags({
linodeCreateRefactor: makeFeatureFlagData(true),
});
mockGetFeatureFlagClientstream();
});

MOBILE_VIEWPORTS.forEach((viewport) => {
/*
* - Confirms Linode create flow can be completed on common mobile screen sizes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { ui } from 'support/ui';
import {
regionFactory,
} from '@src/factories';
import { mockGetRegions } from 'support/intercepts/regions';
import { extendRegion } from 'support/util/regions';

import type { ExtendedRegion } from 'support/util/regions';

const mockRegions: ExtendedRegion[] = [
extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
country: 'uk',
id: 'eu-west',
label: 'London, UK',
})
),
extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
country: 'sg',
id: 'ap-south',
label: 'Singapore, SG',
})
),
extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
id: 'us-east',
label: 'Newark, NJ',
})
),
extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
id: 'us-central',
label: 'Dallas, TX',
})
),
];

describe('Linode Create Region Select', () => {
/*
* Region select test.
*
* TODO: Cypress
* Move this to cypress component testing once the setup is complete - see https://github.com/linode/manager/pull/10134
*
* - Confirms that region select dropdown is visible and interactive.
* - Confirms that region select dropdown is populated with expected regions.
* - Confirms that region select dropdown is sorted alphabetically by region, with North America first.
* - Confirms that region select dropdown is populated with expected DCs, sorted alphabetically.
*/
it('region select', () => {
mockGetRegions(mockRegions).as('getRegions');

cy.visitWithLogin('linodes/create');

cy.wait('@getRegions');

// Confirm that region select dropdown is visible and interactive.
ui.regionSelect.find().click();
cy.get('[data-qa-autocomplete-popper="true"]').should('be.visible');

// Confirm that region select dropdown are grouped by region,
// sorted alphabetically, with North America first.
cy.get('.MuiAutocomplete-groupLabel')
.should('have.length', 3)
.should((group) => {
expect(group[0]).to.contain('North America');
expect(group[1]).to.contain('Asia');
expect(group[2]).to.contain('Europe');
});

// Confirm that region select dropdown is populated with expected regions, sorted alphabetically.
cy.get('[data-qa-option]').should('exist').should('have.length', 4);
mockRegions.forEach((region) => {
cy.get('[data-qa-option]').contains(region.label);
});

// Select an option
cy.findByTestId('eu-west').click();
// Confirm the popper is closed
cy.get('[data-qa-autocomplete-popper="true"]').should('not.exist');

// Confirm that the selected region is displayed in the input field.
cy.findByLabelText('Region').should(
'have.value',
'UK, London (eu-west)'
);

// Confirm that selecting a valid region updates the Plan Selection panel.
expect(cy.get('[data-testid="table-row-empty"]').should('not.exist'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'support/intercepts/feature-flags';

import { makeFeatureFlagData } from 'support/util/feature-flags';
import { chooseRegion } from 'support/util/regions';

describe('Create Linode', () => {
/*
Expand All @@ -23,7 +24,6 @@ describe('Create Linode', () => {
beforeEach(() => {
mockAppendFeatureFlags({
apicliDxToolsAdditions: makeFeatureFlagData(true),
linodeCreateRefactor: makeFeatureFlagData(true),
});
mockGetFeatureFlagClientstream();
});
Expand Down Expand Up @@ -149,13 +149,13 @@ describe('Create Linode', () => {
});
});
});

describe('Create Linode flow with apicliDxToolsAdditions disabled', () => {
// Enable the `apicliDxToolsAdditions` feature flag.
// TODO Delete these mocks and test once `apicliDxToolsAdditions` feature flag is retired.
beforeEach(() => {
mockAppendFeatureFlags({
apicliDxToolsAdditions: makeFeatureFlagData(false),
linodeCreateRefactor: makeFeatureFlagData(true),
});
mockGetFeatureFlagClientstream();
});
Expand Down Expand Up @@ -203,4 +203,75 @@ describe('Create Linode', () => {
});
});
});

it('creates a linode via CLI', () => {
const linodeLabel = randomLabel();
const linodePass = randomString(32);
const linodeRegion = chooseRegion();

cy.visitWithLogin('/linodes/create');

ui.regionSelect.find().click();
ui.autocompletePopper
.findByTitle(`${linodeRegion.label} (${linodeRegion.id})`)
.should('exist')
.click();

cy.get('[id="g6-dedicated-2"]').click();

cy.findByLabelText('Linode Label')
.should('have.value', `debian-${linodeRegion.id}`);

cy.findByLabelText('Linode Label')
.should('be.visible')
.should('be.enabled')
.clear()
.type(linodeLabel);

cy.findByLabelText('Root Password')
.should('be.visible')
.should('be.enabled')
.type(linodePass);

ui.button
.findByTitle('Create using command line')
.should('be.visible')
.should('be.enabled')
.click();

ui.dialog
.findByTitle('Create Linode')
.should('be.visible')
.within(() => {
// Switch to cURL view if necessary.
cy.findByText('cURL')
.should('be.visible')
.click();

// Confirm that cURL command has expected details.
[
`"region": "${linodeRegion.id}"`,
`"type": "g6-dedicated-2"`,
`"label": "${linodeLabel}"`,
`"root_pass": "${linodePass}"`,
].forEach((line: string) =>
cy.findByText(line, { exact: false }).should('be.visible')
);

cy.findByText('Linode CLI').should('be.visible').click();

[
`--region ${linodeRegion.id}`,
'--type g6-dedicated-2',
`--label ${linodeLabel}`,
`--root_pass ${linodePass}`,
].forEach((line: string) => cy.contains(line).should('be.visible'));

ui.buttonGroup
.findButtonByTitle('Close')
.should('be.visible')
.should('be.enabled')
.click();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { linodeFactory } from 'src/factories';
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import {
mockCreateLinode,
mockGetLinodeDetails,
} from 'support/intercepts/linodes';
import { ui } from 'support/ui';
import { linodeCreatePage } from 'support/ui/pages';
import { makeFeatureFlagData } from 'support/util/feature-flags';
import { randomLabel, randomNumber, randomString } from 'support/util/random';
import { chooseRegion } from 'support/util/regions';

describe('Create Linode with Add-ons', () => {
// TODO Remove feature flag mocks when `linodeCreateRefactor` flag is retired.
beforeEach(() => {
mockAppendFeatureFlags({
linodeCreateRefactor: makeFeatureFlagData(true),
});
mockGetFeatureFlagClientstream();
});

/*
* - Confirms UI flow to create a Linode with backups using mock API data.
* - Confirms that backups is reflected in create summary section.
Expand Down
Loading

0 comments on commit 4379494

Please sign in to comment.