From fd2e6b7fd3efe991c8b569fb091cc6908bcf2f53 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:27:57 -0300 Subject: [PATCH 1/8] feat(EmptyState): Add an error status with a retry action Co-Authored-By: Claude Opus 5.5 --- .../components/EmptyState.stories.tsx | 24 ++++++++++- frontend/web/components/EmptyState.tsx | 41 ++++++++++++++++--- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/frontend/documentation/components/EmptyState.stories.tsx b/frontend/documentation/components/EmptyState.stories.tsx index e3e567620606..817030e73617 100644 --- a/frontend/documentation/components/EmptyState.stories.tsx +++ b/frontend/documentation/components/EmptyState.stories.tsx @@ -40,7 +40,18 @@ const meta: Meta = { iconColour: { control: 'color', description: - 'Icon fill colour. Defaults to a neutral grey when not provided.', + 'Icon fill colour. Defaults to the secondary icon colour, or the danger colour for `status="error"`.', + }, + onRetry: { + control: false, + description: + 'Renders a Try again button, with "Try again in a few moments." as the description unless one is given.', + }, + status: { + control: 'inline-radio', + description: + '`error` is for content that failed to load: it defaults to a warning icon in the danger colour and is announced to screen readers. Pair it with a retry action.', + options: ['empty', 'error'], }, title: { control: 'text', @@ -93,3 +104,14 @@ export const WithDocsLink: Story = { title: 'No projects yet', }, } + +export const LoadError: Story = { + args: { + description: undefined, + // Clears the shared icon so the error status shows its warning icon + icon: undefined, + onRetry: () => undefined, + status: 'error', + title: 'Could not load projects', + }, +} diff --git a/frontend/web/components/EmptyState.tsx b/frontend/web/components/EmptyState.tsx index 6bff60883a01..03f18e6e0582 100644 --- a/frontend/web/components/EmptyState.tsx +++ b/frontend/web/components/EmptyState.tsx @@ -1,14 +1,22 @@ import React, { FC, ReactNode } from 'react' +import { colorIconDanger, colorIconSecondary } from 'common/theme/tokens' import Icon, { IconName } from './icons/Icon' +import Button from './base/forms/Button' + +export type EmptyStateStatus = 'empty' | 'error' type EmptyStateProps = { title: string description?: string | ReactNode + // 'error' is for content that failed to load: pair it with a retry action + status?: EmptyStateStatus icon?: IconName iconColour?: string docsUrl?: string docsLabel?: string action?: ReactNode + // Renders a Try again button, and a matching description unless one is given + onRetry?: () => void className?: string } @@ -19,19 +27,35 @@ const EmptyState: FC = ({ docsLabel = 'View docs', docsUrl, icon, - iconColour = '#9DA4AE', + iconColour, + onRetry, + status = 'empty', title, }) => { + const isError = status === 'error' + const iconName = icon ?? (isError ? 'warning' : undefined) + const text = + description ?? (onRetry ? 'Try again in a few moments.' : undefined) return ( -
- {icon && ( +
+ {iconName && (
- +
)}
{title}
- {description && ( -
{description}
+ {text && ( +
{text}
)} {docsUrl && ( = ({ )} {action} + {onRetry && ( + + )}
) } From de11c87ba20ac1cc5a5fa4a0c757dbd289d4eea6 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:27:59 -0300 Subject: [PATCH 2/8] fix(Projects): Remove N+1 calls to get project environments Project cards link to /project/:id, which redirects to the first environment by name, and the permission dialogs load the selected project's environments themselves. Co-Authored-By: Claude Opus 5.5 --- .../hooks/useSortedProjectEnvironments.ts | 15 ++++ frontend/common/stores/organisation-store.js | 34 ++------ .../utils/__tests__/environmentFixture.ts | 19 +++++ .../__tests__/projectLandingPath.test.ts | 26 ++++++ .../__tests__/sortEnvironmentsByName.test.ts | 79 +++++++++++++++++++ frontend/common/utils/projectLandingPath.ts | 11 +++ .../common/utils/sortEnvironmentsByName.ts | 9 +++ frontend/web/components/PermissionsTabs.tsx | 36 ++++----- .../web/components/ProjectManageWidget.tsx | 8 +- .../EnvironmentPermissions.tsx | 31 +++++--- .../InspectPermissions.tsx | 25 ++---- .../components/pages/ProjectRedirectPage.tsx | 45 ++++++----- 12 files changed, 233 insertions(+), 105 deletions(-) create mode 100644 frontend/common/hooks/useSortedProjectEnvironments.ts create mode 100644 frontend/common/utils/__tests__/environmentFixture.ts create mode 100644 frontend/common/utils/__tests__/projectLandingPath.test.ts create mode 100644 frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts create mode 100644 frontend/common/utils/projectLandingPath.ts create mode 100644 frontend/common/utils/sortEnvironmentsByName.ts diff --git a/frontend/common/hooks/useSortedProjectEnvironments.ts b/frontend/common/hooks/useSortedProjectEnvironments.ts new file mode 100644 index 000000000000..946026d8551f --- /dev/null +++ b/frontend/common/hooks/useSortedProjectEnvironments.ts @@ -0,0 +1,15 @@ +import { skipToken } from '@reduxjs/toolkit/query' +import { useGetAllEnvironmentsQuery } from 'common/services/useEnvironment' +import { sortEnvironmentsByName } from 'common/utils/sortEnvironmentsByName' + +export const useSortedProjectEnvironments = (projectId: number | undefined) => { + // currentData, not data: data keeps the previous project's list while the next one loads + const { currentData, isError, isFetching, refetch } = + useGetAllEnvironmentsQuery(projectId ? { projectId } : skipToken) + return { + environments: currentData && sortEnvironmentsByName(currentData), + isError, + isLoading: isFetching && !currentData, + refetch, + } +} diff --git a/frontend/common/stores/organisation-store.js b/frontend/common/stores/organisation-store.js index ff50e0ba316a..9a1b7499ac92 100644 --- a/frontend/common/stores/organisation-store.js +++ b/frontend/common/stores/organisation-store.js @@ -8,7 +8,6 @@ import Dispatcher from 'common/dispatcher/dispatcher' import BaseStore from './base/_store' import data from 'common/data/base/_data' import filter from 'lodash/filter' -import find from 'lodash/find' import findIndex from 'lodash/findIndex' import keyBy from 'lodash/keyBy' @@ -75,10 +74,7 @@ const controller = { const idInt = parseInt(id) store.saving() if (store.model) { - store.model.projects = filter( - store.model.projects, - (p) => p.id !== idInt, - ) + store.model.projects = filter(store.model.projects, (p) => p.id !== idInt) store.model.keyedProjects = keyBy(store.model.projects, 'id') } API.trackEvent(Constants.events.REMOVE_PROJECT) @@ -140,7 +136,9 @@ const controller = { if (`${id}` === `${store.id}`) { // eslint-disable-next-line prefer-const let [_projects, users, invites, subscriptionMeta] = res - let projects = sortBy(_projects, 'name') + let projects = sortBy(_projects, (project) => + project.name.toLowerCase(), + ) store.model = { ...store.model, @@ -196,27 +194,9 @@ const controller = { }) } - return Promise.all( - projects.map((project, i) => - data - .get(`${Project.api}environments/?project=${project.id}`) - .then((res) => { - projects[i].environments = sortBy(res.results, 'name') - }) - .catch(() => { - projects[i].environments = [] - }), - ), - ).then(() => { - projects.sort((a, b) => { - const textA = a.name.toLowerCase() - const textB = b.name.toLowerCase() - return textA < textB ? -1 : textA > textB ? 1 : 0 - }) - store.model.projects = projects - store.model.keyedProjects = keyBy(store.model.projects, 'id') - store.loaded() - }) + store.model.projects = projects + store.model.keyedProjects = keyBy(store.model.projects, 'id') + store.loaded() } }) } diff --git a/frontend/common/utils/__tests__/environmentFixture.ts b/frontend/common/utils/__tests__/environmentFixture.ts new file mode 100644 index 000000000000..106695074a8a --- /dev/null +++ b/frontend/common/utils/__tests__/environmentFixture.ts @@ -0,0 +1,19 @@ +import type { Environment } from 'common/types/responses' + +export const makeEnvironment = (id: number, name: string): Environment => ({ + allow_client_traits: true, + api_key: `key-${id}`, + hide_disabled_flags: null, + hide_sensitive_data: false, + id, + is_creating: false, + metadata: [], + minimum_change_request_approvals: null, + name, + project: 1, + show_disabled_flags: false, + use_identity_composite_key_for_hashing: false, + use_identity_overrides_in_local_eval: false, + use_mv_v2_evaluation: false, + use_v2_feature_versioning: false, +}) diff --git a/frontend/common/utils/__tests__/projectLandingPath.test.ts b/frontend/common/utils/__tests__/projectLandingPath.test.ts new file mode 100644 index 000000000000..e2778d25dd15 --- /dev/null +++ b/frontend/common/utils/__tests__/projectLandingPath.test.ts @@ -0,0 +1,26 @@ +import { getProjectLandingPath } from 'common/utils/projectLandingPath' +import { makeEnvironment } from './environmentFixture' + +describe('getProjectLandingPath', () => { + it('opens the features of the first environment', () => { + // Given + const environments = [ + makeEnvironment(2, 'Development'), + makeEnvironment(1, 'Production'), + ] + + // When + const path = getProjectLandingPath(7, environments) + + // Then + expect(path).toBe('/project/7/environment/key-2/features') + }) + + it('opens create environment when the project has none', () => { + // When + const path = getProjectLandingPath(7, []) + + // Then + expect(path).toBe('/project/7/environment/create') + }) +}) diff --git a/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts b/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts new file mode 100644 index 000000000000..9376aede0928 --- /dev/null +++ b/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts @@ -0,0 +1,79 @@ +import { sortEnvironmentsByName } from 'common/utils/sortEnvironmentsByName' +import { makeEnvironment } from './environmentFixture' + +const names = (environments: { name: string }[]) => + environments.map((env) => env.name) + +describe('sortEnvironmentsByName', () => { + it('orders environments by name rather than by id', () => { + // Given + const environments = [ + makeEnvironment(1, 'Production'), + makeEnvironment(2, 'Development'), + makeEnvironment(3, 'Staging'), + ] + + // When + const sorted = sortEnvironmentsByName(environments) + + // Then + expect(names(sorted)).toEqual(['Development', 'Production', 'Staging']) + }) + + it('puts capitalised names before lowercase ones, as the UI always has', () => { + // Given + const environments = [ + makeEnvironment(1, 'test'), + makeEnvironment(2, 'Production'), + makeEnvironment(3, 'new env'), + makeEnvironment(4, 'Development'), + ] + + // When + const sorted = sortEnvironmentsByName(environments) + + // Then + expect(names(sorted)).toEqual([ + 'Development', + 'Production', + 'new env', + 'test', + ]) + }) + + it('keeps the API order for environments with the same name', () => { + // Given + const environments = [ + makeEnvironment(2, 'Staging'), + makeEnvironment(1, 'Staging'), + ] + + // When + const sorted = sortEnvironmentsByName(environments) + + // Then + expect(sorted.map((env) => env.id)).toEqual([2, 1]) + }) + + it('leaves the input untouched', () => { + // Given + const environments = [ + makeEnvironment(1, 'Production'), + makeEnvironment(2, 'Development'), + ] + + // When + sortEnvironmentsByName(environments) + + // Then + expect(names(environments)).toEqual(['Production', 'Development']) + }) + + it('returns an empty list for a project without environments', () => { + // When + const sorted = sortEnvironmentsByName([]) + + // Then + expect(sorted).toEqual([]) + }) +}) diff --git a/frontend/common/utils/projectLandingPath.ts b/frontend/common/utils/projectLandingPath.ts new file mode 100644 index 000000000000..90b4ea6e4da3 --- /dev/null +++ b/frontend/common/utils/projectLandingPath.ts @@ -0,0 +1,11 @@ +import type { Environment } from 'common/types/responses' + +export function getProjectLandingPath( + projectId: number, + environmentsByName: Environment[], +): string { + const environment = environmentsByName[0] + return environment + ? `/project/${projectId}/environment/${environment.api_key}/features` + : `/project/${projectId}/environment/create` +} diff --git a/frontend/common/utils/sortEnvironmentsByName.ts b/frontend/common/utils/sortEnvironmentsByName.ts new file mode 100644 index 000000000000..df3d82dc0717 --- /dev/null +++ b/frontend/common/utils/sortEnvironmentsByName.ts @@ -0,0 +1,9 @@ +import sortBy from 'lodash/sortBy' +import type { Environment } from 'common/types/responses' + +// The API orders environments by id +export function sortEnvironmentsByName( + environments: Environment[], +): Environment[] { + return sortBy(environments, 'name') +} diff --git a/frontend/web/components/PermissionsTabs.tsx b/frontend/web/components/PermissionsTabs.tsx index cd3988c86800..f028992d694c 100644 --- a/frontend/web/components/PermissionsTabs.tsx +++ b/frontend/web/components/PermissionsTabs.tsx @@ -1,12 +1,6 @@ -import React, { FC, Ref, useEffect, useState } from 'react' +import React, { FC, Ref, useState } from 'react' import { EditPermissionsModal } from './EditPermissions' -import { - Environment, - Project, - Role, - User, - UserGroupSummary, -} from 'common/types/responses' +import { Project, Role, User, UserGroupSummary } from 'common/types/responses' import Tabs from './navigation/TabMenu/Tabs' import TabItem from './navigation/TabMenu/TabItem' import Input from './base/forms/Input' @@ -16,6 +10,8 @@ import ProjectFilter from './ProjectFilter' import OrganisationStore from 'common/stores/organisation-store' import PlanBasedAccess from './PlanBasedAccess' import WarningMessage from './WarningMessage' +import EmptyState from './EmptyState' +import { useSortedProjectEnvironments } from 'common/hooks/useSortedProjectEnvironments' type PermissionsTabsType = { orgId?: number @@ -42,16 +38,8 @@ const PermissionsTabs: FC = ({ const [searchEnv, setSearchEnv] = useState('') const projectData: Project[] | undefined = OrganisationStore.getProjects() const [project, setProject] = useState('') - const [environments, setEnvironments] = useState([]) - - useEffect(() => { - if (project && projectData) { - const environments = projectData.find( - (p) => p.id === parseInt(project), - )?.environments - setEnvironments(environments || []) - } - }, [project, projectData]) + const { environments, isError, isLoading, refetch } = + useSortedProjectEnvironments(Number(project) || undefined) if (!orgId) { return @@ -154,13 +142,21 @@ const PermissionsTabs: FC = ({ />
- {environments.length > 0 && ( + {isLoading && } + {isError && !environments?.length && ( + + )} + {!!environments?.length && ( { + mainItems={environments.map((v) => { return { id: role ? v.id : v.api_key, name: v.name, diff --git a/frontend/web/components/ProjectManageWidget.tsx b/frontend/web/components/ProjectManageWidget.tsx index cfd9768cfdea..62821e48f747 100644 --- a/frontend/web/components/ProjectManageWidget.tsx +++ b/frontend/web/components/ProjectManageWidget.tsx @@ -115,7 +115,7 @@ const ProjectManageWidget: FC = ({ organisationId }) => {
} items={projects} - renderRow={({ environments, id, name }, i) => { + renderRow={({ id, name }, i) => { return ( <> {i === 0 && ( @@ -152,11 +152,7 @@ const ProjectManageWidget: FC = ({ organisationId }) => { key={id} id={`project-select-${i}`} data-test={`project-${Utils.toKebabCase(name)}`} - to={`/project/${id}/environment/${ - environments && environments[0] - ? `${environments[0].api_key}/features` - : 'create' - }`} + to={`/project/${id}`} className='clickable col-md-6 col-xl-3' style={{ minWidth: '190px' }} > diff --git a/frontend/web/components/inspect-permissions/EnvironmentPermissions.tsx b/frontend/web/components/inspect-permissions/EnvironmentPermissions.tsx index 107ed69a30eb..03a598ae3d02 100644 --- a/frontend/web/components/inspect-permissions/EnvironmentPermissions.tsx +++ b/frontend/web/components/inspect-permissions/EnvironmentPermissions.tsx @@ -1,7 +1,6 @@ -import { useMemo } from 'react' import ExpandablePermissionsList from './ExpandablePermissionsList' -import OrganisationStore from 'common/stores/organisation-store' -import { Project } from 'common/types/responses' +import { useSortedProjectEnvironments } from 'common/hooks/useSortedProjectEnvironments' +import EmptyState from 'components/EmptyState' import PanelSearch from 'components/PanelSearch' type EnvironmentPermissionsProps = { @@ -15,19 +14,29 @@ const EnvironmentPermissions = ({ searchEnvironment = '', userId, }: EnvironmentPermissionsProps) => { - const projectData: Project[] = OrganisationStore.getProjects() - const environments = useMemo(() => { - if (!projectData || !projectId) { - return - } - return projectData.find((p) => p.id === parseInt(projectId))?.environments - }, [projectData, projectId]) + const { environments, isError, isLoading, refetch } = + useSortedProjectEnvironments(Number(projectId) || undefined) const filteredEnvironments = environments?.filter((v) => { const search = searchEnvironment?.toLowerCase() if (!search) return true return `${v.name}`.toLowerCase().includes(search) }) + if (isLoading) { + return + } + if (isError && !environments?.length) { + return ( + + ) + } + if (!environments?.length) { + return null + } return ( <> env.name} getItemId={(env) => env.id} getLevelId={(env) => env.api_key} diff --git a/frontend/web/components/inspect-permissions/InspectPermissions.tsx b/frontend/web/components/inspect-permissions/InspectPermissions.tsx index 09052fb06e6a..d2c85ad282ca 100644 --- a/frontend/web/components/inspect-permissions/InspectPermissions.tsx +++ b/frontend/web/components/inspect-permissions/InspectPermissions.tsx @@ -1,11 +1,10 @@ -import React, { FC, Ref, useMemo, useState } from 'react' -import { Project, Role, User, UserGroupSummary } from 'common/types/responses' +import React, { FC, Ref, useState } from 'react' +import { Role, User, UserGroupSummary } from 'common/types/responses' import Tabs from 'components/navigation/TabMenu/Tabs' import TabItem from 'components/navigation/TabMenu/TabItem' import Input from 'components/base/forms/Input' import Utils from 'common/utils/utils' import ProjectFilter from 'components/ProjectFilter' -import OrganisationStore from 'common/stores/organisation-store' import PlanBasedAccess from 'components/PlanBasedAccess' import Permissions from './Permissions' import ProjectPermissions from './ProjectPermissions' @@ -30,16 +29,8 @@ const InspectPermissions: FC = ({ value, }) => { const [searchEnv, setSearchEnv] = useState('') - const projectData: Project[] = OrganisationStore.getProjects() const [project, setProject] = useState('') - const environments = useMemo(() => { - if (!project || !projectData) { - return null - } - return projectData.find((p) => p.id === parseInt(project))?.environments - }, [project, projectData]) - if (!orgId) { return null } @@ -95,13 +86,11 @@ const InspectPermissions: FC = ({ />
- {environments?.length !== 0 && ( - - )} +
diff --git a/frontend/web/components/pages/ProjectRedirectPage.tsx b/frontend/web/components/pages/ProjectRedirectPage.tsx index d41e09e67ecd..5c906c2cc052 100644 --- a/frontend/web/components/pages/ProjectRedirectPage.tsx +++ b/frontend/web/components/pages/ProjectRedirectPage.tsx @@ -1,33 +1,32 @@ -import { FC, useEffect } from 'react' -import { useGetEnvironmentsQuery } from 'common/services/useEnvironment' -import { useHistory } from 'react-router-dom' +import { FC } from 'react' +import { Redirect } from 'react-router-dom' +import { skipToken } from '@reduxjs/toolkit/query' +import { useGetAllEnvironmentsQuery } from 'common/services/useEnvironment' +import { sortEnvironmentsByName } from 'common/utils/sortEnvironmentsByName' import Utils from 'common/utils/utils' +import { getProjectLandingPath } from 'common/utils/projectLandingPath' import ConfigProvider from 'common/providers/ConfigProvider' import { useRouteContext } from 'components/providers/RouteContext' const ProjectRedirectPage: FC = () => { - const history = useHistory() const { projectId } = useRouteContext() + const { currentData, isError } = useGetAllEnvironmentsQuery( + projectId ? { projectId } : skipToken, + ) - const { data, error } = useGetEnvironmentsQuery({ - projectId: projectId?.toString() || '', - }) - useEffect(() => { - if (!data) { - return - } - if (error) { - history.replace(Utils.getOrganisationHomePage()) - } - const environment = data?.results?.[0] - if (environment) { - history.replace( - `/project/${projectId}/environment/${environment.api_key}/features`, - ) - } else { - history.replace(`/project/${projectId}/environment/create`) - } - }, [data, error, history]) + if (isError) { + return + } + if (projectId && currentData) { + return ( + + ) + } return (
From 53332f9840d11400480ab0ccfb3b1e79300723b3 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:28:01 -0300 Subject: [PATCH 3/8] test(Permissions): Cover the environment list in both user permission dialogs Co-Authored-By: Claude Opus 5.5 --- frontend/e2e/helpers/api-setup.playwright.ts | 62 ++++++++++++ .../e2e/helpers/e2e-helpers.playwright.ts | 5 +- frontend/e2e/helpers/index.ts | 1 + frontend/e2e/tests/deep-link-test.pw.ts | 79 ++++------------ .../e2e/tests/user-permissions-test.pw.ts | 94 +++++++++++++++++++ 5 files changed, 177 insertions(+), 64 deletions(-) create mode 100644 frontend/e2e/helpers/api-setup.playwright.ts create mode 100644 frontend/e2e/tests/user-permissions-test.pw.ts diff --git a/frontend/e2e/helpers/api-setup.playwright.ts b/frontend/e2e/helpers/api-setup.playwright.ts new file mode 100644 index 000000000000..01906fa9c468 --- /dev/null +++ b/frontend/e2e/helpers/api-setup.playwright.ts @@ -0,0 +1,62 @@ +import type { APIRequestContext } from '@playwright/test' +import { expect } from '@playwright/test' +import { E2E_USER, PASSWORD } from '../config' +import Project from '../../common/project' + +type ApiList = T[] | { results: T[] } + +const unwrap = (body: ApiList): T[] => + Array.isArray(body) ? body : body.results + +// A project of our own per test, so a run never races another test's data +// or an earlier iteration of the same test under `E2E_REPEAT`. +export const createProjectThroughApi = async ( + request: APIRequestContext, + name: string, +) => { + const api = Project.api + + const loginRes = await request.post(`${api}auth/login/`, { + data: { email: E2E_USER, password: PASSWORD }, + }) + expect(loginRes.ok()).toBeTruthy() + const { key } = await loginRes.json() + const headers = { Authorization: `Token ${key}` } + + // The seeded organisation from e2e_seed_data.py; other orgs may appear + // concurrently (e.g. the versioning test creates one), so match by name. + const organisation = unwrap<{ id: number; name: string }>( + await (await request.get(`${api}organisations/`, { headers })).json(), + ).find((o) => o.name === 'Bullet Train Ltd') + expect(organisation).toBeTruthy() + + // The seeded org is at its subscription's project cap; the E2E auth token + // header marks the request as E2E so the cap check is bypassed. + const e2eToken = + process.env.E2E_TEST_TOKEN ?? + process.env[`E2E_TEST_TOKEN_${Project.env.toUpperCase()}`] ?? + '' + const projectRes = await request.post(`${api}projects/`, { + data: { name, organisation: organisation?.id }, + headers: { ...headers, 'X-E2E-Test-Auth-Token': e2eToken.trim() }, + }) + expect(projectRes.ok()).toBeTruthy() + const project = (await projectRes.json()) as { id: number; name: string } + + return { api, headers, project } +} + +export const createEnvironmentThroughApi = async ( + request: APIRequestContext, + headers: Record, + api: string, + name: string, + projectId: number, +) => { + const res = await request.post(`${api}environments/`, { + data: { name, project: projectId }, + headers, + }) + expect(res.ok()).toBeTruthy() + return (await res.json()) as { id: number; api_key: string; name: string } +} diff --git a/frontend/e2e/helpers/e2e-helpers.playwright.ts b/frontend/e2e/helpers/e2e-helpers.playwright.ts index 724a1282e4b8..5e8384a91d27 100644 --- a/frontend/e2e/helpers/e2e-helpers.playwright.ts +++ b/frontend/e2e/helpers/e2e-helpers.playwright.ts @@ -186,8 +186,9 @@ export class E2EHelpers { const projectLink = this.page.locator('a').filter({ has: this.page.locator(`text="${projectName}"`) }).first(); await projectLink.waitFor({ state: 'visible', timeout: LONG_TIMEOUT }); await projectLink.click(); - // Wait for project page to load - could be features page or create environment page - await this.page.waitForURL(/\/project\/\d+/, { timeout: LONG_TIMEOUT }); + // The card links to /project/:id, which redirects to the features page + // or to create environment, so wait for the redirect to land + await this.page.waitForURL(/\/project\/\d+\/environment\//, { timeout: LONG_TIMEOUT }); await this.waitForPageFullyLoaded(); } diff --git a/frontend/e2e/helpers/index.ts b/frontend/e2e/helpers/index.ts index bf836787ddcb..ba24ff36b2a3 100644 --- a/frontend/e2e/helpers/index.ts +++ b/frontend/e2e/helpers/index.ts @@ -2,3 +2,4 @@ export * from './utils.playwright'; export * from './browser-logging.playwright'; export * from './e2e-helpers.playwright'; export * from './visual-regression'; +export * from './api-setup.playwright'; diff --git a/frontend/e2e/tests/deep-link-test.pw.ts b/frontend/e2e/tests/deep-link-test.pw.ts index 7d7dd30f5fc3..7c52e30c30ec 100644 --- a/frontend/e2e/tests/deep-link-test.pw.ts +++ b/frontend/e2e/tests/deep-link-test.pw.ts @@ -1,8 +1,12 @@ -import type { APIRequestContext } from '@playwright/test' import { test, expect } from '../test-setup' -import { createHelpers, LONG_TIMEOUT, log } from '../helpers' +import { + createEnvironmentThroughApi, + createHelpers, + createProjectThroughApi, + LONG_TIMEOUT, + log, +} from '../helpers' import { E2E_USER, PASSWORD } from '../config' -import Project from '../../common/project' const PAGE_SIZE = 50 const FEATURE_COUNT = 60 @@ -12,61 +16,6 @@ const COMPARE_PREFIX = 'e2e_compare_' // so the row that opened the slideout is identifiable from its value alone. const COMPARE_ENVIRONMENTS = ['Alpha', 'Beta', 'Gamma'] -type ApiList = T[] | { results: T[] } - -const unwrap = (body: ApiList): T[] => - Array.isArray(body) ? body : body.results - -// A project of our own per test, so a run never races another test's features -// or an earlier iteration of this one under `E2E_REPEAT`. -const createProject = async (request: APIRequestContext, name: string) => { - const api = Project.api - - const loginRes = await request.post(`${api}auth/login/`, { - data: { email: E2E_USER, password: PASSWORD }, - }) - expect(loginRes.ok()).toBeTruthy() - const { key } = await loginRes.json() - const headers = { Authorization: `Token ${key}` } - - // The seeded organisation from e2e_seed_data.py; other orgs may appear - // concurrently (e.g. the versioning test creates one), so match by name. - const organisation = unwrap<{ id: number; name: string }>( - await (await request.get(`${api}organisations/`, { headers })).json(), - ).find((o) => o.name === 'Bullet Train Ltd')! - expect(organisation).toBeTruthy() - - // The seeded org is at its subscription's project cap; the E2E auth token - // header marks the request as E2E so the cap check is bypassed. - const e2eToken = - process.env.E2E_TEST_TOKEN ?? - process.env[`E2E_TEST_TOKEN_${Project.env.toUpperCase()}`] ?? - '' - const projectRes = await request.post(`${api}projects/`, { - data: { name, organisation: organisation.id }, - headers: { ...headers, 'X-E2E-Test-Auth-Token': e2eToken.trim() }, - }) - expect(projectRes.ok()).toBeTruthy() - const project = (await projectRes.json()) as { id: number } - - return { api, headers, project } -} - -const createEnvironment = async ( - request: APIRequestContext, - headers: Record, - api: string, - name: string, - projectId: number, -) => { - const res = await request.post(`${api}environments/`, { - data: { name, project: projectId }, - headers, - }) - expect(res.ok()).toBeTruthy() - return (await res.json()) as { id: number; api_key: string; name: string } -} - test.describe('Deep link to feature slideout', () => { test('opens the slideout for a feature on any page of the list @oss', async ({ page, @@ -79,11 +28,11 @@ test.describe('Deep link to feature slideout', () => { const runId = Date.now() log('Create a dedicated project and environment') - const { api, headers, project } = await createProject( + const { api, headers, project } = await createProjectThroughApi( request, `Deep Link Project ${runId}`, ) - const environment = await createEnvironment( + const environment = await createEnvironmentThroughApi( request, headers, api, @@ -151,14 +100,20 @@ test.describe('Deep link to feature slideout', () => { const runId = Date.now() log('Create a project with one environment per compared value') - const { api, headers, project } = await createProject( + const { api, headers, project } = await createProjectThroughApi( request, `Compare Project ${runId}`, ) const environments = [] for (const name of COMPARE_ENVIRONMENTS) { environments.push( - await createEnvironment(request, headers, api, name, project.id), + await createEnvironmentThroughApi( + request, + headers, + api, + name, + project.id, + ), ) } diff --git a/frontend/e2e/tests/user-permissions-test.pw.ts b/frontend/e2e/tests/user-permissions-test.pw.ts new file mode 100644 index 000000000000..5e53c05e718f --- /dev/null +++ b/frontend/e2e/tests/user-permissions-test.pw.ts @@ -0,0 +1,94 @@ +import { test, expect } from '../test-setup' +import { + createEnvironmentThroughApi, + createHelpers, + createProjectThroughApi, + log, +} from '../helpers' +import { + E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, + E2E_USER, + PASSWORD, +} from '../config' + +// Both dialogs list a project's environments once one is picked +const MEMBER_ACTIONS = ['Manage user', 'Inspect permissions'] + +test.describe('User permissions dialogs', () => { + for (const action of MEMBER_ACTIONS) { + test(`${action} lists only the picked project's environments @enterprise`, async ({ + page, + request, + }) => { + const { login } = createHelpers(page) + // Unique per run and per case, as both cases run in parallel + const runId = `${action} ${Date.now()}` + + log('Create two projects with their own environments') + const first = await createProjectThroughApi( + request, + `Permissions A ${runId}`, + ) + const second = await createProjectThroughApi( + request, + `Permissions B ${runId}`, + ) + const firstEnvironments = [`Alpha ${runId}`, `Beta ${runId}`] + const secondEnvironment = `Gamma ${runId}` + for (const name of firstEnvironments) { + await createEnvironmentThroughApi( + request, + first.headers, + first.api, + name, + first.project.id, + ) + } + await createEnvironmentThroughApi( + request, + second.headers, + second.api, + secondEnvironment, + second.project.id, + ) + + log(`Open ${action} for a member`) + await login(E2E_USER, PASSWORD) + await page.getByRole('link', { name: 'Users and Permissions' }).click() + await page + .getByRole('button', { + name: `More actions for ${E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS}`, + }) + .click() + await page.getByRole('button', { name: action }).click() + const dialog = page.getByRole('dialog') + await dialog + .getByRole('button', { exact: true, name: 'Environment' }) + .click() + + // E2E builds render Select's options as plain, always visible links + const pickProject = async (name: string) => { + // Inactive tabs stay in the page, so the Project tab also lists the name + await dialog + .getByText(name, { exact: true }) + .filter({ visible: true }) + .click() + } + + log('The first project lists its environments') + await pickProject(first.project.name) + for (const name of firstEnvironments) { + await expect(dialog.getByText(name, { exact: true })).toBeVisible() + } + + log('Switching project replaces the list') + await pickProject(second.project.name) + await expect( + dialog.getByText(secondEnvironment, { exact: true }), + ).toBeVisible() + for (const name of firstEnvironments) { + await expect(dialog.getByText(name, { exact: true })).toHaveCount(0) + } + }) + } +}) From e2663b32a68a6867fc8cec8b73b082c53dac86b3 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:34:29 -0300 Subject: [PATCH 4/8] fix(Projects): Wait for ProjectStore before rendering a project page The loader used to finish after every project's environments loaded, which also covered ProjectStore. Without the N+1 it finishes first, so pages reading Edge from ProjectStore saw false on a direct load. Co-Authored-By: Claude Opus 5.5 --- frontend/web/components/App.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/web/components/App.js b/frontend/web/components/App.js index bda5c996deca..58bbad3e30da 100644 --- a/frontend/web/components/App.js +++ b/frontend/web/components/App.js @@ -293,8 +293,13 @@ const App = class extends Component { return } const activeProject = OrganisationStore.getProject(projectId) + // Pages still read the project from ProjectStore (e.g. Edge identities), + // so wait for it as well as the organisation's project list const projectNotLoaded = - !activeProject && document.location.href.includes('project/') + document.location.href.includes('project/') && + (!activeProject || + !ProjectStore.model || + `${ProjectStore.id}` !== `${projectId}`) if (this.props.isLoading) { return ( From 27fda93bef80a1bdec2f85f8302cf4b9bf6cb35d Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:40:49 -0300 Subject: [PATCH 5/8] test(Permissions): Type the API setup responses instead of asserting them Co-Authored-By: Claude Opus 5.5 --- frontend/e2e/helpers/api-setup.playwright.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/e2e/helpers/api-setup.playwright.ts b/frontend/e2e/helpers/api-setup.playwright.ts index 01906fa9c468..d5521396b556 100644 --- a/frontend/e2e/helpers/api-setup.playwright.ts +++ b/frontend/e2e/helpers/api-setup.playwright.ts @@ -2,6 +2,10 @@ import type { APIRequestContext } from '@playwright/test' import { expect } from '@playwright/test' import { E2E_USER, PASSWORD } from '../config' import Project from '../../common/project' +import type { + Environment, + Project as ProjectResponse, +} from '../../common/types/responses' type ApiList = T[] | { results: T[] } @@ -41,7 +45,7 @@ export const createProjectThroughApi = async ( headers: { ...headers, 'X-E2E-Test-Auth-Token': e2eToken.trim() }, }) expect(projectRes.ok()).toBeTruthy() - const project = (await projectRes.json()) as { id: number; name: string } + const project: ProjectResponse = await projectRes.json() return { api, headers, project } } @@ -52,11 +56,11 @@ export const createEnvironmentThroughApi = async ( api: string, name: string, projectId: number, -) => { +): Promise => { const res = await request.post(`${api}environments/`, { data: { name, project: projectId }, headers, }) expect(res.ok()).toBeTruthy() - return (await res.json()) as { id: number; api_key: string; name: string } + return res.json() } From 78a944eda33d21ede7de80ffde99a7daa19cc126 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:42:19 -0300 Subject: [PATCH 6/8] test(Projects): Trim tests and comments that repeat the code Co-Authored-By: Claude Opus 5.5 --- .../hooks/useSortedProjectEnvironments.ts | 2 +- .../__tests__/projectLandingPath.test.ts | 15 ++---- .../__tests__/sortEnvironmentsByName.test.ts | 54 +++---------------- .../e2e/helpers/e2e-helpers.playwright.ts | 3 +- .../e2e/tests/user-permissions-test.pw.ts | 1 - frontend/web/components/EmptyState.tsx | 1 - 6 files changed, 12 insertions(+), 64 deletions(-) diff --git a/frontend/common/hooks/useSortedProjectEnvironments.ts b/frontend/common/hooks/useSortedProjectEnvironments.ts index 946026d8551f..0e17f16b8ba4 100644 --- a/frontend/common/hooks/useSortedProjectEnvironments.ts +++ b/frontend/common/hooks/useSortedProjectEnvironments.ts @@ -3,7 +3,7 @@ import { useGetAllEnvironmentsQuery } from 'common/services/useEnvironment' import { sortEnvironmentsByName } from 'common/utils/sortEnvironmentsByName' export const useSortedProjectEnvironments = (projectId: number | undefined) => { - // currentData, not data: data keeps the previous project's list while the next one loads + // currentData: data would keep the previous project's list while the next loads const { currentData, isError, isFetching, refetch } = useGetAllEnvironmentsQuery(projectId ? { projectId } : skipToken) return { diff --git a/frontend/common/utils/__tests__/projectLandingPath.test.ts b/frontend/common/utils/__tests__/projectLandingPath.test.ts index e2778d25dd15..9ac8738e95a7 100644 --- a/frontend/common/utils/__tests__/projectLandingPath.test.ts +++ b/frontend/common/utils/__tests__/projectLandingPath.test.ts @@ -3,24 +3,17 @@ import { makeEnvironment } from './environmentFixture' describe('getProjectLandingPath', () => { it('opens the features of the first environment', () => { - // Given const environments = [ makeEnvironment(2, 'Development'), makeEnvironment(1, 'Production'), ] - // When - const path = getProjectLandingPath(7, environments) - - // Then - expect(path).toBe('/project/7/environment/key-2/features') + expect(getProjectLandingPath(7, environments)).toBe( + '/project/7/environment/key-2/features', + ) }) it('opens create environment when the project has none', () => { - // When - const path = getProjectLandingPath(7, []) - - // Then - expect(path).toBe('/project/7/environment/create') + expect(getProjectLandingPath(7, [])).toBe('/project/7/environment/create') }) }) diff --git a/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts b/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts index 9376aede0928..1be1ee4a5046 100644 --- a/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts +++ b/frontend/common/utils/__tests__/sortEnvironmentsByName.test.ts @@ -6,22 +6,20 @@ const names = (environments: { name: string }[]) => describe('sortEnvironmentsByName', () => { it('orders environments by name rather than by id', () => { - // Given const environments = [ makeEnvironment(1, 'Production'), makeEnvironment(2, 'Development'), makeEnvironment(3, 'Staging'), ] - // When - const sorted = sortEnvironmentsByName(environments) - - // Then - expect(names(sorted)).toEqual(['Development', 'Production', 'Staging']) + expect(names(sortEnvironmentsByName(environments))).toEqual([ + 'Development', + 'Production', + 'Staging', + ]) }) it('puts capitalised names before lowercase ones, as the UI always has', () => { - // Given const environments = [ makeEnvironment(1, 'test'), makeEnvironment(2, 'Production'), @@ -29,51 +27,11 @@ describe('sortEnvironmentsByName', () => { makeEnvironment(4, 'Development'), ] - // When - const sorted = sortEnvironmentsByName(environments) - - // Then - expect(names(sorted)).toEqual([ + expect(names(sortEnvironmentsByName(environments))).toEqual([ 'Development', 'Production', 'new env', 'test', ]) }) - - it('keeps the API order for environments with the same name', () => { - // Given - const environments = [ - makeEnvironment(2, 'Staging'), - makeEnvironment(1, 'Staging'), - ] - - // When - const sorted = sortEnvironmentsByName(environments) - - // Then - expect(sorted.map((env) => env.id)).toEqual([2, 1]) - }) - - it('leaves the input untouched', () => { - // Given - const environments = [ - makeEnvironment(1, 'Production'), - makeEnvironment(2, 'Development'), - ] - - // When - sortEnvironmentsByName(environments) - - // Then - expect(names(environments)).toEqual(['Production', 'Development']) - }) - - it('returns an empty list for a project without environments', () => { - // When - const sorted = sortEnvironmentsByName([]) - - // Then - expect(sorted).toEqual([]) - }) }) diff --git a/frontend/e2e/helpers/e2e-helpers.playwright.ts b/frontend/e2e/helpers/e2e-helpers.playwright.ts index 5e8384a91d27..3bf344b6eab9 100644 --- a/frontend/e2e/helpers/e2e-helpers.playwright.ts +++ b/frontend/e2e/helpers/e2e-helpers.playwright.ts @@ -186,8 +186,7 @@ export class E2EHelpers { const projectLink = this.page.locator('a').filter({ has: this.page.locator(`text="${projectName}"`) }).first(); await projectLink.waitFor({ state: 'visible', timeout: LONG_TIMEOUT }); await projectLink.click(); - // The card links to /project/:id, which redirects to the features page - // or to create environment, so wait for the redirect to land + // Cards go to /project/:id, which redirects to an environment page await this.page.waitForURL(/\/project\/\d+\/environment\//, { timeout: LONG_TIMEOUT }); await this.waitForPageFullyLoaded(); } diff --git a/frontend/e2e/tests/user-permissions-test.pw.ts b/frontend/e2e/tests/user-permissions-test.pw.ts index 5e53c05e718f..312a8af353e6 100644 --- a/frontend/e2e/tests/user-permissions-test.pw.ts +++ b/frontend/e2e/tests/user-permissions-test.pw.ts @@ -11,7 +11,6 @@ import { PASSWORD, } from '../config' -// Both dialogs list a project's environments once one is picked const MEMBER_ACTIONS = ['Manage user', 'Inspect permissions'] test.describe('User permissions dialogs', () => { diff --git a/frontend/web/components/EmptyState.tsx b/frontend/web/components/EmptyState.tsx index 03f18e6e0582..374397f3aa0b 100644 --- a/frontend/web/components/EmptyState.tsx +++ b/frontend/web/components/EmptyState.tsx @@ -38,7 +38,6 @@ const EmptyState: FC = ({ description ?? (onRetry ? 'Try again in a few moments.' : undefined) return (
From fd004cf7467db9528e4c2b71c10dc201486fdc04 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:46:34 -0300 Subject: [PATCH 7/8] test(Permissions): Use the seeded projects instead of creating them Co-Authored-By: Claude Opus 5.5 --- frontend/e2e/helpers/api-setup.playwright.ts | 66 ---------------- frontend/e2e/helpers/index.ts | 1 - frontend/e2e/tests/deep-link-test.pw.ts | 79 +++++++++++++++---- .../e2e/tests/user-permissions-test.pw.ts | 64 ++++----------- 4 files changed, 77 insertions(+), 133 deletions(-) delete mode 100644 frontend/e2e/helpers/api-setup.playwright.ts diff --git a/frontend/e2e/helpers/api-setup.playwright.ts b/frontend/e2e/helpers/api-setup.playwright.ts deleted file mode 100644 index d5521396b556..000000000000 --- a/frontend/e2e/helpers/api-setup.playwright.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { APIRequestContext } from '@playwright/test' -import { expect } from '@playwright/test' -import { E2E_USER, PASSWORD } from '../config' -import Project from '../../common/project' -import type { - Environment, - Project as ProjectResponse, -} from '../../common/types/responses' - -type ApiList = T[] | { results: T[] } - -const unwrap = (body: ApiList): T[] => - Array.isArray(body) ? body : body.results - -// A project of our own per test, so a run never races another test's data -// or an earlier iteration of the same test under `E2E_REPEAT`. -export const createProjectThroughApi = async ( - request: APIRequestContext, - name: string, -) => { - const api = Project.api - - const loginRes = await request.post(`${api}auth/login/`, { - data: { email: E2E_USER, password: PASSWORD }, - }) - expect(loginRes.ok()).toBeTruthy() - const { key } = await loginRes.json() - const headers = { Authorization: `Token ${key}` } - - // The seeded organisation from e2e_seed_data.py; other orgs may appear - // concurrently (e.g. the versioning test creates one), so match by name. - const organisation = unwrap<{ id: number; name: string }>( - await (await request.get(`${api}organisations/`, { headers })).json(), - ).find((o) => o.name === 'Bullet Train Ltd') - expect(organisation).toBeTruthy() - - // The seeded org is at its subscription's project cap; the E2E auth token - // header marks the request as E2E so the cap check is bypassed. - const e2eToken = - process.env.E2E_TEST_TOKEN ?? - process.env[`E2E_TEST_TOKEN_${Project.env.toUpperCase()}`] ?? - '' - const projectRes = await request.post(`${api}projects/`, { - data: { name, organisation: organisation?.id }, - headers: { ...headers, 'X-E2E-Test-Auth-Token': e2eToken.trim() }, - }) - expect(projectRes.ok()).toBeTruthy() - const project: ProjectResponse = await projectRes.json() - - return { api, headers, project } -} - -export const createEnvironmentThroughApi = async ( - request: APIRequestContext, - headers: Record, - api: string, - name: string, - projectId: number, -): Promise => { - const res = await request.post(`${api}environments/`, { - data: { name, project: projectId }, - headers, - }) - expect(res.ok()).toBeTruthy() - return res.json() -} diff --git a/frontend/e2e/helpers/index.ts b/frontend/e2e/helpers/index.ts index ba24ff36b2a3..bf836787ddcb 100644 --- a/frontend/e2e/helpers/index.ts +++ b/frontend/e2e/helpers/index.ts @@ -2,4 +2,3 @@ export * from './utils.playwright'; export * from './browser-logging.playwright'; export * from './e2e-helpers.playwright'; export * from './visual-regression'; -export * from './api-setup.playwright'; diff --git a/frontend/e2e/tests/deep-link-test.pw.ts b/frontend/e2e/tests/deep-link-test.pw.ts index 7c52e30c30ec..7d7dd30f5fc3 100644 --- a/frontend/e2e/tests/deep-link-test.pw.ts +++ b/frontend/e2e/tests/deep-link-test.pw.ts @@ -1,12 +1,8 @@ +import type { APIRequestContext } from '@playwright/test' import { test, expect } from '../test-setup' -import { - createEnvironmentThroughApi, - createHelpers, - createProjectThroughApi, - LONG_TIMEOUT, - log, -} from '../helpers' +import { createHelpers, LONG_TIMEOUT, log } from '../helpers' import { E2E_USER, PASSWORD } from '../config' +import Project from '../../common/project' const PAGE_SIZE = 50 const FEATURE_COUNT = 60 @@ -16,6 +12,61 @@ const COMPARE_PREFIX = 'e2e_compare_' // so the row that opened the slideout is identifiable from its value alone. const COMPARE_ENVIRONMENTS = ['Alpha', 'Beta', 'Gamma'] +type ApiList = T[] | { results: T[] } + +const unwrap = (body: ApiList): T[] => + Array.isArray(body) ? body : body.results + +// A project of our own per test, so a run never races another test's features +// or an earlier iteration of this one under `E2E_REPEAT`. +const createProject = async (request: APIRequestContext, name: string) => { + const api = Project.api + + const loginRes = await request.post(`${api}auth/login/`, { + data: { email: E2E_USER, password: PASSWORD }, + }) + expect(loginRes.ok()).toBeTruthy() + const { key } = await loginRes.json() + const headers = { Authorization: `Token ${key}` } + + // The seeded organisation from e2e_seed_data.py; other orgs may appear + // concurrently (e.g. the versioning test creates one), so match by name. + const organisation = unwrap<{ id: number; name: string }>( + await (await request.get(`${api}organisations/`, { headers })).json(), + ).find((o) => o.name === 'Bullet Train Ltd')! + expect(organisation).toBeTruthy() + + // The seeded org is at its subscription's project cap; the E2E auth token + // header marks the request as E2E so the cap check is bypassed. + const e2eToken = + process.env.E2E_TEST_TOKEN ?? + process.env[`E2E_TEST_TOKEN_${Project.env.toUpperCase()}`] ?? + '' + const projectRes = await request.post(`${api}projects/`, { + data: { name, organisation: organisation.id }, + headers: { ...headers, 'X-E2E-Test-Auth-Token': e2eToken.trim() }, + }) + expect(projectRes.ok()).toBeTruthy() + const project = (await projectRes.json()) as { id: number } + + return { api, headers, project } +} + +const createEnvironment = async ( + request: APIRequestContext, + headers: Record, + api: string, + name: string, + projectId: number, +) => { + const res = await request.post(`${api}environments/`, { + data: { name, project: projectId }, + headers, + }) + expect(res.ok()).toBeTruthy() + return (await res.json()) as { id: number; api_key: string; name: string } +} + test.describe('Deep link to feature slideout', () => { test('opens the slideout for a feature on any page of the list @oss', async ({ page, @@ -28,11 +79,11 @@ test.describe('Deep link to feature slideout', () => { const runId = Date.now() log('Create a dedicated project and environment') - const { api, headers, project } = await createProjectThroughApi( + const { api, headers, project } = await createProject( request, `Deep Link Project ${runId}`, ) - const environment = await createEnvironmentThroughApi( + const environment = await createEnvironment( request, headers, api, @@ -100,20 +151,14 @@ test.describe('Deep link to feature slideout', () => { const runId = Date.now() log('Create a project with one environment per compared value') - const { api, headers, project } = await createProjectThroughApi( + const { api, headers, project } = await createProject( request, `Compare Project ${runId}`, ) const environments = [] for (const name of COMPARE_ENVIRONMENTS) { environments.push( - await createEnvironmentThroughApi( - request, - headers, - api, - name, - project.id, - ), + await createEnvironment(request, headers, api, name, project.id), ) } diff --git a/frontend/e2e/tests/user-permissions-test.pw.ts b/frontend/e2e/tests/user-permissions-test.pw.ts index 312a8af353e6..95966ce15b87 100644 --- a/frontend/e2e/tests/user-permissions-test.pw.ts +++ b/frontend/e2e/tests/user-permissions-test.pw.ts @@ -1,55 +1,23 @@ import { test, expect } from '../test-setup' -import { - createEnvironmentThroughApi, - createHelpers, - createProjectThroughApi, - log, -} from '../helpers' +import { createHelpers, log } from '../helpers' import { E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, E2E_USER, PASSWORD, } from '../config' +// Seeded projects: the first has Development and Production, the second only Development +const PROJECT_WITH_TWO_ENVIRONMENTS = 'My Test Project' +const PROJECT_WITH_ONE_ENVIRONMENT = 'My Test Project 2' + const MEMBER_ACTIONS = ['Manage user', 'Inspect permissions'] test.describe('User permissions dialogs', () => { for (const action of MEMBER_ACTIONS) { test(`${action} lists only the picked project's environments @enterprise`, async ({ page, - request, }) => { const { login } = createHelpers(page) - // Unique per run and per case, as both cases run in parallel - const runId = `${action} ${Date.now()}` - - log('Create two projects with their own environments') - const first = await createProjectThroughApi( - request, - `Permissions A ${runId}`, - ) - const second = await createProjectThroughApi( - request, - `Permissions B ${runId}`, - ) - const firstEnvironments = [`Alpha ${runId}`, `Beta ${runId}`] - const secondEnvironment = `Gamma ${runId}` - for (const name of firstEnvironments) { - await createEnvironmentThroughApi( - request, - first.headers, - first.api, - name, - first.project.id, - ) - } - await createEnvironmentThroughApi( - request, - second.headers, - second.api, - secondEnvironment, - second.project.id, - ) log(`Open ${action} for a member`) await login(E2E_USER, PASSWORD) @@ -59,7 +27,8 @@ test.describe('User permissions dialogs', () => { name: `More actions for ${E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS}`, }) .click() - await page.getByRole('button', { name: action }).click() + // The menu items aren't buttons yet + await page.getByText(action, { exact: true }).click() const dialog = page.getByRole('dialog') await dialog .getByRole('button', { exact: true, name: 'Environment' }) @@ -74,20 +43,17 @@ test.describe('User permissions dialogs', () => { .click() } - log('The first project lists its environments') - await pickProject(first.project.name) - for (const name of firstEnvironments) { - await expect(dialog.getByText(name, { exact: true })).toBeVisible() - } + log('A project lists its environments') + await pickProject(PROJECT_WITH_ONE_ENVIRONMENT) + await expect( + dialog.getByText('Development', { exact: true }), + ).toBeVisible() - log('Switching project replaces the list') - await pickProject(second.project.name) + log("Switching project loads the new project's list") + await pickProject(PROJECT_WITH_TWO_ENVIRONMENTS) await expect( - dialog.getByText(secondEnvironment, { exact: true }), + dialog.getByText('Production', { exact: true }), ).toBeVisible() - for (const name of firstEnvironments) { - await expect(dialog.getByText(name, { exact: true })).toHaveCount(0) - } }) } }) From 4f856186881dbdf55fd668a143e1c54691f78db5 Mon Sep 17 00:00:00 2001 From: Talisson Costa Date: Wed, 18 Nov 2026 13:48:18 -0300 Subject: [PATCH 8/8] refactor(Projects): Load the redirect's environments with the shared hook Co-Authored-By: Claude Opus 5.5 --- .../components/pages/ProjectRedirectPage.tsx | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/frontend/web/components/pages/ProjectRedirectPage.tsx b/frontend/web/components/pages/ProjectRedirectPage.tsx index 5c906c2cc052..fcc3f5a76a8a 100644 --- a/frontend/web/components/pages/ProjectRedirectPage.tsx +++ b/frontend/web/components/pages/ProjectRedirectPage.tsx @@ -1,8 +1,6 @@ import { FC } from 'react' import { Redirect } from 'react-router-dom' -import { skipToken } from '@reduxjs/toolkit/query' -import { useGetAllEnvironmentsQuery } from 'common/services/useEnvironment' -import { sortEnvironmentsByName } from 'common/utils/sortEnvironmentsByName' +import { useSortedProjectEnvironments } from 'common/hooks/useSortedProjectEnvironments' import Utils from 'common/utils/utils' import { getProjectLandingPath } from 'common/utils/projectLandingPath' import ConfigProvider from 'common/providers/ConfigProvider' @@ -10,22 +8,13 @@ import { useRouteContext } from 'components/providers/RouteContext' const ProjectRedirectPage: FC = () => { const { projectId } = useRouteContext() - const { currentData, isError } = useGetAllEnvironmentsQuery( - projectId ? { projectId } : skipToken, - ) + const { environments, isError } = useSortedProjectEnvironments(projectId) if (isError) { return } - if (projectId && currentData) { - return ( - - ) + if (projectId && environments) { + return } return (