From 884244df4a7f8b4779f388041004ea67caf28622 Mon Sep 17 00:00:00 2001 From: jlnat Date: Thu, 9 Jan 2025 21:14:11 +0100 Subject: [PATCH] Add tests for the Top tasks page --- .../webdriver/baseSpecs/showAllTasks.spec.js | 74 +++++++++++++++++++ .../webdriver/pages/showAllTasks.page.js | 32 ++++++++ 2 files changed, 106 insertions(+) create mode 100644 client/tests/webdriver/baseSpecs/showAllTasks.spec.js create mode 100644 client/tests/webdriver/pages/showAllTasks.page.js diff --git a/client/tests/webdriver/baseSpecs/showAllTasks.spec.js b/client/tests/webdriver/baseSpecs/showAllTasks.spec.js new file mode 100644 index 0000000000..cbebd19eb8 --- /dev/null +++ b/client/tests/webdriver/baseSpecs/showAllTasks.spec.js @@ -0,0 +1,74 @@ +import { expect } from "chai" +import ShowAllTasks from "../pages/showAllTasks.page" + +const FIRST_TASK_NAME = "EF 1: Budget and Planning" +const FIRST_TASK_DESCENDANT_NAME = "1.1: Budgeting in the MoD" +const NO_DESCENDANTS_TASK_NAME = "EF 5: Force Sustainment (Logistics)" + +describe("Show All Tasks Page", () => { + beforeEach(async() => { + await ShowAllTasks.open() + }) + + it("Should display all top tasks", async() => { + const topTasks = await ShowAllTasks.getAllTasks() + expect(topTasks).to.have.lengthOf(16) + for (const task of topTasks) { + const isDisplayed = await task.isDisplayed() + expect(isDisplayed).to.equal(true) + } + }) + + it("Should expand a task to show its descendants", async() => { + const topTasks = await ShowAllTasks.getAllTasks() + const firstTask = topTasks[0] + const firstTaskText = await firstTask.getText() + expect(firstTaskText).to.equal(FIRST_TASK_NAME) + + const caret = await firstTask.$(".bp5-tree-node-caret") + expect(caret).to.not.equal(null) + await caret.click() + + const descendants = await ShowAllTasks.getAllDescendants(firstTask) + expect(descendants).to.have.lengthOf(3) + const firstDescendant = descendants[0] + const firstDescendantText = await firstDescendant.getText() + expect(firstDescendantText).to.equal(FIRST_TASK_DESCENDANT_NAME) + }) + + it("Should collapse a task to hide its descendants", async() => { + const topTasks = await ShowAllTasks.getAllTasks() + const firstTask = topTasks[0] + + const caret = await firstTask.$(".bp5-tree-node-caret") + expect(caret).to.not.equal(null) + await caret.click() + const descendants = await ShowAllTasks.getAllDescendants(firstTask) + expect(descendants).to.have.lengthOf(3) + + await caret.click() + const collapsedDescendants = await ShowAllTasks.getAllDescendants( + firstTask, + true + ) + expect(collapsedDescendants).to.have.lengthOf(0) + }) + + it("Should not show a caret for tasks without descendants", async() => { + const topTasks = await ShowAllTasks.getAllTasks() + const noDescendantsTask = topTasks[4] + + const noDescendantsTaskText = await noDescendantsTask.getText() + expect(noDescendantsTaskText).to.equal(NO_DESCENDANTS_TASK_NAME) + + const caret = await noDescendantsTask.$(".bp5-tree-node-caret") + const caretExists = await caret.isExisting() + expect(caretExists).to.equal(false) + + const descendants = await ShowAllTasks.getAllDescendants(noDescendantsTask) + expect(descendants).to.have.lengthOf( + 0, + "No descendants should be present for EF 5" + ) + }) +}) diff --git a/client/tests/webdriver/pages/showAllTasks.page.js b/client/tests/webdriver/pages/showAllTasks.page.js new file mode 100644 index 0000000000..39923db61f --- /dev/null +++ b/client/tests/webdriver/pages/showAllTasks.page.js @@ -0,0 +1,32 @@ +import Page from "./page" + +const PAGE_URL = "/top-tasks" +const TIMEOUT = 5000 + +class ShowAllTasks extends Page { + async open() { + await super.open(PAGE_URL) + } + + async getAllTasks() { + await browser.pause(TIMEOUT) + return await browser.$$(".bp5-tree-node") + } + + async getAllDescendants(task, filterVisible = false) { + await browser.pause(TIMEOUT) + const descendants = await task.$$(".bp5-tree-node-list .bp5-tree-node") + if (!filterVisible) { + return descendants + } + const visibleDescendants = [] + for (const descendant of descendants) { + if (await descendant.isDisplayed()) { + visibleDescendants.push(descendant) + } + } + return visibleDescendants + } +} + +export default new ShowAllTasks()