Skip to content
Closed
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
24 changes: 24 additions & 0 deletions frontend/e2e/helpers/e2e-helpers.playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,14 +872,38 @@ export class E2EHelpers {
if (entityName) {
await this.click(byId(`permissions-${entityName.toLowerCase()}`));
}
// The toggle saves async via POST/PUT to .../user-permissions/. Await it
// before closing the modal — otherwise logout can abort the in-flight
// save and the grant never lands, so the next user can't see the entity.
const saved = this.page.waitForResponse(
(res) =>
res.url().includes('/user-permissions/') &&
res.request().method() !== 'GET',
{ timeout: LONG_TIMEOUT },
);
if (permission === 'ADMIN') {
await this.click(byId(`admin-switch-${level}`));
} else {
await this.click(byId(`permission-switch-${permission}`));
}
await saved;
await this.closeModal();
}

// Reload the page until a selector becomes visible. For state that is
// eventually consistent across a fresh navigation (e.g. a just-granted
// permission) — waiting on a single page load can't help, because the data
// was already fetched without it.
async reloadUntilVisible(selector: string, timeout: number = LONG_TIMEOUT) {
logUsingLastSection(`Reload until visible ${selector}`);
await expect(async () => {
await this.page.reload();
await expect(this.page.locator(selector).first()).toBeVisible({
timeout: 5000,
});
}).toPass({ timeout });
}

// Create a tag
async createTag(label: string, color: string = '#FF6B6B') {
logUsingLastSection(`Creating tag: ${label}`);
Expand Down
5 changes: 4 additions & 1 deletion frontend/e2e/tests/environment-permission-test.pw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test.describe('Environment Permission Tests', () => {
gotoTraits,
login,
logout,
reloadUntilVisible,
setUserPermission,
toggleFeature,
waitForElementClickable,
Expand Down Expand Up @@ -87,7 +88,9 @@ test.describe('Environment Permission Tests', () => {
log('User with permissions can see environment')
await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD)
await gotoProject(PROJECT_NAME)
await waitForElementVisible(byId('switch-environment-production'))
// VIEW_ENVIRONMENT was just granted; the env list was fetched on
// navigation, so reload until it reflects the new permission.
await reloadUntilVisible(byId('switch-environment-production'))
await logout()

log('User with permissions can update feature state')
Expand Down
Loading