Skip to content

Commit

Permalink
Migrated other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flurdy committed Dec 5, 2024
1 parent 49fdd03 commit 1c4d2f3
Show file tree
Hide file tree
Showing 36 changed files with 2,139 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/components/banner.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { $ } from '@wdio/globals'

/** appBanner component */
class BannerComponent {
content(content) {
return $('[data-testid="app-banner-content"]*=' + content)
}
}

export default new BannerComponent()
14 changes: 14 additions & 0 deletions test/components/entity-list.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { $ } from '@wdio/globals'

/** appEntityList component */
class EntityListComponent {
content(content) {
return $('[data-testid="app-entity-list"]*=' + content)
}

entityLink(content) {
return $('[data-testid="app-entity-link"]*=' + content)
}
}

export default new EntityListComponent()
24 changes: 24 additions & 0 deletions test/components/form.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { $ } from '@wdio/globals'

/**
* Form helper component
*/
class FormComponent {
form() {
return $('form')
}

legend(content) {
return $('legend*=' + content)
}

inputLabel(content) {
return $('label*=' + content)
}

submitButton(content) {
return $('button*=' + content)
}
}

export default new FormComponent()
16 changes: 16 additions & 0 deletions test/components/govuk-summary-list.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { $ } from '@wdio/globals'

/**
* govukSummaryList helper component
*/
class GovukSummaryListComponent {
content() {
return $('[data-testid="govuk-summary-list"]')
}

row(testId) {
return $(`[data-testid="govuk-summary-list"] [data-testid="${testId}"]`)
}
}

export default new GovukSummaryListComponent()
20 changes: 20 additions & 0 deletions test/components/heading.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { $ } from '@wdio/globals'

/** @deprecated appHeading component */
class HeadingComponent {
banner(content) {
return $('[data-testid="app-banner-content"]*=' + content)
}

title(content) {
return $('[data-testid="app-heading-title"]*=' + content)
}

caption(content) {
return $(
'[data-testid="app-heading-caption"]' + (content ? '*=' + content : '')
)
}
}

export default new HeadingComponent()
17 changes: 17 additions & 0 deletions test/components/link.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { $ } from '@wdio/globals'

/**
* Link helper component
*/
class LinkComponent {
/**
* @param {string }testId
* @param {string }content
* @returns {*}
*/
link(testId, content) {
return $(`a[data-testid="${testId}"]*=` + content)
}
}

export default new LinkComponent()
21 changes: 21 additions & 0 deletions test/components/page-heading.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { $ } from '@wdio/globals'

/** appPageHeading component */
class PageHeadingComponent {
title(content) {
return $('[data-testid="app-page-heading-title"]*=' + content)
}

caption(content) {
return $(
'[data-testid="app-page-heading-caption"]' +
(content ? '*=' + content : '')
)
}

cta(content) {
return $('[data-testid="app-page-heading-cta"]*=' + content)
}
}

export default new PageHeadingComponent()
25 changes: 25 additions & 0 deletions test/components/split-pane.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { $ } from '@wdio/globals'

/** appSplitPane component */
class SplitPaneComponent {
content() {
return $('[data-testid="app-split-pane"]')
}

subNavItem(navItemName) {
return $(`[data-testid="app-subnav-item-${navItemName}"]`)
}

subNavItemLink(navItemName) {
return $(`[data-testid="app-subnav-link-${navItemName}"]`)
}

async subNavIsActive(navItemName) {
const subNavItemElem = await this.subNavItem(navItemName)
const className = await subNavItemElem.getAttribute('class')

return className.includes('app-subnav__section-item--current')
}
}

export default new SplitPaneComponent()
14 changes: 14 additions & 0 deletions test/components/tabs.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { $ } from '@wdio/globals'

/** appTabs component */
class TabsComponent {
activeTab() {
return $('[data-testid*="app-tabs-list-item--selected"]')
}

secondTab() {
return $('[data-testid="app-tabs-list-item-2"]')
}
}

export default new TabsComponent()
47 changes: 47 additions & 0 deletions test/helpers/create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { browser } from '@wdio/globals'

import AdminPage from 'page-objects/admin.page'
import FormComponent from 'components/form.component'
import LinkComponent from 'components/link.component'
import LoginStubPage from 'page-objects/login-stub.page'

async function createUser(searchTerm) {
await LoginStubPage.loginAsAdmin()

await AdminPage.open('/users/create')

// AAD user
await FormComponent.inputLabel('AAD users name or email').click()
await browser.keys(searchTerm)
await FormComponent.inputLabel(searchTerm).click()
await FormComponent.submitButton('Next').click()

// GitHub user
await FormComponent.inputLabel('GitHub username').click()
await browser.keys(searchTerm)
await FormComponent.inputLabel(searchTerm).click()
await FormComponent.submitButton('Next').click()

// Skip user details
await FormComponent.submitButton('Skip').click()

// Create
await FormComponent.submitButton('Create').click()

await LoginStubPage.logOut()
}

