From 3543adce4b1deeb4208ba7d3ec23ba30fdb790b6 Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 17 Dec 2024 18:03:44 +0000 Subject: [PATCH] More environment tests --- frontend/e2e/init.cafe.js | 111 ++++++------ .../e2e/tests/environment-permission-test.ts | 162 ++++++++++-------- frontend/web/components/pages/UsersPage.tsx | 6 +- 3 files changed, 147 insertions(+), 132 deletions(-) diff --git a/frontend/e2e/init.cafe.js b/frontend/e2e/init.cafe.js index 814fb76dae65..7c0e6a0cdbdf 100644 --- a/frontend/e2e/init.cafe.js +++ b/frontend/e2e/init.cafe.js @@ -85,66 +85,61 @@ fixture`E2E Tests`.requestHooks(logger).before(async () => { await logResults(logger.requests, t) }) -// test('Segment-part-1', async () => { -// await testSegment1() -// await logout() -// }) -// -// test('Segment-part-2', async () => { -// await testSegment2() -// await logout() -// }) -// -// test('Segment-part-3', async () => { -// await testSegment3() -// await logout() -// }) -// -// test('Flag', async () => { -// await flagTests() -// await logout() -// }) -// -// test('Signup', async () => { -// await initialiseTests() -// await logout() -// }) -// -// test('Invite', async () => { -// await inviteTest() -// }) -// -// test('Environment', async () => { -// await environmentTest() -// await logout() -// }) -// -// test('Project', async () => { -// await projectTest() -// await logout() -// }) -// -// test('Versioning', async () => { -// await versioningTests() -// await logout() -// }) -// -// test('Organisation-permission', async () => { -// await organisationPermissionTest() -// await logout() -// }) -// -// test('Project-permission', async () => { -// await projectPermissionTest() -// await logout() -// }) +test('Segment-part-1', async () => { + await testSegment1() + await logout() +}) + +test('Segment-part-2', async () => { + await testSegment2() + await logout() +}) + +test('Segment-part-3', async () => { + await testSegment3() + await logout() +}) + +test('Flag', async () => { + await flagTests() + await logout() +}) + +test('Signup', async () => { + await initialiseTests() + await logout() +}) + +test('Invite', async () => { + await inviteTest() +}) + +test('Environment', async () => { + await environmentTest() + await logout() +}) + +test('Project', async () => { + await projectTest() + await logout() +}) + +test('Versioning', async () => { + await versioningTests() + await logout() +}) + +test('Organisation-permission', async () => { + await organisationPermissionTest() + await logout() +}) + +test('Project-permission', async () => { + await projectPermissionTest() + await logout() +}) test('Environment-permission', async () => { await environmentPermissionTest() await logout() }) -// -// test('Roles', async () => { -// await rolesTest() -// await logout() -// }) diff --git a/frontend/e2e/tests/environment-permission-test.ts b/frontend/e2e/tests/environment-permission-test.ts index f6c8db2ced3a..b0d8be1b2f39 100644 --- a/frontend/e2e/tests/environment-permission-test.ts +++ b/frontend/e2e/tests/environment-permission-test.ts @@ -17,77 +17,97 @@ import { Selector, t } from 'testcafe' import { cli } from 'yaml/dist/cli'; export default async function () { - // log('Login') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // log('User only can see an project') - // await click('#project-select-0') - // await t - // .expect(Selector('#project-select-1').exists) - // .notOk('The element"#project-select-1" should not be present') - // await logout() - // - // log('User with permissions can Handle the Features') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await createFeature(0, 'test_feature', false) - // await toggleFeature(0, true) - // await logout() - // - // log('User without permissions cannot create traits') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await gotoTraits() - // const createTraitBtn = Selector(byId('add-trait')) - // await t.expect(createTraitBtn.hasAttribute('disabled')).ok() - // await logout() - // - // log('User without permissions cannot see audit logs') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await waitForElementNotExist(byId('audit-log-link')) - // await logout() - // - // log('Create new environment') - // await login(E2E_USER, PASSWORD) - // await clickByText('My Test Project 6 Env Permission') - // await click('#create-env-link') - // await createEnvironment('Production') - // await logout() - // log('User without permissions cannot see environment') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await waitForElementVisible(byId('switch-environment-development')) - // await waitForElementNotExist(byId('switch-environment-production')) - // await logout() - // - // log('Grant view environment permission') - // await login(E2E_USER, PASSWORD) - // await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_ENVIRONMENT', 'Production', 'environment', 'My Test Project 6 Env Permission' ) - // await logout() - // log('User with permissions can see environment') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await waitForElementVisible(byId('switch-environment-production')) - // await waitForElementVisible(byId('switch-environment-production')) - // await logout() - // - // log('User with permissions can update feature state') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await createFeature(0,'my_feature',"foo",'A test feature') - // await editRemoteConfig(0, 'bar') - // await logout() - // - // log('User without permissions cannot update feature state') - // await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) - // await click('#project-select-0') - // await waitForElementClickable(byId('feature-switch-0-on')) - // await click(byId('switch-environment-production')) - // await waitForElementNotClickable(byId('feature-switch-0-on')) - // await click(byId('feature-item-0')) - // await waitForElementNotClickable(byId('update-feature-btn')) - // await closeModal() - // await logout() + log('Login') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + log('User only can see an project') + await click('#project-select-0') + await t + .expect(Selector('#project-select-1').exists) + .notOk('The element"#project-select-1" should not be present') + await logout() + + log('User with permissions can Handle the Features') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await createFeature(0, 'test_feature', false) + await toggleFeature(0, true) + await logout() + + log('User without permissions cannot create traits') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await gotoTraits() + const createTraitBtn = Selector(byId('add-trait')) + await t.expect(createTraitBtn.hasAttribute('disabled')).ok() + await logout() + + log('User without permissions cannot see audit logs') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await waitForElementNotExist(byId('audit-log-link')) + await logout() + + log('Create new environment') + await login(E2E_USER, PASSWORD) + await clickByText('My Test Project 6 Env Permission') + await click('#create-env-link') + await createEnvironment('Production') + await logout() + log('User without permissions cannot see environment') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await waitForElementVisible(byId('switch-environment-development')) + await waitForElementNotExist(byId('switch-environment-production')) + await logout() + + log('Grant view environment permission') + await login(E2E_USER, PASSWORD) + await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'VIEW_ENVIRONMENT', 'Production', 'environment', 'My Test Project 6 Env Permission' ) + await logout() + log('User with permissions can see environment') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await waitForElementVisible(byId('switch-environment-production')) + await waitForElementVisible(byId('switch-environment-production')) + await logout() + + log('User with permissions can update feature state') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await createFeature(0,'my_feature',"foo",'A test feature') + await editRemoteConfig(0, 'bar') + await logout() + log('User without permission cannot create a segment override') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await click(byId('feature-item-0')) + await click(byId('segment_overrides')) + await waitForElementNotClickable('#update-feature-segments-btn') + await closeModal() + await logout() + log('Grant MANAGE_IDENTITIES permission') + await login(E2E_USER, PASSWORD) + await setUserPermission(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, 'MANAGE_SEGMENT_OVERRIDES', 'Development', 'environment', 'My Test Project 6 Env Permission' ) + await logout() + log('User with permission can create a segment override') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await click(byId('feature-item-0')) + await click(byId('segment_overrides')) + await waitForElementClickable('#update-feature-segments-btn') + await closeModal() + + + log('User without permissions cannot update feature state') + await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) + await click('#project-select-0') + await waitForElementClickable(byId('feature-switch-0-on')) + await click(byId('switch-environment-production')) + await waitForElementNotClickable(byId('feature-switch-0-on')) + await click(byId('feature-item-0')) + await waitForElementNotClickable(byId('update-feature-btn')) + await closeModal() + await logout() log('User with permissions can view identities') await login(E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS, PASSWORD) diff --git a/frontend/web/components/pages/UsersPage.tsx b/frontend/web/components/pages/UsersPage.tsx index d19b43dc6d0a..09c8bec0eb62 100644 --- a/frontend/web/components/pages/UsersPage.tsx +++ b/frontend/web/components/pages/UsersPage.tsx @@ -138,7 +138,7 @@ const UsersPage: FC = (props) => {