123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {reactHooks} from 'sentry-test/reactTestingLibrary';
- import usePerformanceOnboardingDocs, {
- generateOnboardingDocKeys,
- } from 'sentry/components/performanceOnboarding/usePerformanceOnboardingDocs';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- describe('usePerformanceOnboardingDocs', function () {
- it('fetches onboarding documentation steps', async function () {
- const {organization} = initializeOrg({
- router: {
- location: {query: {}, search: ''},
- push: jest.fn(),
- },
- } as any);
- const wrapper = ({children}) => (
- <OrganizationContext.Provider value={organization}>
- {children}
- </OrganizationContext.Provider>
- );
- const project = TestStubs.Project({
- platform: 'javascript-react',
- firstTransactionEvent: false,
- });
- const apiMocks: any = {};
- const docKeys = generateOnboardingDocKeys(project.platform);
- expect(docKeys).toEqual([
- 'javascript-react-performance-onboarding-1-install',
- 'javascript-react-performance-onboarding-2-configure',
- 'javascript-react-performance-onboarding-3-verify',
- ]);
- docKeys.forEach(docKey => {
- apiMocks[docKey] = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
- method: 'GET',
- body: {html: `${docKey} content`},
- });
- });
- const {result, waitForNextUpdate} = reactHooks.renderHook(
- () => usePerformanceOnboardingDocs(project),
- {
- wrapper,
- }
- );
- await waitForNextUpdate();
- const {docContents, isLoading, hasOnboardingContents} = result.current;
- expect(isLoading).toEqual(false);
- const expectedDocContents = Object.keys(apiMocks).reduce((acc, key) => {
- acc[key] = `${key} content`;
- return acc;
- }, {});
- expect(docContents).toEqual(expectedDocContents);
- expect(hasOnboardingContents).toEqual(true);
- Object.values(apiMocks).forEach(mock => {
- expect(mock).toHaveBeenCalled();
- });
- });
- it('project with no onboarding support', function () {
- const {organization} = initializeOrg({
- router: {
- location: {query: {}, search: ''},
- push: jest.fn(),
- },
- } as any);
- const wrapper = ({children}) => (
- <OrganizationContext.Provider value={organization}>
- {children}
- </OrganizationContext.Provider>
- );
- const project = TestStubs.Project({
- platform: 'javascript-angular',
- firstTransactionEvent: false,
- });
- const apiMocks: any = {};
- const docKeys = generateOnboardingDocKeys(project.platform);
- expect(docKeys).toEqual([
- 'javascript-angular-performance-onboarding-1-install',
- 'javascript-angular-performance-onboarding-2-configure',
- 'javascript-angular-performance-onboarding-3-verify',
- ]);
- docKeys.forEach(docKey => {
- apiMocks[docKey] = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
- method: 'GET',
- body: {html: `${docKey} content`},
- });
- });
- const {result} = reactHooks.renderHook(() => usePerformanceOnboardingDocs(project), {
- wrapper,
- });
- const {docContents, isLoading, hasOnboardingContents} = result.current;
- expect(isLoading).toEqual(false);
- expect(docContents).toEqual({});
- expect(hasOnboardingContents).toEqual(false);
- Object.values(apiMocks).forEach(mock => {
- expect(mock).not.toHaveBeenCalled();
- });
- });
- it('project with no performance support', function () {
- const {organization} = initializeOrg({
- router: {
- location: {query: {}, search: ''},
- push: jest.fn(),
- },
- } as any);
- const wrapper = ({children}) => (
- <OrganizationContext.Provider value={organization}>
- {children}
- </OrganizationContext.Provider>
- );
- const project = TestStubs.Project({
- platform: 'elixir',
- firstTransactionEvent: false,
- });
- const apiMocks: any = {};
- const docKeys = generateOnboardingDocKeys(project.platform);
- expect(docKeys).toEqual([
- 'elixir-performance-onboarding-1-install',
- 'elixir-performance-onboarding-2-configure',
- 'elixir-performance-onboarding-3-verify',
- ]);
- docKeys.forEach(docKey => {
- apiMocks[docKey] = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
- method: 'GET',
- body: {html: `${docKey} content`},
- });
- });
- const {result} = reactHooks.renderHook(() => usePerformanceOnboardingDocs(project), {
- wrapper,
- });
- const {docContents, isLoading, hasOnboardingContents} = result.current;
- expect(isLoading).toEqual(false);
- expect(docContents).toEqual({});
- expect(hasOnboardingContents).toEqual(false);
- Object.values(apiMocks).forEach(mock => {
- expect(mock).not.toHaveBeenCalled();
- });
- });
- });
|