-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️(frontend) replace env NEXT_PUBLIC_FEATURE_TEAM
NEXT_PUBLIC_FEATURE_TEAM is a buid-time env variable, it is not easy to overload it per environment. We will use the config endpoint to get the feature flag at runtime. To do so, we are using the ConfigStore.
- Loading branch information
Showing
11 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
NEXT_PUBLIC_API_ORIGIN=http://localhost:8071 | ||
NEXT_PUBLIC_FEATURE_TEAM=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
NEXT_PUBLIC_API_ORIGIN=http://test.jest | ||
NEXT_PUBLIC_FEATURE_TEAM=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { useConfigStore } from '@/core'; | ||
import { AppWrapper } from '@/tests/utils'; | ||
|
||
import Page from '../pages'; | ||
|
||
const mockedPush = jest.fn(); | ||
const mockedUseRouter = jest.fn().mockReturnValue({ | ||
push: mockedPush, | ||
}); | ||
|
||
jest.mock('next/navigation', () => ({ | ||
...jest.requireActual('next/navigation'), | ||
useRouter: () => ({}), | ||
useRouter: () => mockedUseRouter(), | ||
})); | ||
|
||
describe('Page', () => { | ||
it('checks Page rendering', () => { | ||
afterEach(() => jest.clearAllMocks()); | ||
|
||
it('checks Page rendering with team feature', () => { | ||
useConfigStore.setState({ | ||
config: { FEATURES: { TEAMS: true }, LANGUAGES: [] }, | ||
}); | ||
|
||
render(<Page />, { wrapper: AppWrapper }); | ||
|
||
expect(mockedPush).toHaveBeenCalledWith('/teams/'); | ||
}); | ||
|
||
it('checks Page rendering without team feature', () => { | ||
useConfigStore.setState({ | ||
config: { FEATURES: { TEAMS: false }, LANGUAGES: [] }, | ||
}); | ||
|
||
render(<Page />, { wrapper: AppWrapper }); | ||
|
||
expect( | ||
screen.getByRole('button', { | ||
name: /Create a new team/i, | ||
}), | ||
).toBeInTheDocument(); | ||
expect(mockedPush).toHaveBeenCalledWith('/mail-domains/'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
import { keyCloakSignIn } from './common'; | ||
|
||
test.describe('Config', () => { | ||
test.beforeEach(async ({ page, browserName }) => { | ||
await page.goto('/'); | ||
await keyCloakSignIn(page, browserName); | ||
}); | ||
|
||
test('it checks the config api is called', async ({ page }) => { | ||
const responsePromise = page.waitForResponse( | ||
(response) => | ||
response.url().includes('/config/') && response.status() === 200, | ||
); | ||
|
||
const response = await responsePromise; | ||
expect(response.ok()).toBeTruthy(); | ||
|
||
expect(await response.json()).toStrictEqual({ | ||
LANGUAGES: [ | ||
['en-us', 'English'], | ||
['fr-fr', 'French'], | ||
], | ||
FEATURES: { TEAMS: true }, | ||
}); | ||
}); | ||
|
||
test('it checks that the config can deactivate the feature "teams"', async ({ | ||
page, | ||
}) => { | ||
await page.route('**/api/v1.0/config/', async (route) => { | ||
const request = route.request(); | ||
if (request.method().includes('GET')) { | ||
await route.fulfill({ | ||
json: { | ||
LANGUAGES: [ | ||
['en-us', 'English'], | ||
['fr-fr', 'French'], | ||
], | ||
FEATURES: { TEAMS: false }, | ||
}, | ||
}); | ||
} else { | ||
await route.continue(); | ||
} | ||
}); | ||
|
||
await expect(page.locator('menu')).toBeHidden(); | ||
|
||
await expect( | ||
page.getByRole('button', { | ||
name: 'Create a new team', | ||
}), | ||
).toBeHidden(); | ||
|
||
await expect( | ||
page.getByRole('button', { | ||
name: 'Add your mail domain', | ||
}), | ||
).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters