Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [M3-7287] - Add new test for the NodeBalancer Create flow for multiple nodes and multiple configs #10825

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10825-tests-1724428903440.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add tests for NodeBalancer Create flow ([#10825](https://github.com/linode/manager/pull/10825))
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { entityTag } from 'support/constants/cypress';
import { createTestLinode } from 'support/util/linodes';
import { randomLabel } from 'support/util/random';
import { chooseRegion, getRegionById } from 'support/util/regions';
import { ui } from 'support/ui';
import { cleanUp } from 'support/util/cleanup';
import { authenticate } from 'support/api/authentication';
import type { Linode } from '@linode/api-v4';
import { nodeBalancerFactory } from 'src/factories';
import { interceptCreateNodeBalancer } from 'support/intercepts/nodebalancers';

authenticate();
describe('create NodeBalancer to test the submission of multiple nodes and multiple configs', () => {
before(() => {
cleanUp(['tags', 'node-balancers', 'linodes']);
});

/*
* - Confirms NodeBalancer create flow when adding multiple Backend Nodes.
* - Confirms Summary field displays correct Node number.
*/
it('creates a NodeBalancer with multiple Backend Nodes', async () => {
const region = chooseRegion();
const linodePayload = {
region: region.id,
// NodeBalancers require Linodes with private IPs.
private_ip: true,
};
const linode: Linode = await createTestLinode(linodePayload);
const nodeBal = nodeBalancerFactory.build({
label: randomLabel(),
region: region.id,
ipv4: linode.ipv4[1],
});

const linodePayload_2 = {
region: region.id,
private_ip: true,
};
const linode_2: Linode = await createTestLinode(linodePayload_2);
const nodeBal_2 = nodeBalancerFactory.build({
label: randomLabel(),
region: region.id,
ipv4: linode_2.ipv4[1],
});
const regionName = getRegionById(nodeBal.region).label;

// catch request
interceptCreateNodeBalancer().as('createNodeBalancer');
cy.visitWithLogin('/nodebalancers/create');
cy.get('[id="nodebalancer-label"]')
.should('be.visible')
.click()
.clear()
.type(nodeBal.label);
cy.findByPlaceholderText(/create a tag/i)
.click()
.type(entityTag);

// this will create the NB in newark, where the default Linode was created
ui.regionSelect.find().click().clear().type(`${regionName}{enter}`);

// node backend config
cy.findByText('Label').click().type(randomLabel());
cy.findByLabelText('IP Address')
.should('be.visible')
.click()
.type(nodeBal.ipv4);
ui.autocompletePopper
.findByTitle(nodeBal.ipv4)
.should('be.visible')
.click();
cy.findByLabelText('Weight')
.should('be.visible')
.click()
.clear()
.type('50');

// Add a backend node
cy.get('[data-testid="Button"]').contains('Add a Node').click();
cy.findAllByText('Label').last().click().type(randomLabel());
cy.findAllByText('IP Address')
.last()
.should('be.visible')
.click()
.type(nodeBal_2.ipv4);
ui.autocompletePopper
.findByTitle(nodeBal_2.ipv4)
.should('be.visible')
.click();
cy.get('[data-testid="textfield-input"]')
.last()
.should('be.visible')
.click()
.clear()
.type('50');

// Confirm Summary info
cy.get('[data-qa-summary="true"]').within(() => {
cy.contains(`Nodes 2`).should('be.visible');
});

cy.get('[data-qa-deploy-nodebalancer]').click();
cy.wait('@createNodeBalancer').its('response.statusCode').should('eq', 200);
});

/*
* - Confirms NodeBalancer create flow when adding additional config.
* - Confirms Summary field displays correct Config number.
*/
it('creates a NodeBalancer with an additional config', async () => {
const region = chooseRegion();
const linodePayload = {
region: region.id,
// NodeBalancers require Linodes with private IPs.
private_ip: true,
};
const linode: Linode = await createTestLinode(linodePayload);
const nodeBal = nodeBalancerFactory.build({
label: randomLabel(),
region: region.id,
ipv4: linode.ipv4[1],
});

const linodePayload_2 = {
region: region.id,
private_ip: true,
};
const linode_2: Linode = await createTestLinode(linodePayload_2);
const nodeBal_2 = nodeBalancerFactory.build({
label: randomLabel(),
region: region.id,
ipv4: linode_2.ipv4[1],
});
const regionName = getRegionById(nodeBal.region).label;

// catch request
interceptCreateNodeBalancer().as('createNodeBalancer');

cy.visitWithLogin('/nodebalancers/create');
cy.get('[id="nodebalancer-label"]')
.should('be.visible')
.click()
.clear()
.type(nodeBal.label);
cy.findByPlaceholderText(/create a tag/i)
.click()
.type(entityTag);

// This will create the NB in newark, where the default Linode was created
ui.regionSelect.find().click().clear().type(`${regionName}{enter}`);

// Node backend config
cy.findByText('Label').click().type(randomLabel());
cy.findByLabelText('IP Address')
.should('be.visible')
.click()
.type(nodeBal.ipv4);
ui.autocompletePopper
.findByTitle(nodeBal.ipv4)
.should('be.visible')
.click();

// Add another configuration
cy.get('[data-testid="Button"]')
.contains('Add another Configuration')
.click();
cy.get('[data-qa-panel="Configuration - Port "]').within(() => {
cy.get('[data-testid="textfield-input"]').first().click().type('8080');
});
cy.findAllByText('Label').last().click().type(randomLabel());
cy.findAllByText('IP Address')
.last()
.should('be.visible')
.click()
.type(nodeBal_2.ipv4);
ui.autocompletePopper
.findByTitle(nodeBal_2.ipv4)
.should('be.visible')
.click();

// Confirm Summary info
cy.get('[data-qa-summary="true"]').within(() => {
cy.contains('Configs 2').should('be.visible');
});

cy.get('[data-qa-deploy-nodebalancer]').click();
cy.wait('@createNodeBalancer').its('response.statusCode').should('eq', 200);
});

/*
* - Confirms Port field displays error if same port number used in additional config.
* - Confirms Label field displays error if label is empty in additional config.
* - Confirms IP field displays error if ip is empty in additional config.
*/
it('displays errors during adding new config', async () => {
const region = chooseRegion();
const linodePayload = {
region: region.id,
// NodeBalancers require Linodes with private IPs.
private_ip: true,
};
const linode: Linode = await createTestLinode(linodePayload);
const nodeBal = nodeBalancerFactory.build({
label: randomLabel(),
region: region.id,
ipv4: linode.ipv4[1],
});
const regionName = getRegionById(nodeBal.region).label;

cy.visitWithLogin('/nodebalancers/create');
cy.get('[id="nodebalancer-label"]')
.should('be.visible')
.click()
.clear()
.type(nodeBal.label);
cy.findByPlaceholderText(/create a tag/i)
.click()
.type(entityTag);

// This will create the NB in newark, where the default Linode was created
ui.regionSelect.find().click().clear().type(`${regionName}{enter}`);

// Node backend config
cy.findByText('Label').click().type(randomLabel());
cy.findByLabelText('IP Address')
.should('be.visible')
.click()
.type(nodeBal.ipv4);
ui.autocompletePopper
.findByTitle(nodeBal.ipv4)
.should('be.visible')
.click();

// Add another configuration
cy.get('[data-testid="Button"]')
.contains('Add another Configuration')
.click();
cy.get('[data-qa-panel="Configuration - Port "]').within(() => {
cy.get('[data-testid="textfield-input"]').first().click().type('80');
});
cy.get('[data-qa-deploy-nodebalancer]').click();

// Confirm error displays
cy.contains('Port must be unique').scrollIntoView().should('be.visible');
cy.contains('Label is required').scrollIntoView().should('be.visible');
cy.contains('Must be a valid private IPv4 address.')
.scrollIntoView()
.should('be.visible');
});
});
Loading