Skip to content

Commit

Permalink
Add tests for the Top tasks page
Browse files Browse the repository at this point in the history
  • Loading branch information
jlnat committed Jan 9, 2025
1 parent fdc4964 commit 884244d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
74 changes: 74 additions & 0 deletions client/tests/webdriver/baseSpecs/showAllTasks.spec.js
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
32 changes: 32 additions & 0 deletions client/tests/webdriver/pages/showAllTasks.page.js
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 884244d

Please sign in to comment.