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

automation: fleet dashboard tests #12983

Merged
merged 1 commit into from
Jan 9, 2025
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
6 changes: 6 additions & 0 deletions cypress/e2e/po/components/header.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export class HeaderPo extends ComponentPo {
return wsFilter.clickOptionWithLabel(name);
}

checkCurrentWorkspace(name: string) {
const wsFilter = new WorkspaceSwitcherPo();

return wsFilter.checkOptionSelected(name);
}

importYamlHeaderAction() {
return this.self().find('[data-testid="header-action-import-yaml"]');
}
Expand Down
65 changes: 65 additions & 0 deletions cypress/e2e/po/edit/fleet/gitrepo-edit.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import PagePo from '@/cypress/e2e/po/pages/page.po';
import ArrayListPo from '@/cypress/e2e/po/components/array-list.po';
import CreateEditViewPo from '@/cypress/e2e/po/components/create-edit-view.po';
import LabeledInputPo from '@/cypress/e2e/po/components/labeled-input.po';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';
import SelectOrCreateAuthPo from '@/cypress/e2e/po/components/select-or-create-auth.po';
import NameNsDescription from '@/cypress/e2e/po/components/name-ns-description.po';

export class GitRepoEditPo extends PagePo {
private static createPath(fleetWorkspace: string, gitRepoName: string) {
return `/c/_/fleet/fleet.cattle.io.gitrepo/${ fleetWorkspace }/${ gitRepoName }`;
}

static goTo(path: string): Cypress.Chainable<Cypress.AUTWindow> {
throw new Error('invalid');
}

constructor(fleetWorkspace: string, gitRepoName: string) {
super(GitRepoEditPo.createPath(fleetWorkspace, gitRepoName));
}

title() {
return this.self().get('.title .primaryheader h1');
}

nameNsDescription() {
return new NameNsDescription(this.self());
}

setBranchName(branch = 'dashboard-e2e-basic') {
return LabeledInputPo.byLabel(this.self(), 'Branch').set(branch);
}

setGitRepoUrl(url: string) {
return LabeledInputPo.byLabel(this.self(), 'Repository URL').set(url);
}

setHelmRepoURLRegex(regexStr = 'https://charts.rancher.io/*') {
return LabeledInputPo.bySelector(this.self(), '[data-testid="gitrepo-helm-repo-url-regex"]').set(regexStr);
}

setGitRepoPath(path: string, index = 0) {
return this.gitRepoPaths().setValueAtIndex(path, index);
}

targetCluster(): LabeledSelectPo {
return new LabeledSelectPo('[data-testid="fleet-gitrepo-target-cluster"]');
}

footer() {
return new CreateEditViewPo(this.self());
}

gitRepoPaths() {
return new ArrayListPo('[data-testid="gitRepo-paths"]');
}

authSelectOrCreate(selector: string) {
return new SelectOrCreateAuthPo(selector);
}

helmAuthSelectOrCreate() {
return this.authSelectOrCreate('[data-testid="gitrepo-helm-auth"]');
}
}
17 changes: 17 additions & 0 deletions cypress/e2e/po/pages/fleet/fleet-dashboard.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PagePo from '@/cypress/e2e/po/pages/page.po';
import ResourceTablePo from '@/cypress/e2e/po/components/resource-table.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import { LONG_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';
import BaseResourceList from '@/cypress/e2e/po/lists/base-resource-list.po';

