Skip to content

Commit b70515f

Browse files
committed
test(onboarding): Update SCM tests to use experiment fixture
The SCM onboarding flow is now gated by useExperiment instead of a feature flag. Update the test to use experiments on the org fixture and register a minimal useExperiment hook in HookStore, since gsApp's registerHooks() doesn't run in the test environment.
1 parent 99a700a commit b70515f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

static/app/views/onboarding/onboarding.spec.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ import {
2222
useOnboardingContext,
2323
} from 'sentry/components/onboarding/onboardingContext';
2424
import * as useRecentCreatedProjectHook from 'sentry/components/onboarding/useRecentCreatedProject';
25+
import {HookStore} from 'sentry/stores/hookStore';
2526
import {OnboardingDrawerStore} from 'sentry/stores/onboardingDrawerStore';
2627
import {ProjectsStore} from 'sentry/stores/projectsStore';
2728
import {TeamStore} from 'sentry/stores/teamStore';
2829
import type {PlatformKey} from 'sentry/types/project';
2930
import {trackAnalytics} from 'sentry/utils/analytics';
31+
import type {UseExperimentOptions} from 'sentry/utils/useExperiment';
32+
import {useOrganization} from 'sentry/utils/useOrganization';
3033
import {OnboardingWithoutContext} from 'sentry/views/onboarding/onboarding';
3134

3235
jest.mock('sentry/utils/analytics');
@@ -630,7 +633,7 @@ describe('Onboarding', () => {
630633

631634
describe('SCM onboarding flow', () => {
632635
const scmOrganization = OrganizationFixture({
633-
features: ['onboarding-scm'],
636+
experiments: {'onboarding-scm-experiment': 'active'},
634637
});
635638

636639
const githubProvider = GitHubIntegrationProviderFixture({
@@ -646,7 +649,19 @@ describe('Onboarding', () => {
646649
link: 'https://docs.sentry.io/platforms/javascript/guides/nextjs/',
647650
};
648651

652+
// In production, gsApp's registerHooks() registers the real useExperiment
653+
// hook into HookStore. That doesn't run in tests, so useExperiment falls
654+
// back to a noop that always returns inExperiment: false. We register a
655+
// minimal implementation here (can't import the real one due to boundary
656+
// lint rules).
657+
function useTestExperiment(options: UseExperimentOptions) {
658+
const organization = useOrganization();
659+
const assignment = organization.experiments?.[options.feature] ?? 'control';
660+
return {inExperiment: assignment === 'active', experimentAssignment: assignment};
661+
}
662+
649663
beforeEach(() => {
664+
HookStore.add('react-hook:use-experiment', useTestExperiment);
650665
MockApiClient.addMockResponse({
651666
url: `/organizations/${scmOrganization.slug}/config/integrations/`,
652667
body: {providers: [githubProvider]},
@@ -661,6 +676,10 @@ describe('Onboarding', () => {
661676
});
662677
});
663678

679+
afterEach(() => {
680+
HookStore.remove('react-hook:use-experiment', useTestExperiment);
681+
});
682+
664683
function renderOnboarding(
665684
step: string,
666685
options?: {

0 commit comments

Comments
 (0)