diff --git a/cypress/integration/all/app/hosts.spec.ts b/cypress/integration/all/app/hosts.spec.ts index 5d222d0156..64f664ce29 100644 --- a/cypress/integration/all/app/hosts.spec.ts +++ b/cypress/integration/all/app/hosts.spec.ts @@ -1,4 +1,5 @@ import _ = require("cypress/types/lodash"); +import { closeSync } from "fs"; import * as path from "path"; let hostname = ""; @@ -11,6 +12,7 @@ describe("Hosts flow", () => { cy.addDockerHost(); cy.clearDownloads(); cy.seedQueries(); + cy.seedSchedule(); cy.seedPolicies(); cy.viewport(1200, 660); }); @@ -70,7 +72,6 @@ describe("Hosts flow", () => { cy.getAttached("@hostLink") // Set hostname variable for later assertions .then((el) => { - console.log(el); hostname = el.text(); return el; }) @@ -87,7 +88,6 @@ describe("Hosts flow", () => { cy.getAttached("@policyLink") // Set policyname variable for later assertions .then((el) => { - console.log(el); policyname = el.text(); return el; }); @@ -115,33 +115,112 @@ describe("Hosts flow", () => { cy.getAttached(".button--text-link").first().click(); }); }); + it("runs query on an existing host", () => { + cy.getAttached(".host-details__action-button-container").within(() => { + cy.getAttached('img[alt="Query host icon"]').click(); + }); + + cy.getAttached(".select-query-modal__modal").within(() => { + cy.getAttached(".modal-query-button").eq(2).click(); + }); + + cy.getAttached(".query-form__button-wrap--new-query").within(() => { + cy.findByText(/run query/i) + .should("exist") + .click(); + }); + cy.getAttached(".query-page__wrapper").within(() => { + cy.getAttached(".data-table").within(() => { + cy.findByText(hostname).should("exist"); + }); + cy.findByText(/run/i).click(); + }); + }); + it("renders and searches the host's users", () => { + cy.getAttached(".section--users").within(() => { + cy.getAttached("tbody>tr").should("have.length.greaterThan", 0); + cy.findByPlaceholderText(/search/i).type("Ash"); + cy.getAttached("tbody>tr").should("have.length", 0); + cy.getAttached(".empty-users").within(() => { + cy.findByText(/no users matched/i).should("exist"); + }); + }); + }); + it("renders and searches the host's software, links to filter hosts by software", () => { + cy.getAttached(".react-tabs__tab-list").within(() => { + cy.findByText(/software/i).click(); + }); + let initialCount = 0; + cy.getAttached(".section--software").within(() => { + cy.getAttached(".table-container__results-count") + .invoke("text") + .then((text) => { + const fullText = text; + const pattern = /[0-9]+/g; + const newCount = fullText.match(pattern); + initialCount = parseInt(newCount[0], 10); + expect(initialCount).to.be.at.least(1); + }); + cy.findByPlaceholderText(/filter software/i).type("lib"); + // Ensures search completes + cy.wait(1000); // eslint-disable-line cypress/no-unnecessary-waiting + cy.getAttached(".table-container__results-count") + .invoke("text") + .then((text) => { + const fullText = text; + const pattern = /[0-9]+/g; + const newCount = fullText.match(pattern); + const searchCount = parseInt(newCount[0], 10); + expect(searchCount).to.be.lessThan(initialCount); + }); + cy.getAttached(".software-link").first().click({ force: true }); + }); + cy.getAttached(".manage-hosts__software-filter-block").within(() => { + cy.getAttached(".manage-hosts__software-filter-name-card").should( + "exist" + ); + }); + cy.getAttached(".data-table").within(() => { + cy.findByText(hostname).should("exist"); + }); + }); + it("renders host's schedule", () => { + cy.getAttached(".react-tabs__tab-list").within(() => { + cy.findByText(/schedule/i).click(); + }); + cy.getAttached(".data-table").within(() => { + cy.findByText(/query name/i).should("exist"); + }); + }); + it("renders host's policies and links to filter hosts by policy status", () => { + cy.getAttached(".react-tabs__tab-list").within(() => { + cy.findByText(/policies/i).click(); + }); + cy.getAttached(".section--policies").within(() => { + cy.findByText(/failing 1 policy/i).should("exist"); + cy.getAttached(".policy-link").first().click({ force: true }); + }); + cy.getAttached(".manage-hosts__policies-filter-name-card").should( + "exist" + ); + cy.getAttached(".data-table").within(() => { + cy.findByText(hostname).should("exist"); + }); + }); it( - "runs query on an existing host", + "refetches host vitals", { retries: { runMode: 2, }, - defaultCommandTimeout: 10000, + defaultCommandTimeout: 15000, }, () => { - cy.getAttached(".host-details__action-button-container").within(() => { - cy.getAttached('img[alt="Query host icon"]').click(); - }); - - cy.getAttached(".select-query-modal__modal").within(() => { - cy.getAttached(".modal-query-button").eq(2).click(); - }); - - cy.getAttached(".query-form__button-wrap--new-query").within(() => { - cy.findByText(/run query/i) - .should("exist") - .click(); - }); - cy.getAttached(".query-page__wrapper").within(() => { - cy.getAttached(".data-table").within(() => { - cy.findByText(hostname).should("exist"); - }); - cy.findByText(/run/i).click(); + cy.getAttached(".hostname-container").within(() => { + cy.contains("button", /refetch/i).click(); + cy.findByText(/fetching/i).should("exist"); + cy.contains("button", /refetch/i).should("exist"); + cy.findByText(/few seconds/i).should("exist"); }); } ); diff --git a/cypress/integration/premium/team_maintainer_observer.spec.ts b/cypress/integration/premium/team_maintainer_observer.spec.ts index b0e17b9a92..60a5d60c32 100644 --- a/cypress/integration/premium/team_maintainer_observer.spec.ts +++ b/cypress/integration/premium/team_maintainer_observer.spec.ts @@ -164,7 +164,9 @@ describe("Premium tier - Team observer/maintainer user", () => { cy.visit("/schedule/manage"); cy.contains(/oranges/i).should("exist"); cy.contains(/advanced/i).should("not.exist"); - cy.findByRole("button", { name: /schedule a query/i }).click(); + cy.getAttached(".no-schedule__cta-buttons").within(() => { + cy.findByRole("button", { name: /schedule a query/i }).click(); + }); // Schedule a query on maintaining team cy.getAttached(".schedule-editor-modal__form").within(() => { cy.findByText(/select query/i).click(); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 22c5c6dad0..9161ff2dab 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -111,6 +111,49 @@ Cypress.Commands.add("seedQueries", () => { }); }); +Cypress.Commands.add("seedSchedule", () => { + const scheduledQueries = [ + { + interval: 86400, + platform: "", + query_id: 1, + removed: false, + shard: null, + snapshot: true, + version: "", + }, + { + interval: 604800, + platform: "linux", + query_id: 2, + removed: true, + shard: 50, + snapshot: false, + version: "4.6.0", + }, + ]; + + scheduledQueries.forEach((scheduleForm) => { + const { + interval, + platform, + query_id, + removed, + shard, + snapshot, + version, + } = scheduleForm; + cy.request({ + url: "/api/v1/fleet/global/schedule", + method: "POST", + body: { interval, platform, query_id, removed, shard, snapshot, version }, + auth: { + bearer: window.localStorage.getItem("FLEET::auth_token"), + }, + }); + }); +}); + Cypress.Commands.add("seedPacks", () => { const packs = [ { diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts index 7429f64a99..8b147bdc9b 100644 --- a/cypress/support/index.d.ts +++ b/cypress/support/index.d.ts @@ -30,7 +30,12 @@ declare namespace Cypress { seedQueries(): Chainable; /** - * Custom command to add new queries by default. + * Custom command to add new scheduled queries by default. + */ + seedSchedule(): Chainable; + + /** + * Custom command to add new policies by default. */ seedPolicies(): Chainable;