export class FleetDashboardPagePo extends PagePo {
static url: string;
Expand Down Expand Up @@ -44,4 +45,20 @@ export class FleetDashboardPagePo extends PagePo {
sortableTable(tableName = 'fleet-local') {
return this.resourceTable(tableName).sortableTable();
}

goToGitRepoListLink(name: 'fleet-local' | 'fleet-default') {
return this.self().find(`[data-testid="collapsible-card-${ name }"] h2 span` );
}

list() {
return new BaseResourceList('[data-testid="sortable-table-list-container"]');
}

fleetDashboardEmptyState() {
return this.self().get('.fleet-empty-dashboard');
}

getStartedButton() {
return this.self().get('.btn').contains('Get started');
}
}
232 changes: 190 additions & 42 deletions cypress/e2e/tests/pages/fleet/dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,213 @@
import { FleetDashboardPagePo } from '@/cypress/e2e/po/pages/fleet/fleet-dashboard.po';
// import { GitRepoCreatePo } from '@/cypress/e2e/po/pages/fleet/gitrepo-create.po';
// import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
// import { LONG_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';

describe('Fleet Dashboard', { tags: ['@fleet', '@adminUser'] }, () => {
let fleetDashboardPage: FleetDashboardPagePo;
// const repoName = 'fleet-e2e-test-dashboard';

// Note - The 'describe` previously had `.only`, which ironically meant this was not tested in our CI (probably something to so with grep tags)
// Enabling the test results results in consistent failures (bundle does not become ready). For the short term comment these out
import FleetGitRepoDetailsPo from '@/cypress/e2e/po/detail/fleet/fleet.cattle.io.gitrepo.po';
import { GitRepoCreatePo } from '@/cypress/e2e/po/pages/fleet/gitrepo-create.po';
import { GitRepoEditPo } from '@/cypress/e2e/po/edit/fleet/gitrepo-edit.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import { LONG_TIMEOUT_OPT } from '@/cypress/support/utils/timeouts';
import { gitRepoTargetAllClustersRequest } from '@/cypress/e2e/blueprints/fleet/gitrepos';
import { HeaderPo } from '@/cypress/e2e/po/components/header.po';
import { MenuActions } from '@/cypress/support/types/menu-actions';
import * as path from 'path';
import * as jsyaml from 'js-yaml';
import { FleetGitRepoListPagePo } from '@/cypress/e2e/po/pages/fleet/fleet.cattle.io.gitrepo.po';
const downloadsFolder = Cypress.config('downloadsFolder');

describe('Fleet Dashboard', { tags: ['@fleet', '@adminUser', '@jenkins'] }, () => {
const fleetDashboardPage = new FleetDashboardPagePo('_');
const gitRepoCreatePage = new GitRepoCreatePo('_');
const headerPo = new HeaderPo();

let repoName;
const gitRepoUrl = 'https://github.com/rancher/fleet-test-data';
const branch = 'master';
const paths = 'qa-test-apps/nginx-app';
const localWorkspace = 'fleet-local';
let removeGitRepo = false;
const reposToDelete = [];

beforeEach(() => {
cy.login();
fleetDashboardPage = new FleetDashboardPagePo('_');
fleetDashboardPage.goTo();
cy.createE2EResourceName('git-repo').then((name) => {
repoName = name;
});
});

it('has the correct title', () => {
cy.get('.fleet-empty-dashboard').should('be.visible');
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();

fleetDashboardPage.fleetDashboardEmptyState().should('be.visible');

cy.title().should('eq', 'Rancher - Continuous Delivery - Dashboard');
});

// before(() => {
// cy.login();
it('Get Started button takes you to the correct page', () => {
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();

// const gitRepoCreatePage = new GitRepoCreatePo('_');
fleetDashboardPage.fleetDashboardEmptyState().should('be.visible');
fleetDashboardPage.getStartedButton().click();
gitRepoCreatePage.waitForPage();
gitRepoCreatePage.title().contains('Git Repo: Create').should('be.visible');
});

// gitRepoCreatePage.goTo();
it('Should display cluster status', () => {
// create gitrepo
cy.createRancherResource('v1', 'fleet.cattle.io.gitrepos', gitRepoTargetAllClustersRequest(localWorkspace, repoName, gitRepoUrl, branch, paths)).then(() => {
removeGitRepo = true;
reposToDelete.push(`fleet-local/${ repoName }`);
});

// gitRepoCreatePage.setRepoName(repoName);
// gitRepoCreatePage.selectWorkspace('fleet-local');
// gitRepoCreatePage.setGitRepoUrl('https://github.com/rancher/fleet-test-data.git');
// gitRepoCreatePage.setBranchName();
// // NB - This step is here because DOM may not be ready
// gitRepoCreatePage.goToNext();
// gitRepoCreatePage.create();
// });
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();

// it('Should display cluster status', () => {
// // check if burguer menu nav is highlighted correctly for Fleet
// BurgerMenuPo.checkIfMenuItemLinkIsHighlighted('Continuous Delivery');
// check if burguer menu nav is highlighted correctly for Fleet
BurgerMenuPo.checkIfMenuItemLinkIsHighlighted('Continuous Delivery');

// const row = fleetDashboardPage.sortableTable('fleet-local').row(0);
const row = fleetDashboardPage.sortableTable(localWorkspace).row(0);

// row.get('.bg-success[data-testid="clusters-ready"]', LONG_TIMEOUT_OPT).should('exist');
// row.get('.bg-success[data-testid="clusters-ready"] span').should('have.text', '1/1');
row.get('.bg-success[data-testid="clusters-ready"]', LONG_TIMEOUT_OPT).should('exist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, it's not possible to avoid this row.get in this case is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct in this case .get is a method in cypress/e2e/po/components/list-row.po.ts and accepts selector and options as arguments. Instead of the cy.get() command

row.get('.bg-success[data-testid="clusters-ready"] span').should('have.text', '1/1');

// row.get('.bg-success[data-testid="bundles-ready"]').should('exist');
// row.get('.bg-success[data-testid="bundles-ready"] span').should('have.text', '1/1');
row.get('.bg-success[data-testid="bundles-ready"]').should('exist');
row.get('.bg-success[data-testid="bundles-ready"] span').should('have.text', '1/1');

// row.get('.bg-success[data-testid="resources-ready"]').should('exist');
// row.get('.bg-success[data-testid="resources-ready"] span').should('have.text', '1/1');
// });
row.get('.bg-success[data-testid="resources-ready"]').should('exist');
row.get('.bg-success[data-testid="resources-ready"] span').should('have.text', '1/1');
});

// after(() => {
// fleetDashboardPage = new FleetDashboardPagePo('_');
// fleetDashboardPage.goTo();
it('can navigate to Git Repo details page from Fleet Dashboard', () => {
const gitRepoDetails = new FleetGitRepoDetailsPo(localWorkspace, repoName);

// const fleetLocalResourceTable = fleetDashboardPage.resourceTable('fleet-local');
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.list().rowWithName(repoName).column(0).find('a')
.click();
gitRepoDetails.waitForPage(null, 'bundles');
});

it('should only display action menu with allowed actions only', () => {
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
headerPo.selectWorkspace(localWorkspace);

const constActionMenu = fleetDashboardPage.sortableTable().rowActionMenuOpen(repoName);

const allowedActions: MenuActions[] = [
MenuActions.Pause,
MenuActions.ForceUpdate,
MenuActions.EditYaml,
MenuActions.EditConfig,
MenuActions.Clone,
MenuActions.DownloadYaml,
MenuActions.Delete
];

const disabledActions: MenuActions[] = [MenuActions.ChangeWorkspace];

allowedActions.forEach((action) => {
constActionMenu.getMenuItem(action).should('exist');
});

// Disabled actions should not exist
disabledActions.forEach((action) => {
constActionMenu.getMenuItem(action).should('not.exist');
});
});

it('can clone a git repo', () => {
const gitRepoEditPage = new GitRepoEditPo(localWorkspace, repoName);

fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable().rowActionMenuOpen(repoName).getMenuItem('Clone').click();

gitRepoEditPage.waitForPage('mode=clone');
gitRepoEditPage.title().contains(`Git Repo: Clone from ${ repoName }`).should('be.visible');
headerPo.selectWorkspace('fleet-default');
gitRepoEditPage.nameNsDescription().name().set(`clone-${ repoName }`);
gitRepoEditPage.footer().nextPage();
gitRepoEditPage.footer().create().then(() => {
removeGitRepo = true;
reposToDelete.push(`fleet-default/clone-${ repoName }`);
});

FleetDashboardPagePo.navTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable('fleet-default').rowElementWithName(`clone-${ repoName }`).should('be.visible');
fleetDashboardPage.sortableTable('fleet-local').rowElementWithName(repoName).should('be.visible');
});

it('user lands in correct git repo workspace when using workspace link on Fleet Dashboard', () => {
const gitrepoListPage = new FleetGitRepoListPagePo();

fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable('fleet-default').rowElementWithName(`clone-${ repoName }`).should('be.visible');
fleetDashboardPage.sortableTable('fleet-local').rowElementWithName(repoName).should('be.visible');

// fleetLocalResourceTable.sortableTable().deleteItemWithUI(repoName);
// });
// click workspace link: fleet default
fleetDashboardPage.goToGitRepoListLink('fleet-default').click();
gitrepoListPage.waitForPage();
headerPo.checkCurrentWorkspace('fleet-default');

// click workspace link: fleet local
fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.goToGitRepoListLink('fleet-local').click();
gitrepoListPage.waitForPage();
headerPo.checkCurrentWorkspace('fleet-local');
});

it('can Edit Yaml', () => {
const gitRepoEditPage = new GitRepoEditPo(localWorkspace, repoName);

fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable().rowActionMenuOpen(repoName).getMenuItem('Edit YAML').click();
gitRepoEditPage.waitForPage('mode=edit&as=yaml');
gitRepoEditPage.title().contains(`Git Repo: ${ repoName }`).should('be.visible');
});

it('can Download Yaml', () => {
cy.deleteDownloadsFolder();

fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable().rowActionMenuOpen(repoName).getMenuItem('Download YAML').click();

const downloadedFilename = path.join(downloadsFolder, `${ repoName }.yaml`);

cy.readFile(downloadedFilename).then((buffer) => {
const obj: any = jsyaml.load(buffer);

// Basic checks on the downloaded YAML
expect(obj.kind).to.equal('GitRepo');
expect(obj.metadata['name']).to.equal(repoName);
expect(obj.metadata['namespace']).to.equal(localWorkspace);
expect(obj.spec['repo']).to.equal(gitRepoUrl);
});
});

it('can Edit Config', () => {
const gitRepoEditPage = new GitRepoEditPo(localWorkspace, repoName);
const description = `${ repoName }-desc`;

fleetDashboardPage.goTo();
fleetDashboardPage.waitForPage();
fleetDashboardPage.sortableTable().rowActionMenuOpen(repoName).getMenuItem('Edit Config').click();

gitRepoEditPage.waitForPage('mode=edit');
gitRepoEditPage.nameNsDescription().description().set(description);
gitRepoEditPage.footer().nextPage();
gitRepoEditPage.footer().save();
fleetDashboardPage.waitForPage();
});

after(() => {
if (removeGitRepo) {
// delete gitrepo
reposToDelete.forEach((r) => cy.deleteRancherResource('v1', 'fleet.cattle.io.gitrepo', r));
}
});
});
3 changes: 3 additions & 0 deletions cypress/support/types/menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export enum MenuActions {
ViewInApi = 'View in API', // eslint-disable-line no-unused-vars
ChangeWorkspace = 'Change workspace', // eslint-disable-line no-unused-vars
Delete = 'Delete', // eslint-disable-line no-unused-vars
Clone = 'Clone', // eslint-disable-line no-unused-vars
DownloadYaml = 'Download YAML', // eslint-disable-line no-unused-vars

}
Loading