-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: changed the way feature flags are provided to app
- Loading branch information
1 parent
d93f5cf
commit 65130dd
Showing
6 changed files
with
31 additions
and
140 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
export type FeatureFlag = 'useNewConnectionForm'; | ||
export type FeatureFlags = Record<FeatureFlag, boolean>; | ||
export const getFeatureFlags = (): FeatureFlags => ({ | ||
const FEATURE_FLAGS = { | ||
useNewConnectionForm: `${process.env.MDB_USE_NEW_CONNECTION_FORM}` === 'true', | ||
}); | ||
}; | ||
|
||
export type FeatureFlag = keyof typeof FEATURE_FLAGS; | ||
|
||
export const getFeatureFlag = (flag: FeatureFlag) => { | ||
if (typeof window === 'object') { | ||
return (window as any).MDB_FEATURE_FLAGS?.[flag]; | ||
} | ||
return FEATURE_FLAGS[flag]; | ||
}; | ||
|
||
export const getFeatureFlagsScript = (nonce: string) => { | ||
return ` | ||
<script nonce="${nonce}">window['MDB_FEATURE_FLAGS']=${JSON.stringify( | ||
FEATURE_FLAGS | ||
)}</script> | ||
`; | ||
}; |
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,53 +1,21 @@ | ||
import assert from 'assert'; | ||
import * as React from 'react'; | ||
import sinon from 'sinon'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import * as featureFlags from '../../../../featureFlags'; | ||
import { render, screen } from '@testing-library/react'; | ||
import App from '../../../../views/webview-app/app'; | ||
import { MESSAGE_TYPES } from '../../../../views/webview-app/extension-app-message-constants'; | ||
|
||
describe('App Component Test Suite', () => { | ||
let fakeVscodeWindowPostMessage; | ||
let fakeOnEventFunction; | ||
let fakeAddEventListener; | ||
|
||
beforeEach(() => { | ||
fakeVscodeWindowPostMessage = sinon.fake.returns(null); | ||
fakeAddEventListener = (eventName, eventFn): void => { | ||
if (eventName === 'message') { | ||
fakeOnEventFunction = eventFn; | ||
} | ||
}; | ||
|
||
sinon.replace( | ||
(global as any).vscodeFake, | ||
'postMessage', | ||
fakeVscodeWindowPostMessage | ||
); | ||
|
||
sinon.replace(window, 'addEventListener', fakeAddEventListener); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
afterEach(() => sinon.restore()); | ||
test('it renders the old overview page when useNewConnectionForm is falsy', () => { | ||
sinon.stub(featureFlags, 'getFeatureFlag').returns(false); | ||
render(<App />); | ||
assert.doesNotThrow(() => screen.getAllByTestId('legacy-app')); | ||
}); | ||
|
||
test('it renders the new overview page when useNewConnectionForm is truthy', () => { | ||
sinon.stub(featureFlags, 'getFeatureFlag').returns(true); | ||
render(<App />); | ||
act(() => { | ||
fakeOnEventFunction({ | ||
data: { | ||
command: MESSAGE_TYPES.FEATURE_FLAGS_RESULTS, | ||
featureFlags: { | ||
useNewConnectionForm: true, | ||
}, | ||
}, | ||
}); | ||
}); | ||
assert.throws(() => screen.getAllByTestId('legacy-app')); | ||
}); | ||
}); |
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