|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { addBrowserSuffixToText } from "../utils/helpers"; |
| 3 | +import { loginAsServerAdmin } from "../utils/authenticate"; |
| 4 | +import { PlaywrightConnectionConfigurationsPage } from "./models/playwright-connection-configurations-page"; |
| 5 | + |
| 6 | +const searchName = "000-testgetall-connection-configuration"; |
| 7 | +const institutionModelId = 11; |
| 8 | + |
| 9 | +function getConnectionConfigurationIdsForBrowser(browserName: string) { |
| 10 | + switch (browserName) { |
| 11 | + case "chromium": |
| 12 | + return { activeId: 1001, inactiveId: 1002 }; |
| 13 | + case "firefox": |
| 14 | + return { activeId: 1003, inactiveId: 1004 }; |
| 15 | + case "webkit": |
| 16 | + return { activeId: 1005, inactiveId: 1006 }; |
| 17 | + default: |
| 18 | + throw new Error(`Unsupported browser: ${browserName}`); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +test.describe("4.2.1 Connection Configurations - READ Get All", () => { |
| 23 | + let connectionConfigurationsPage: PlaywrightConnectionConfigurationsPage; |
| 24 | + |
| 25 | + test.beforeEach(async ({ page }) => { |
| 26 | + await loginAsServerAdmin(page); |
| 27 | + connectionConfigurationsPage = |
| 28 | + new PlaywrightConnectionConfigurationsPage(page); |
| 29 | + await connectionConfigurationsPage.goto(); |
| 30 | + await connectionConfigurationsPage.expectVisible(); |
| 31 | + }); |
| 32 | + |
| 33 | + test("A Success", async ({ page, browserName }, testInfo) => { |
| 34 | + expect(page.url()).toContain("/connection-configurations"); |
| 35 | + |
| 36 | + const nameWithBrowserSuffix = addBrowserSuffixToText( |
| 37 | + searchName, |
| 38 | + testInfo, |
| 39 | + ); |
| 40 | + |
| 41 | + const { activeId, inactiveId } = |
| 42 | + getConnectionConfigurationIdsForBrowser(browserName); |
| 43 | + |
| 44 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 45 | + async () => { |
| 46 | + await connectionConfigurationsPage.search( |
| 47 | + nameWithBrowserSuffix, |
| 48 | + ); |
| 49 | + }, |
| 50 | + { |
| 51 | + urlMustContain: [encodeURIComponent(nameWithBrowserSuffix)], |
| 52 | + }, |
| 53 | + ); |
| 54 | + |
| 55 | + await connectionConfigurationsPage.expectRowVisible(activeId); |
| 56 | + await connectionConfigurationsPage.expectRowVisible(inactiveId); |
| 57 | + }); |
| 58 | + |
| 59 | + test("B Using search and filters", async ({ |
| 60 | + page, |
| 61 | + browserName, |
| 62 | + }, testInfo) => { |
| 63 | + expect(page.url()).toContain("/connection-configurations"); |
| 64 | + |
| 65 | + const nameWithBrowserSuffix = addBrowserSuffixToText( |
| 66 | + searchName, |
| 67 | + testInfo, |
| 68 | + ); |
| 69 | + |
| 70 | + const { activeId, inactiveId } = |
| 71 | + getConnectionConfigurationIdsForBrowser(browserName); |
| 72 | + |
| 73 | + await connectionConfigurationsPage.search(nameWithBrowserSuffix); |
| 74 | + |
| 75 | + await connectionConfigurationsPage.expectRowVisible(activeId); |
| 76 | + await connectionConfigurationsPage.expectRowVisible(inactiveId); |
| 77 | + |
| 78 | + // set status filter inactive |
| 79 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 80 | + async () => { |
| 81 | + await connectionConfigurationsPage.toggleStatusFilter( |
| 82 | + "Inactive", |
| 83 | + ); |
| 84 | + }, |
| 85 | + { |
| 86 | + urlMustContain: [/optionalParameters%5Bactive%5D=false/i], |
| 87 | + }, |
| 88 | + ); |
| 89 | + |
| 90 | + await connectionConfigurationsPage.expectRowVisible(inactiveId); |
| 91 | + await expect(connectionConfigurationsPage.row(activeId)).toHaveCount(0); |
| 92 | + |
| 93 | + // set status filter active |
| 94 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 95 | + async () => { |
| 96 | + await connectionConfigurationsPage.toggleStatusFilter("Active"); |
| 97 | + }, |
| 98 | + { |
| 99 | + urlMustContain: [/optionalParameters%5Bactive%5D=true/i], |
| 100 | + }, |
| 101 | + ); |
| 102 | + |
| 103 | + await connectionConfigurationsPage.expectRowVisible(activeId); |
| 104 | + await expect(connectionConfigurationsPage.row(inactiveId)).toHaveCount( |
| 105 | + 0, |
| 106 | + ); |
| 107 | + |
| 108 | + // institution filter if present |
| 109 | + if ( |
| 110 | + await connectionConfigurationsPage.institutionFilterContainer.count() |
| 111 | + ) { |
| 112 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 113 | + async () => { |
| 114 | + await connectionConfigurationsPage.toggleInstitutionFilter( |
| 115 | + institutionModelId, |
| 116 | + ); |
| 117 | + }, |
| 118 | + { |
| 119 | + urlMustContain: [ |
| 120 | + new RegExp( |
| 121 | + `optionalParameters%5BinstitutionId%5D=${institutionModelId}`, |
| 122 | + "i", |
| 123 | + ), |
| 124 | + ], |
| 125 | + }, |
| 126 | + ); |
| 127 | + |
| 128 | + await expect(connectionConfigurationsPage.table).toBeVisible(); |
| 129 | + } |
| 130 | + |
| 131 | + // clear filters / searches |
| 132 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 133 | + async () => { |
| 134 | + await connectionConfigurationsPage.clearSearch(); |
| 135 | + }, |
| 136 | + { |
| 137 | + urlMustContain: [ |
| 138 | + /optionalParameters%5Bpage_size%5D=5/i, |
| 139 | + /optionalParameters%5Bpage_number%5D=1/i, |
| 140 | + ], |
| 141 | + }, |
| 142 | + ); |
| 143 | + |
| 144 | + await expect(connectionConfigurationsPage.searchInput).toHaveValue(""); |
| 145 | + }); |
| 146 | + |
| 147 | + test("C Using table sorting and paging", async ({ page }, testInfo) => { |
| 148 | + expect(page.url()).toContain("/connection-configurations"); |
| 149 | + |
| 150 | + const nameWithBrowserSuffix = addBrowserSuffixToText( |
| 151 | + searchName, |
| 152 | + testInfo, |
| 153 | + ); |
| 154 | + |
| 155 | + await connectionConfigurationsPage.search(nameWithBrowserSuffix); |
| 156 | + |
| 157 | + // sort by name |
| 158 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 159 | + async () => { |
| 160 | + await connectionConfigurationsPage.sortByHeaderText("Name"); |
| 161 | + }, |
| 162 | + { |
| 163 | + urlMustContain: [/optionalParameters%5Bsort%5D=name/i], |
| 164 | + }, |
| 165 | + ); |
| 166 | + |
| 167 | + // sort by creation date |
| 168 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 169 | + async () => { |
| 170 | + await connectionConfigurationsPage.sortByHeaderText( |
| 171 | + "Creation Date", |
| 172 | + ); |
| 173 | + }, |
| 174 | + { |
| 175 | + urlMustContain: [/optionalParameters%5Bsort%5D=date/i], |
| 176 | + }, |
| 177 | + ); |
| 178 | + |
| 179 | + // verify pagination |
| 180 | + const pagination = connectionConfigurationsPage.paginationRoot(); |
| 181 | + if (await pagination.count()) { |
| 182 | + const page2 = pagination.getByRole("button", { name: "2" }); |
| 183 | + |
| 184 | + if (await page2.count()) { |
| 185 | + await connectionConfigurationsPage.expectConnectionConfigurationsListRequestSucceeded( |
| 186 | + async () => { |
| 187 | + await page2.first().click(); |
| 188 | + }, |
| 189 | + { |
| 190 | + urlMustContain: [ |
| 191 | + /optionalParameters%5Bpage_number%5D=2/i, |
| 192 | + ], |
| 193 | + }, |
| 194 | + ); |
| 195 | + } |
| 196 | + } |
| 197 | + }); |
| 198 | + |
| 199 | + test("D Server Error", async ({ page }) => { |
| 200 | + await page.route(/\/client_configuration(?:\?|$)/i, async (route) => { |
| 201 | + await route.fulfill({ |
| 202 | + status: 500, |
| 203 | + contentType: "application/json", |
| 204 | + body: JSON.stringify({ |
| 205 | + message: "Internal Server Error (forced by Playwright)", |
| 206 | + }), |
| 207 | + }); |
| 208 | + }); |
| 209 | + |
| 210 | + await connectionConfigurationsPage.goto(); |
| 211 | + await connectionConfigurationsPage.expectVisible(); |
| 212 | + await connectionConfigurationsPage.expectErrorToast([ |
| 213 | + "Unexpected error —", |
| 214 | + "500", |
| 215 | + ]); |
| 216 | + }); |
| 217 | +}); |
0 commit comments