-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(renterd): files and uploads pagination
- Loading branch information
1 parent
5a8824d
commit 853b556
Showing
11 changed files
with
424 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { test, expect, Page } from '@playwright/test' | ||
import { navigateToContracts } from '../fixtures/navigate' | ||
import { afterTest, beforeTest } from '../fixtures/beforeTest' | ||
import { getContractRowByIndex, getContractRows } from '../fixtures/contracts' | ||
import { ContractsResponse, contractsRoute } from '@siafoundation/hostd-types' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await beforeTest(page, { | ||
renterdCount: 3, | ||
}) | ||
}) | ||
|
||
test.afterEach(async () => { | ||
await afterTest() | ||
}) | ||
|
||
test('viewing a page with no data shows the correct empty state', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/contracts?offset=100') | ||
// Check that the empty state is correct. | ||
await expect( | ||
page.getByText('No data on this page, reset pagination to continue.') | ||
).toBeVisible() | ||
await expect(page.getByText('Back to first page')).toBeVisible() | ||
await page.getByText('Back to first page').click() | ||
// Ensure we are now seeing rows of data. | ||
await getContractRowByIndex(page, 0, true) | ||
}) | ||
|
||
test('paginating contracts with known total and client side pagination', async ({ | ||
page, | ||
}) => { | ||
await interceptApiContactsAndEnsure3Results(page) | ||
await navigateToContracts(page) | ||
const url = page.url() | ||
await page.goto(url + '?limit=1') | ||
|
||
const first = page.getByRole('button', { name: 'go to first page' }) | ||
const previous = page.getByRole('button', { name: 'go to previous page' }) | ||
const next = page.getByRole('button', { name: 'go to next page' }) | ||
const last = page.getByRole('button', { name: 'go to last page' }) | ||
const rows = getContractRows(page) | ||
await expect(rows).toHaveCount(1) | ||
await expect(first).toBeDisabled() | ||
await expect(previous).toBeDisabled() | ||
await expect(next).toBeEnabled() | ||
await expect(last).toBeEnabled() | ||
await next.click() | ||
await expect(rows).toHaveCount(1) | ||
await expect(first).toBeEnabled() | ||
await expect(previous).toBeEnabled() | ||
await expect(next).toBeEnabled() | ||
await expect(last).toBeEnabled() | ||
await next.click() | ||
await expect(rows).toHaveCount(1) | ||
await expect(first).toBeEnabled() | ||
await expect(previous).toBeEnabled() | ||
await expect(next).toBeDisabled() | ||
await expect(last).toBeDisabled() | ||
}) | ||
|
||
async function interceptApiContactsAndEnsure3Results(page: Page) { | ||
await page.route(`**/api${contractsRoute}*`, async (route) => { | ||
console.log('Intercepted contracts API request') | ||
// Fetch the original response. | ||
const response = await route.fetch() | ||
|
||
// Parse the response body as JSON. | ||
const originalData: ContractsResponse = await response.json() | ||
|
||
// Slice the contracts down to exactly 3 items. | ||
const modifiedData: ContractsResponse = { | ||
contracts: originalData.contracts.slice(0, 3), | ||
count: Math.min(3, originalData.count), | ||
} | ||
|
||
// Fulfill the route with the modified response. | ||
await route.fulfill({ | ||
json: modifiedData, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Page, expect } from '@playwright/test' | ||
import { maybeExpectAndReturn, step } from '@siafoundation/e2e' | ||
|
||
export const uploadInList = step( | ||
'expect upload in list', | ||
async (page: Page, id: string, timeout?: number) => { | ||
await expect(page.getByTestId('uploadsTable').getByTestId(id)).toBeVisible({ | ||
timeout, | ||
}) | ||
} | ||
) | ||
|
||
export const uploadNotInList = step( | ||
'expect upload not in list', | ||
async (page: Page, id: string) => { | ||
await expect(page.getByTestId('uploadsTable').getByTestId(id)).toBeHidden() | ||
} | ||
) | ||
|
||
export const getUploadRowById = step( | ||
'get upload row by ID', | ||
async (page: Page, id: string, shouldExpect?: boolean) => { | ||
return maybeExpectAndReturn( | ||
page.getByTestId('uploadsTable').getByTestId(id), | ||
shouldExpect | ||
) | ||
} | ||
) | ||
|
||
export const expectUploadRowById = step( | ||
'expect upload row by ID', | ||
async (page: Page, id: string) => { | ||
return expect( | ||
page.getByTestId('uploadsTable').getByTestId(id) | ||
).toBeVisible() | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.