Skip to content

Commit

Permalink
Merge pull request #2986 from uktrade/chore/DT-1804-add-homepage-e2e-…
Browse files Browse the repository at this point in the history
…test

chore/DT-1804 Add homepage E2E tests
  • Loading branch information
ian-leggett authored Feb 2, 2024
2 parents a30559d + 8b40b6e commit dd7f2c0
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 1,474 deletions.
184 changes: 184 additions & 0 deletions cypress/e2e/datasets/home-page.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const endpoints = {
recentItems: "/api/v2/recent_items/*",
recentCollections: "/api/v2/collections/*",
recentTools: "/api/v2/recent_tools/*",
yourBookmarks: "/api/v2/your_bookmarks/*",
} as const;

describe("Homepage dashboard", () => {
context("When any user visits the page", () => {
beforeEach(() => {
cy.visit("/");
});

it("should show a search bar with a link to getting started", () => {
cy.findByTestId("search-form")
.first()
.findByRole("heading", {
level: 1,
name: "Search Data Workspace",
})
.parent()
.findByRole("link", { name: "Getting started as a new user" })
.should("have.attr", "href", "/welcome");
});

it("should show a support title", () => {
cy.findByRole("heading", {
level: 2,
name: "How we can support you",
}).should("exist");
});

it("should show a 'Get help' article", () => {
cy.findByRole("heading", {
level: 3,
name: "Get help",
}).should("exist");
cy.findByRole("heading", {
level: 4,
name: "Suggested articles",
}).should("exist");
});

it("should show a 'Get in touch' article", () => {
cy.findByRole("heading", {
level: 3,
name: "Get in touch",
}).should("exist");
["Message", "Community", "Work"].forEach((message) => {
cy.findByRole("heading", {
level: 4,
name: message,
}).should("exist");
});
});
});

context("When a user visits the page for the first time", () => {
beforeEach(() => {
cy.intercept(endpoints.recentItems, { results: [] }).as("recentItems");
cy.intercept(endpoints.recentCollections, { results: [] }).as(
"recentCollections"
);
cy.intercept(endpoints.recentTools, { results: [] }).as("recentTools");
cy.intercept(endpoints.yourBookmarks, { results: [] }).as(
"yourBookmarks"
);
cy.visit("/");
});

it("should show the 'Your recent items' section with NO items", () => {
cy.wait("@recentItems");
cy.findByRole("heading", {
level: 2,
name: "Your recent items",
}).should("exist");
cy.findByRole("link", { name: "Data cut - links" }).should("not.exist");
cy.findByRole("link", { name: "Data types on Data Workspace" }).should(
"exist"
);
cy.findByRole("link", { name: "Data cut - links" }).should("not.exist");
});

it("should show the 'Your recent collections' section with NO collections", () => {
cy.wait("@recentCollections");
cy.findByRole("heading", {
level: 2,
name: "Your recent collections",
}).should("exist");
cy.findByRole("link", { name: "Create a collection" }).should("exist");
cy.findByRole("link", {
name: "Find out more about collections",
}).should("exist");
cy.findByRole("link", {
name: "Collection a",
}).should("not.exist");
});

it("should show the 'Your recent tools' section with NO tools", () => {
cy.wait("@recentTools");
cy.findByRole("heading", {
level: 2,
name: "Your recent tools",
}).should("exist");
cy.findByRole("link", { name: "Visit tools" }).should("exist");
cy.findByRole("link", { name: "Find out more about tools" }).should(
"exist"
);
cy.findByRole("link", { name: "Superset" }).should("not.exist");
});

it("should show the 'Your bookmarks' section with NO bookmarks", () => {
cy.wait("@yourBookmarks");
cy.findByRole("heading", {
level: 2,
name: "Your bookmarks",
}).should("exist");
cy.findByRole("link", { name: "Data cut - links" }).should("not.exist");
cy.findByRole("link", { name: "View all bookmarks" }).should("not.exist");
});
});

context("When an exisiting user visits the page", () => {
beforeEach(() => {
cy.intercept(endpoints.recentItems).as("recentItems");
cy.intercept(endpoints.recentCollections).as("recentCollections");
cy.intercept(endpoints.recentTools).as("recentTools");
cy.intercept(endpoints.yourBookmarks).as("yourBookmarks");
cy.visit("/");
});

it("should show the 'Your recent items' section with items", () => {
cy.wait("@recentItems");
cy.findByRole("heading", {
level: 2,
name: "Your recent items",
}).should("exist");
cy.findByRole("link", { name: "Data cut - links" }).should("exist");
cy.findByRole("link", { name: "Data types on Data Workspace" }).should(
"not.exist"
);
});

it("should show the 'Your recent collections' section with collections", () => {
cy.wait("@recentCollections");
cy.findByRole("heading", {
level: 2,
name: "Your recent collections",
}).should("exist");
cy.findByRole("link", { name: "Create a collection" }).should(
"not.exist"
);
cy.findAllByRole("link", {
name: "Find out more about collections",
}).should("not.exist");
cy.findAllByRole("link", {
name: "Collection a",
}).should("exist");
});

it("should show the 'Your recent tools' section with tools", () => {
cy.wait("@recentTools");
cy.findByRole("heading", {
level: 2,
name: "Your recent tools",
}).should("exist");
cy.findAllByRole("link", { name: "Visit tools" }).should("not.exist");
cy.findAllByRole("link", { name: "Find out more about tools" }).should(
"not.exist"
);
cy.findByRole("link", { name: "Superset" }).should("exist");
});

it("should show the 'Your bookmarks' section with bookmarks", () => {
cy.wait("@yourBookmarks");
cy.findByRole("heading", {
level: 2,
name: "Your bookmarks",
}).should("exist");
cy.findByRole("link", { name: "source dataset a" }).should("exist");
cy.findByRole("link", { name: "View all bookmarks" }).should("exist");
});
});
});
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="cypress" />
import "@testing-library/cypress/add-commands";
import "./setup-cypress-testing-library";
/// <reference types="cypress" />
12 changes: 6 additions & 6 deletions dataworkspace/dataworkspace/apps/datasets/fixtures/datasets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pk": "161d4b68-4b0d-4d96-80dc-d2f9867ff515",
"fields": {
"created_date": "2024-01-12T14:18:19.489Z",
"modified_date": "2024-01-29T10:30:00.090Z",
"modified_date": "2024-02-01T14:30:00.234Z",
"deleted": false,
"created_by": 2,
"updated_by": 2,
Expand Down Expand Up @@ -50,7 +50,7 @@
"pk": "3112a785-6bd9-4e56-bc67-10b6cccb5db7",
"fields": {
"created_date": "2024-01-12T09:24:49.567Z",
"modified_date": "2024-01-29T10:30:00.099Z",
"modified_date": "2024-02-01T14:30:00.238Z",
"deleted": false,
"created_by": 2,
"updated_by": 2,
Expand Down Expand Up @@ -96,7 +96,7 @@
"pk": "406291aa-e35e-41a9-ab05-6355c5cc92d6",
"fields": {
"created_date": "2024-01-12T13:57:10.044Z",
"modified_date": "2024-01-29T10:30:00.064Z",
"modified_date": "2024-02-01T14:30:00.203Z",
"deleted": false,
"created_by": 2,
"updated_by": 2,
Expand Down Expand Up @@ -142,7 +142,7 @@
"pk": "b603337f-0073-43ac-9dc4-05a8d5cf635d",
"fields": {
"created_date": "2024-01-12T14:29:16.808Z",
"modified_date": "2024-01-29T10:30:00.079Z",
"modified_date": "2024-02-01T14:30:00.229Z",
"deleted": false,
"created_by": 2,
"updated_by": 2,
Expand Down Expand Up @@ -188,7 +188,7 @@
"pk": "c9e3eeac-4dd3-4c3d-8350-18ae2064311b",
"fields": {
"created_date": "2024-01-12T14:32:50.390Z",
"modified_date": "2024-01-29T10:30:00.094Z",
"modified_date": "2024-02-01T14:30:00.244Z",
"deleted": false,
"created_by": null,
"updated_by": 2,
Expand Down Expand Up @@ -234,7 +234,7 @@
"pk": "d7094267-ddfc-40f3-a4a8-ca4f30a0992f",
"fields": {
"created_date": "2024-01-12T10:16:35.298Z",
"modified_date": "2024-01-29T10:30:00.086Z",
"modified_date": "2024-02-01T14:30:00.248Z",
"deleted": false,
"created_by": 2,
"updated_by": 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"model": "datasets.datasetbookmark",
"pk": 1,
"fields": {
"user": 2,
"dataset": "3112a785-6bd9-4e56-bc67-10b6cccb5db7",
"created_date": "2024-02-01T15:53:46.379Z"
}
}
]
Loading

0 comments on commit dd7f2c0

Please sign in to comment.