Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor all fixtures into boxed steps #801

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stupid-jars-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/e2e': minor
---

Refactored all fixtures into boxed steps.
108 changes: 56 additions & 52 deletions apps/hostd-e2e/src/fixtures/configResetAllSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,74 @@ import {
clearToasts,
fillTextInputByName,
fillSelectInputByName,
step,
} from '@siafoundation/e2e'
import { navigateToConfig } from './navigate'

export async function configResetAllSettings({ page }: { page: Page }) {
await navigateToConfig({ page })
await setViewMode({ page, state: 'advanced' })
export const configResetAllSettings = step(
'config reset all settings',
async ({ page }: { page: Page }) => {
await navigateToConfig({ page })
await setViewMode({ page, state: 'advanced' })

// host
await setSwitchByLabel(page, 'acceptingContracts', false)
await fillTextInputByName(page, 'netAddress', 'foobar.com:9880')
await fillTextInputByName(page, 'maxContractDuration', '6')
// host
await setSwitchByLabel(page, 'acceptingContracts', false)
await fillTextInputByName(page, 'netAddress', 'foobar.com:9880')
await fillTextInputByName(page, 'maxContractDuration', '6')

// pricing
await fillSelectInputByName(page, 'pinnedCurrency', 'USD')
await fillTextInputByName(page, 'pinnedThreshold', '3')
// pricing
await fillSelectInputByName(page, 'pinnedCurrency', 'USD')
await fillTextInputByName(page, 'pinnedThreshold', '3')

await setSwitchByLabel(page, 'shouldPinStoragePrice', false)
await fillTextInputByName(page, 'storagePrice', '10')
await setSwitchByLabel(page, 'shouldPinStoragePrice', true)
await fillTextInputByName(page, 'storagePricePinned', '5')
await setSwitchByLabel(page, 'shouldPinStoragePrice', false)
await setSwitchByLabel(page, 'shouldPinStoragePrice', false)
await fillTextInputByName(page, 'storagePrice', '10')
await setSwitchByLabel(page, 'shouldPinStoragePrice', true)
await fillTextInputByName(page, 'storagePricePinned', '5')
await setSwitchByLabel(page, 'shouldPinStoragePrice', false)

await setSwitchByLabel(page, 'shouldPinEgressPrice', false)
await fillTextInputByName(page, 'egressPrice', '10')
await setSwitchByLabel(page, 'shouldPinEgressPrice', true)
await fillTextInputByName(page, 'egressPricePinned', '5')
await setSwitchByLabel(page, 'shouldPinEgressPrice', false)
await setSwitchByLabel(page, 'shouldPinEgressPrice', false)
await fillTextInputByName(page, 'egressPrice', '10')
await setSwitchByLabel(page, 'shouldPinEgressPrice', true)
await fillTextInputByName(page, 'egressPricePinned', '5')
await setSwitchByLabel(page, 'shouldPinEgressPrice', false)

await setSwitchByLabel(page, 'shouldPinIngressPrice', false)
await fillTextInputByName(page, 'ingressPrice', '10')
await setSwitchByLabel(page, 'shouldPinIngressPrice', true)
await fillTextInputByName(page, 'ingressPricePinned', '5')
await setSwitchByLabel(page, 'shouldPinIngressPrice', false)
await setSwitchByLabel(page, 'shouldPinIngressPrice', false)
await fillTextInputByName(page, 'ingressPrice', '10')
await setSwitchByLabel(page, 'shouldPinIngressPrice', true)
await fillTextInputByName(page, 'ingressPricePinned', '5')
await setSwitchByLabel(page, 'shouldPinIngressPrice', false)

await fillTextInputByName(page, 'collateralMultiplier', '2')
await fillTextInputByName(page, 'collateralMultiplier', '2')

await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
await fillTextInputByName(page, 'maxCollateral', '10')
await setSwitchByLabel(page, 'shouldPinMaxCollateral', true)
await fillTextInputByName(page, 'maxCollateralPinned', '5')
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)
await fillTextInputByName(page, 'maxCollateral', '10')
await setSwitchByLabel(page, 'shouldPinMaxCollateral', true)
await fillTextInputByName(page, 'maxCollateralPinned', '5')
await setSwitchByLabel(page, 'shouldPinMaxCollateral', false)

await fillTextInputByName(page, 'contractPrice', '0.2')
await fillTextInputByName(page, 'baseRPCPrice', '1')
await fillTextInputByName(page, 'sectorAccessPrice', '1')
await fillTextInputByName(page, 'priceTableValidity', '30')
await fillTextInputByName(page, 'contractPrice', '0.2')
await fillTextInputByName(page, 'baseRPCPrice', '1')
await fillTextInputByName(page, 'sectorAccessPrice', '1')
await fillTextInputByName(page, 'priceTableValidity', '30')

// accounts
await fillTextInputByName(page, 'accountExpiry', '30')
await fillTextInputByName(page, 'maxAccountBalance', '10')
// accounts
await fillTextInputByName(page, 'accountExpiry', '30')
await fillTextInputByName(page, 'maxAccountBalance', '10')

// bandwidth
await fillTextInputByName(page, 'ingressLimit', '0')
await fillTextInputByName(page, 'egressLimit', '0')
// bandwidth
await fillTextInputByName(page, 'ingressLimit', '0')
await fillTextInputByName(page, 'egressLimit', '0')

// DNS
await fillSelectInputByName(page, 'dnsProvider', '')
// DNS
await fillSelectInputByName(page, 'dnsProvider', '')

// save
await clickIfEnabledAndWait(
page.getByText('Save changes'),
page.getByText('Settings have been saved')
)
await clearToasts({ page })
await setViewMode({ page, state: 'basic' })
await navigateToConfig({ page })
}
// save
await clickIfEnabledAndWait(
page.getByText('Save changes'),
page.getByText('Settings have been saved')
)
await clearToasts({ page })
await setViewMode({ page, state: 'basic' })
await navigateToConfig({ page })
}
)
41 changes: 22 additions & 19 deletions apps/hostd-e2e/src/fixtures/login.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { Page, expect } from '@playwright/test'
import { fillTextInputByName } from '@siafoundation/e2e'
import { fillTextInputByName, step } from '@siafoundation/e2e'

