Skip to content

Commit

Permalink
test: [M3-8661] - Cypress test to validate CAA record are editable (#…
Browse files Browse the repository at this point in the history
…11440)

* test: [M3-8661] - Cypress test to validate CAA record are editable

* Added changeset: Cypress test to validate CAA records are editable

* Splitting the test cases for valid and invalid records

* Move`createCaaRecord` and `verifyRecordInTable` function calls in `beforeEach` block

* Add cleanup, use @example.com for emails, and replace `cy.get()` for stability.

* Update Changeset type
  • Loading branch information
hasyed-akamai authored Jan 7, 2025
1 parent 7432afd commit 3febaa0
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 8 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11440-tests-1734593684793.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Cypress test to validate CAA records are editable ([#11440](https://github.com/linode/manager/pull/11440))
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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:[email protected]',
'5 minutes'
);

// Verify the initial record is in the table
verifyRecordInTable(
'securitytest',
'iodef',
'mailto:[email protected]',
'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:[email protected]');
cy.get('table').should('contain', 'mailto:[email protected]');
});

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');
});
});

0 comments on commit 3febaa0

Please sign in to comment.