@@ -15,14 +15,19 @@ vi.mock('@/components/settings/standalone-settings-shell', () => ({
1515import AccountSettingsLayout from '@/app/account/settings/layout'
1616import { useFeatureFlag } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider'
1717
18- /** Stands in for the personal API keys page, whose create modal reads this flag on every render. */
19- function ReadOnlyKeysFlag ( ) {
20- return < span > { `read-only keys ${ useFeatureFlag ( 'api-key-read-only' ) ? 'on' : 'off' } ` } </ span >
21- }
22-
23- async function renderAccountSettings ( ) : Promise < string > {
24- const element = await AccountSettingsLayout ( { children : < ReadOnlyKeysFlag /> } )
25- return renderToStaticMarkup ( element )
18+ /**
19+ * Renders the account layout around a section that reads the read-only key flag the way the
20+ * personal API keys page's create modal does on every render, and returns what it read.
21+ */
22+ async function readFlagInAccountSettings ( ) : Promise < boolean > {
23+ let observed : boolean | undefined
24+ function ReadOnlyKeysSection ( ) {
25+ observed = useFeatureFlag ( 'api-key-read-only' )
26+ return null
27+ }
28+ renderToStaticMarkup ( await AccountSettingsLayout ( { children : < ReadOnlyKeysSection /> } ) )
29+ if ( observed === undefined ) throw new Error ( 'The account section never rendered' )
30+ return observed
2631}
2732
2833describe ( 'AccountSettingsLayout' , ( ) => {
@@ -33,13 +38,10 @@ describe('AccountSettingsLayout', () => {
3338 } )
3439 } )
3540
36- it . each ( [
37- [ true , 'on' ] ,
38- [ false , 'off' ] ,
39- ] ) ( 'gives account sections the read-only key flag (%s)' , async ( enabled , rendered ) => {
41+ it . each ( [ true , false ] ) ( 'gives account sections the read-only key flag (%s)' , async ( enabled ) => {
4042 featureFlagsMockFns . mockIsFeatureEnabled . mockImplementation (
4143 async ( flag ) => flag === 'api-key-read-only' && enabled
4244 )
43- expect ( await renderAccountSettings ( ) ) . toContain ( `read-only keys ${ rendered } ` )
45+ expect ( await readFlagInAccountSettings ( ) ) . toBe ( enabled )
4446 } )
4547} )
0 commit comments