export async function login({
page,
address,
password,
}: {
page: Page
address: string
password: string
}) {
await page.goto('/login')
await expect(page).toHaveTitle('hostd')
await page.getByLabel('login settings').click()
await page.getByRole('menuitem', { name: 'Show custom API' }).click()
await fillTextInputByName(page, 'api', address)
await fillTextInputByName(page, 'password', password)
await page.locator('input[name=password]').press('Enter')
await expect(page.getByTestId('navbar').getByText('Overview')).toBeVisible()
}
export const login = step(
'login',
async ({
page,
address,
password,
}: {
page: Page
address: string
password: string
}) => {
await page.goto('/login')
await expect(page).toHaveTitle('hostd')
await page.getByLabel('login settings').click()
await page.getByRole('menuitem', { name: 'Show custom API' }).click()
await fillTextInputByName(page, 'api', address)
await fillTextInputByName(page, 'password', password)
await page.locator('input[name=password]').press('Enter')
await expect(page.getByTestId('navbar').getByText('Overview')).toBeVisible()
}
)
49 changes: 31 additions & 18 deletions apps/hostd-e2e/src/fixtures/navigate.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import { Page, expect } from '@playwright/test'
import { step } from '@siafoundation/e2e'

export async function navigateToDashboard({ page }: { page: Page }) {
await page.getByTestId('sidenav').getByLabel('Overview').click()
await expect(page.getByTestId('navbar').getByText('Overview')).toBeVisible()
}
export const navigateToDashboard = step(
'navigate to dashboard',
async ({ page }: { page: Page }) => {
await page.getByTestId('sidenav').getByLabel('Overview').click()
await expect(page.getByTestId('navbar').getByText('Overview')).toBeVisible()
}
)

export async function navigateToConfig({ page }: { page: Page }) {
await page.getByTestId('sidenav').getByLabel('Configuration').click()
await expect(
page.getByTestId('navbar').getByText('Configuration')
).toBeVisible()
}
export const navigateToConfig = step(
'navigate to config',
async ({ page }: { page: Page }) => {
await page.getByTestId('sidenav').getByLabel('Configuration').click()
await expect(
page.getByTestId('navbar').getByText('Configuration')
).toBeVisible()
}
)

export async function navigateToVolumes({ page }: { page: Page }) {
await page.getByTestId('sidenav').getByLabel('Volumes').click()
await expect(page.getByTestId('navbar').getByText('Volumes')).toBeVisible()
}
export const navigateToVolumes = step(
'navigate to volumes',
async ({ page }: { page: Page }) => {
await page.getByTestId('sidenav').getByLabel('Volumes').click()
await expect(page.getByTestId('navbar').getByText('Volumes')).toBeVisible()
}
)

export async function navigateToWallet(page: Page) {
await page.getByTestId('sidenav').getByLabel('Wallet').click()
await expect(page.getByTestId('navbar').getByText('Wallet')).toBeVisible()
}
export const navigateToWallet = step(
'navigate to wallet',
async (page: Page) => {
await page.getByTestId('sidenav').getByLabel('Wallet').click()
await expect(page.getByTestId('navbar').getByText('Wallet')).toBeVisible()
}
)
131 changes: 73 additions & 58 deletions apps/hostd-e2e/src/fixtures/volumes.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,82 @@
import { Page, expect } from '@playwright/test'
import { navigateToVolumes } from './navigate'
import { fillTextInputByName } from '@siafoundation/e2e'
import { fillTextInputByName, step } from '@siafoundation/e2e'

