|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { TREE_LISTING_SELECTORS, COMMON_SELECTORS } from './e2e-selectors'; |
| 4 | + |
| 5 | +const PAGE_LOAD_TIMEOUT = 5000; |
| 6 | +const DEFAULT_ACTION_TIMEOUT = 1000; |
| 7 | +const SEARCH_UPDATE_TIMEOUT = 2000; |
| 8 | +const NAVIGATION_TIMEOUT = 5000; |
| 9 | +const GO_BACK_TIMEOUT = 3000; |
| 10 | + |
| 11 | +test.describe('Tree Listing Page Tests', () => { |
| 12 | + test.beforeEach(async ({ page }) => { |
| 13 | + await page.goto('/tree'); |
| 14 | + await page.waitForTimeout(PAGE_LOAD_TIMEOUT); |
| 15 | + }); |
| 16 | + |
| 17 | + test('loads tree listing page correctly', async ({ page }) => { |
| 18 | + await expect(page).toHaveTitle(/KernelCI/); |
| 19 | + await expect(page).toHaveURL(/\/tree/); |
| 20 | + |
| 21 | + await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); |
| 22 | + |
| 23 | + await expect( |
| 24 | + page.locator(TREE_LISTING_SELECTORS.treeColumnHeader), |
| 25 | + ).toBeVisible(); |
| 26 | + await expect( |
| 27 | + page.locator(TREE_LISTING_SELECTORS.branchColumnHeader), |
| 28 | + ).toBeVisible(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('change time interval', async ({ page }) => { |
| 32 | + await expect(page.locator(COMMON_SELECTORS.tableRow).first()).toBeVisible(); |
| 33 | + |
| 34 | + const intervalInput = page |
| 35 | + .locator(TREE_LISTING_SELECTORS.intervalInput) |
| 36 | + .first(); |
| 37 | + await expect(intervalInput).toBeVisible(); |
| 38 | + |
| 39 | + await intervalInput.fill('14'); |
| 40 | + |
| 41 | + await page.waitForTimeout(DEFAULT_ACTION_TIMEOUT); |
| 42 | + |
| 43 | + await expect(intervalInput).toHaveValue('14'); |
| 44 | + }); |
| 45 | + |
| 46 | + test('change table size', async ({ page }) => { |
| 47 | + await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); |
| 48 | + |
| 49 | + const tableSizeSelector = page.locator('[role="combobox"]').nth(1); |
| 50 | + await expect(tableSizeSelector).toBeVisible(); |
| 51 | + |
| 52 | + await tableSizeSelector.click(); |
| 53 | + |
| 54 | + await expect( |
| 55 | + page.locator(TREE_LISTING_SELECTORS.itemsPerPageDropdown), |
| 56 | + ).toBeVisible(); |
| 57 | + |
| 58 | + await page.locator(TREE_LISTING_SELECTORS.itemsPerPageOption('20')).click(); |
| 59 | + |
| 60 | + await page.waitForTimeout(DEFAULT_ACTION_TIMEOUT); |
| 61 | + |
| 62 | + await expect(tableSizeSelector).toContainText('20'); |
| 63 | + }); |
| 64 | + |
| 65 | + test('search for trees', async ({ page }) => { |
| 66 | + const searchInput = page.locator(TREE_LISTING_SELECTORS.searchInput).nth(0); |
| 67 | + await expect(searchInput).toBeVisible(); |
| 68 | + await searchInput.fill('main'); |
| 69 | + |
| 70 | + await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); |
| 71 | + |
| 72 | + const tableRows = page.locator(COMMON_SELECTORS.tableRow); |
| 73 | + const count = await tableRows.count(); |
| 74 | + expect(count).toBeGreaterThan(1); |
| 75 | + }); |
| 76 | + |
| 77 | + test('navigate to tree details and back via breadcrumb', async ({ page }) => { |
| 78 | + await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); |
| 79 | + |
| 80 | + const firstTreeLink = page.locator('td a').first(); |
| 81 | + await expect(firstTreeLink).toBeVisible(); |
| 82 | + |
| 83 | + await firstTreeLink.click(); |
| 84 | + |
| 85 | + await page.waitForTimeout(NAVIGATION_TIMEOUT); |
| 86 | + |
| 87 | + const url = page.url(); |
| 88 | + expect(url).toMatch(/\/tree\/[^/]+\/[^/]+\/[^/]+$/); |
| 89 | + |
| 90 | + const breadcrumbLink = page.locator( |
| 91 | + TREE_LISTING_SELECTORS.breadcrumbTreesLink, |
| 92 | + ); |
| 93 | + await expect(breadcrumbLink).toBeVisible({ timeout: 15000 }); |
| 94 | + await breadcrumbLink.click(); |
| 95 | + await page.waitForTimeout(GO_BACK_TIMEOUT); |
| 96 | + |
| 97 | + await expect(page).toHaveURL(/\/tree$/); |
| 98 | + }); |
| 99 | + |
| 100 | + test('pagination navigation', async ({ page }) => { |
| 101 | + await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); |
| 102 | + |
| 103 | + const nextPageButton = page |
| 104 | + .locator(TREE_LISTING_SELECTORS.nextPageButton) |
| 105 | + .first(); |
| 106 | + const hasNextPage = |
| 107 | + (await nextPageButton.count()) > 0 && |
| 108 | + !(await nextPageButton.isDisabled()); |
| 109 | + |
| 110 | + if (hasNextPage) { |
| 111 | + const originalPageUrl = page.url(); |
| 112 | + await nextPageButton.click(); |
| 113 | + |
| 114 | + await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); |
| 115 | + |
| 116 | + const newPageUrl = page.url(); |
| 117 | + expect(newPageUrl).not.toBe(originalPageUrl); |
| 118 | + } |
| 119 | + }); |
| 120 | + |
| 121 | + test('change origin', async ({ page }) => { |
| 122 | + const testOrigin = 'linaro'; |
| 123 | + |
| 124 | + await expect(page.locator(TREE_LISTING_SELECTORS.table)).toBeVisible(); |
| 125 | + |
| 126 | + await expect(page.locator('text="Origin"')).toBeVisible(); |
| 127 | + |
| 128 | + const originDropdown = page.locator(COMMON_SELECTORS.originDropdown); |
| 129 | + await expect(originDropdown).toBeVisible({ timeout: 15000 }); |
| 130 | + |
| 131 | + await originDropdown.click(); |
| 132 | + |
| 133 | + await expect( |
| 134 | + page.locator(COMMON_SELECTORS.originOption(testOrigin)), |
| 135 | + ).toBeVisible(); |
| 136 | + |
| 137 | + await page.locator(COMMON_SELECTORS.originOption(testOrigin)).click(); |
| 138 | + |
| 139 | + await page.waitForTimeout(SEARCH_UPDATE_TIMEOUT); |
| 140 | + |
| 141 | + await expect(originDropdown).toContainText(testOrigin); |
| 142 | + }); |
| 143 | +}); |
0 commit comments