async function deleteUser(username) {
await LoginStubPage.loginAsAdmin()

await AdminPage.open('/users')

// Go to users page, then delete confirm page, then press delete
await LinkComponent.link('app-entity-link', username).click()
await LinkComponent.link('admin-delete-user', 'Delete user').click()
await FormComponent.submitButton('Delete user').click()

await LoginStubPage.logOut()
}

export { createUser, deleteUser }
31 changes: 31 additions & 0 deletions test/page-objects/admin-team.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Page } from 'page-objects/page'
import SplitPaneComponent from 'components/split-pane.component'
import { $ } from '@wdio/globals'

class AdminTeamPage extends Page {
/**
* Check if the user sub nav link is active
* @returns {Promise<boolean>}
*/
async subNavIsActive() {
return await SplitPaneComponent.subNavIsActive('teams')
}

teamMembers() {
return $('[data-testid="admin-team-members"]')
}

removeButton(name) {
const listItem = $$('[data-testid="admin-team-members"] li').find(
async (li) => {
const textContent = await li.getText()

return textContent.includes(name)
}
)

return listItem.$('a[data-testid="app-link"]*=Remove')
}
}

export default new AdminTeamPage()
18 changes: 18 additions & 0 deletions test/page-objects/admin-teams.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Page } from 'page-objects/page'
import SplitPaneComponent from 'components/split-pane.component'

class AdminTeamsPage extends Page {
/**
* Check if the user sub nav link is active
* @returns {Promise<boolean>}
*/
async subNavIsActive() {
return await SplitPaneComponent.subNavIsActive('teams')
}

open() {
return super.open('/admin/teams')
}
}

export default new AdminTeamsPage()
17 changes: 17 additions & 0 deletions test/page-objects/admin.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page } from 'page-objects/page'

class AdminPage extends Page {
/**
* Check if the admin nav link is active
* @returns {Promise<boolean>}
*/
navIsActive() {
return super.navIsActive('admin')
}

open(value = '') {
return super.open('/admin' + value)
}
}

export default new AdminPage()
17 changes: 17 additions & 0 deletions test/page-objects/create.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page } from 'page-objects/page'

class CreatePage extends Page {
/**
* Check if the create nav link is active
* @returns {Promise<boolean>}
*/
navIsActive() {
return super.navIsActive('create')
}

open() {
return super.open('/create')
}
}

export default new CreatePage()
17 changes: 17 additions & 0 deletions test/page-objects/deploy.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page } from 'page-objects/page'

class DeployPage extends Page {
/**
* Check if the deploy service nav link is active
* @returns {Promise<boolean>}
*/
navIsActive() {
return super.navIsActive('deploy-service')
}

open() {
return super.open('/deploy-service')
}
}

export default new DeployPage()
17 changes: 17 additions & 0 deletions test/page-objects/deployments.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page } from 'page-objects/page'

class DeploymentsPage extends Page {
/**
* Check if the deployments nav link is active
* @returns {Promise<boolean>}
*/
navIsActive() {
return super.navIsActive('deployments')
}

open() {
return super.open('/deployments')
}
}

export default new DeploymentsPage()
16 changes: 16 additions & 0 deletions test/page-objects/error.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { $ } from '@wdio/globals'

import { Page } from 'page-objects/page'
import HeadingComponent from 'components/heading.component'

class ErrorPage extends Page {
title(content) {
return HeadingComponent.title(content)
}

message() {
return $('[data-testid="error-message"]')
}
}

export default new ErrorPage()
30 changes: 30 additions & 0 deletions test/page-objects/login-stub.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Page } from 'page-objects/page'
import { $, browser, expect } from '@wdio/globals'

class LoginStubPage extends Page {
adminUserLink() {
return $('a[id="admin"]*=' + 'Admin User')
}

nonAdminUserLink() {
return $('a[id="nonAdmin"]*=' + 'Non-Admin User')
}

async loginAsAdmin() {
await super.login()
await this.onLoginStubsPage()
return await this.adminUserLink().click()
}

async loginAsNonAdmin() {
await super.login()
await this.onLoginStubsPage()
return await this.nonAdminUserLink().click()
}

onLoginStubsPage() {
return expect(browser).toHaveTitle('CDP-Portal-Stubs - Login Stub')
}
}

export default new LoginStubPage()
Loading

0 comments on commit 1c4d2f3

Please sign in to comment.