export async function createVolume(page: Page, name: string, path: string) {
const fullPath = `${path}/${name}`
await navigateToVolumes({ page })
await page.getByText('Create volume').click()
await fillTextInputByName(page, 'name', name)
await fillTextInputByName(page, 'immediatePath', path)
// immediatePath updates path after 500ms
// eslint-disable-next-line playwright/no-wait-for-timeout
await page.waitForTimeout(1000)
await fillTextInputByName(page, 'size', '11')
await expect(
page.getByRole('dialog').getByText('Must be between 10.00 GB')
).toBeHidden()
await page.locator('input[name=size]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
const row = page.getByRole('row', { name: fullPath })
await expect(page.getByText('Volume created')).toBeVisible()
await expect(row.getByText('ready')).toBeVisible()
await expect(page.getByRole('cell', { name: fullPath })).toBeVisible()
}
export const createVolume = step(
'create volume',
async (page: Page, name: string, path: string) => {
const fullPath = `${path}/${name}`
await navigateToVolumes({ page })
await page.getByText('Create volume').click()
await fillTextInputByName(page, 'name', name)
await fillTextInputByName(page, 'immediatePath', path)
// immediatePath updates path after 500ms
// eslint-disable-next-line playwright/no-wait-for-timeout
await page.waitForTimeout(1000)
await fillTextInputByName(page, 'size', '11')
await expect(
page.getByRole('dialog').getByText('Must be between 10.00 GB')
).toBeHidden()
await page.locator('input[name=size]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
const row = page.getByRole('row', { name: fullPath })
await expect(page.getByText('Volume created')).toBeVisible()
await expect(row.getByText('ready')).toBeVisible()
await expect(page.getByRole('cell', { name: fullPath })).toBeVisible()
}
)

export async function deleteVolume(page: Page, name: string, path: string) {
const fullPath = `${path}/${name}`
await openVolumeContextMenu(page, fullPath)
const menuDelete = page.getByRole('menuitem', { name: 'Delete' })
await menuDelete.click({ timeout: 10_000 })
await fillTextInputByName(page, 'path', fullPath)
await page.locator('input[name=path]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
await expect(
page.getByText('Volume is now being permanently deleted')
).toBeVisible()
await volumeNotInList(page, fullPath)
}
export const deleteVolume = step(
'delete volume',
async (page: Page, name: string, path: string) => {
const fullPath = `${path}/${name}`
await openVolumeContextMenu(page, fullPath)
const menuDelete = page.getByRole('menuitem', { name: 'Delete' })
await menuDelete.click({ timeout: 10_000 })
await fillTextInputByName(page, 'path', fullPath)
await page.locator('input[name=path]').press('Enter')
await expect(page.getByRole('dialog')).toBeHidden()
await expect(
page.getByText('Volume is now being permanently deleted')
).toBeVisible()
await volumeNotInList(page, fullPath)
}
)

export async function deleteVolumeIfExists(
page: Page,
name: string,
path: string
) {
const doesVolumeExist = await page
.getByRole('table')
.getByText(path + '/' + name)
.isVisible()
if (doesVolumeExist) {
await deleteVolume(page, name, path)
export const deleteVolumeIfExists = step(
'delete volume if exists',
async (page: Page, name: string, path: string) => {
const doesVolumeExist = await page
.getByRole('table')
.getByText(path + '/' + name)
.isVisible()
if (doesVolumeExist) {
await deleteVolume(page, name, path)
}
}
}
)

export async function openVolumeContextMenu(page: Page, name: string) {
await page
.getByRole('row', { name })
.getByLabel('volume context menu')
.click()
}
export const openVolumeContextMenu = step(
'open volume context menu',
async (page: Page, name: string) => {
const menu = page
.getByRole('row', { name })
.getByLabel('volume context menu')
await expect(menu).toBeVisible()
await menu.click()
}
)

export async function volumeInList(page: Page, name: string) {
await expect(page.getByRole('table').getByText(name)).toBeVisible()
}
export const volumeInList = step(
'volume in list',
async (page: Page, name: string) => {
await expect(page.getByRole('table').getByText(name)).toBeVisible()
}
)

export async function volumeNotInList(page: Page, name: string) {
await expect(page.getByRole('table').getByText(name)).toBeHidden()
}
export const volumeNotInList = step(
'volume not in list',
async (page: Page, name: string) => {
await expect(page.getByRole('table').getByText(name)).toBeHidden()
}
)
Loading
Loading