diff --git a/packages/manager/.changeset/pr-11440-tests-1734593684793.md b/packages/manager/.changeset/pr-11440-tests-1734593684793.md new file mode 100644 index 00000000000..6760cfd5001 --- /dev/null +++ b/packages/manager/.changeset/pr-11440-tests-1734593684793.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Cypress test to validate CAA records are editable ([#11440](https://github.com/linode/manager/pull/11440)) diff --git a/packages/manager/cypress/e2e/core/domains/smoke-create-domain-records.spec.ts b/packages/manager/cypress/e2e/core/domains/smoke-create-domain-records.spec.ts index 950719ce399..22fd28b798a 100644 --- a/packages/manager/cypress/e2e/core/domains/smoke-create-domain-records.spec.ts +++ b/packages/manager/cypress/e2e/core/domains/smoke-create-domain-records.spec.ts @@ -2,22 +2,83 @@ import { authenticate } from 'support/api/authentication'; import { createDomain } from 'support/api/domains'; import { interceptCreateDomainRecord } from 'support/intercepts/domains'; import { createDomainRecords } from 'support/constants/domains'; +import { ui } from 'support/ui'; +import { cleanUp } from 'support/util/cleanup'; + +const createCaaRecord = ( + name: string, + tag: string, + value: string, + ttl: string +) => { + cy.findByText('Add a CAA Record').click(); + + // Fill in the form fields + cy.findByLabelText('Name').type(name); + + ui.autocomplete.findByLabel('Tag').click(); + ui.autocompletePopper.findByTitle(tag).click(); + + cy.findByLabelText('Value').type(value); + + ui.autocomplete.findByLabel('TTL').click(); + ui.autocompletePopper.findByTitle(ttl).click(); + + // Save the record + ui.button + .findByTitle('Save') + .should('be.visible') + .should('be.enabled') + .click(); +}; + +// Reusable function to edit a CAA record +const editCaaRecord = (name: string, newValue: string) => { + ui.actionMenu + .findByTitle(`Action menu for Record ${name}`) + .should('be.visible') + .click(); + + ui.actionMenuItem.findByTitle('Edit').should('be.visible').click(); + + // Edit the value field + cy.findByLabelText('Value').clear().type(newValue); + ui.button.findByTitle('Save').click(); +}; + +// Reusable function to verify record details in the table +const verifyRecordInTable = ( + name: string, + tag: string, + value: string, + ttl: string +) => { + cy.get('[aria-label="List of Domains CAA Record"]') // Target table by aria-label + .should('contain', name) + .and('contain', tag) + .and('contain', value) + .and('contain', ttl); +}; authenticate(); + +before(() => { + cleanUp('domains'); +}); + beforeEach(() => { cy.tag('method:e2e'); + createDomain().then((domain) => { + // intercept create API record request + interceptCreateDomainRecord().as('apiCreateRecord'); + const url = `/domains/${domain.id}`; + cy.visitWithLogin(url); + cy.url().should('contain', url); + }); }); describe('Creates Domains records with Form', () => { it('Adds domain records to a newly created Domain', () => { - createDomain().then((domain) => { - // intercept create api record request - interceptCreateDomainRecord().as('apiCreateRecord'); - const url = `/domains/${domain.id}`; - cy.visitWithLogin(url); - cy.url().should('contain', url); - }); - createDomainRecords().forEach((rec) => { cy.findByText(rec.name).click(); rec.fields.forEach((field) => { @@ -36,3 +97,37 @@ describe('Creates Domains records with Form', () => { }); }); }); + +describe('Tests for Editable Domain CAA Records', () => { + beforeEach(() => { + // Create the initial record with a valid email + createCaaRecord( + 'securitytest', + 'iodef', + 'mailto:security@example.com', + '5 minutes' + ); + + // Verify the initial record is in the table + verifyRecordInTable( + 'securitytest', + 'iodef', + 'mailto:security@example.com', + '5 minutes' + ); + }); + + it('Validates that "iodef" domain records can be edited with valid record', () => { + // Edit the record with a valid email and verify the updated record + editCaaRecord('securitytest', 'mailto:secdef@example.com'); + cy.get('table').should('contain', 'mailto:secdef@example.com'); + }); + + it('Validates that "iodef" domain records returns error with invalid record', () => { + // Edit the record with invalid email and validate form validation + editCaaRecord('securitytest', 'invalid-email-format'); + cy.get('p[role="alert"][data-qa-textfield-error-text="Value"]') + .should('exist') + .and('have.text', 'You have entered an invalid target'); + }); +});