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

Fleet qa/click resources and refactor verifytablerow #167

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion tests/cypress/e2e/unit_tests/first_login_rancher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('First login on Rancher', { tags: '@login' }, () => {
cy.contains('Dashboard').should('be.visible');
cypressLib.accesMenu('Clusters');
cy.fleetNamespaceToggle('fleet-local');
cy.verifyTableRow(0, 'Active', ' ' );
cy.verifyTableRow(0, 'Active');
cy.get("td[data-testid='sortable-cell-0-2']", { timeout: 300000 }).should("not.contain", '0');
})
);
Expand Down
2 changes: 2 additions & 0 deletions tests/cypress/e2e/unit_tests/p0_fleet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('Test Fleet deployment on PUBLIC repos', { tags: '@p0' }, () => {
cy.contains('apiVersion: fleet.cattle.io/v1alpha1').should('be.visible');
cy.clickButton('Create')
cy.checkGitRepoStatus(repoName, '1 / 1', '6 / 6');
// Click on "Resources" option
cy.get('a[data-testid="btn-resources"]').contains('Resources').should('be.visible').click();
cy.verifyTableRow(1, 'Service', 'frontend');
cy.verifyTableRow(3, 'Service', 'redis-master');
cy.verifyTableRow(5, 'Service', 'redis-slave');
Expand Down
4 changes: 3 additions & 1 deletion tests/cypress/e2e/unit_tests/p1_fleet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ if (!/\/2\.7/.test(Cypress.env('rancher_version'))) {
cy.accesMenuSelection('local', 'Workloads');
cy.nameSpaceMenuToggle('All Namespaces');
cy.filterInSearchBox('fleet-controller');
cy.verifyTableRow(0, 'Running', 'fleet-controller')
cy.verifyTableRow(0, 'Active', 'fleet-controller')
// This is to check "Running" count is present behind dropdown
cy.get('span.counts-label').contains('Running').should('exist');
cy.deleteAllFleetRepos();
})
)
Expand Down
55 changes: 23 additions & 32 deletions tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,39 +141,30 @@ Cypress.Commands.add('open3dotsMenu', (name, selection, checkNotInMenu=false) =>
}
});

// Verify textvalues in table giving the row number
// More items can be added with new ".and"
Cypress.Commands.add('verifyTableRow', (rowNumber, expectedText1, expectedText2) => {
// Adding small wait to give time for things to settle a bit
// Could not find a better way to wait, but can be improved
cy.wait(1000)
// Ensure table is loaded and visible
cy.contains('tr.main-row[data-testid="sortable-table-0-row"]').should('not.be.empty', { timeout: 25000 });
cy.get(`table > tbody > tr.main-row[data-testid="sortable-table-${rowNumber}-row"]`, { timeout: 60000 }).should(($row) => {
// Replace whitespaces by a space and trim the string for both expected texts
const text = $row.text().replace(/\s+/g, ' ').trim();

// Check if expectedTextX is a regular expression or a string and perform the assertion
if (expectedText1) {
// If expectedText1 is provided, perform the check
if (expectedText1 instanceof RegExp) {
expect(text).to.match(expectedText1);
} else {
expect(text).to.include(expectedText1);
}
}

if (expectedText2) {
// If expectedText2 is provided, perform the check
if (expectedText2 instanceof RegExp) {
expect(text).to.match(expectedText2);
} else {
expect(text).to.include(expectedText2);
}
}
});
// Verify all elemennts desired in a table, given an specific row
Cypress.Commands.add('verifyTableRow', (rowNumber, ...expectedTexts) => {
// Adding small wait to give time for things to settle a bit
// Could not find a better way to wait, but can be improved
cy.wait(1000)

cy.get(`table > tbody > tr.main-row[data-testid="sortable-table-${rowNumber}-row"]`, { timeout: 60000 }).should('be.visible').then(($row) => {

// Replace whitespaces by a space and trim the string for both expected texts
const text = $row.text().replace(/\s+/g, ' ').trim();

// Check if expectedTextX is a regular expression or a string and perform the assertion
expectedTexts.forEach(expectedText => {
if (expectedTexts instanceof RegExp) {
expect(text).to.match(expectedText);
}
else {
cy.contains(expectedText, { timeout: 30000 }).should('be.visible');
}
});
});
});


// Namespace Toggle
Cypress.Commands.add('nameSpaceMenuToggle', (namespaceName) => {
cy.get('.top > .ns-filter').should('be.visible');
Expand Down Expand Up @@ -348,7 +339,7 @@ Cypress.Commands.add('assignRoleToUser', (userName, roleName) => {
// Sortering by Age so first row is the desired user
cy.contains('Age').should('be.visible').click();
// Verifying name only given in 2.9 there is only icon
cy.verifyTableRow(0, userName, '');
cy.verifyTableRow(0, userName);
})

// Delete created user
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare global {
gitRepoAuth(AuthType: string, userOrPublicKey?: string, pwdOrPrivateKey?: string, gitOrHelmAuth?: string, helmUrlRegex?: string): Chainable<Element>;
addFleetGitRepo(repoName: string, repoUrl?: string, branch?: string, path?: string, fleetNamespace?: string): Chainable<Element>;
fleetNamespaceToggle(toggleOption: string): Chainable<Element>;
verifyTableRow(rowNumber: number, expectedText1?: string|RegExp, expectedText2?: string|RegExp): Chainable<Element>;
verifyTableRow(rowNumber: number, expectedTexts?: string|RegExp): Chainable<Element>;
nameSpaceMenuToggle(namespaceName: string): Chainable<Element>;
accesMenuSelection(firstAccessMenu: string, secondAccessMenu?: string, clickOption?: string): Chainable<Element>;
filterInSearchBox(filterText: string): Chainable<Element>;
Expand Down
Loading