import {Component} from 'react'; import {RouteContextInterface} from 'react-router'; import {LocationFixture} from 'sentry-fixture/locationFixture'; import {OrganizationFixture} from 'sentry-fixture/organization'; import {ProjectFixture} from 'sentry-fixture/project'; import {RouterFixture} from 'sentry-fixture/routerFixture'; import {TeamFixture} from 'sentry-fixture/team'; import {UserFixture} from 'sentry-fixture/user'; import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary'; import * as orgsActionCreators from 'sentry/actionCreators/organizations'; import {openSudo} from 'sentry/actionCreators/sudoModal'; import {SentryPropTypeValidators} from 'sentry/sentryPropTypeValidators'; import ConfigStore from 'sentry/stores/configStore'; import OrganizationStore from 'sentry/stores/organizationStore'; import ProjectsStore from 'sentry/stores/projectsStore'; import TeamStore from 'sentry/stores/teamStore'; import {Organization} from 'sentry/types'; import useOrganization from 'sentry/utils/useOrganization'; import {OrganizationContextProvider, useEnsureOrganization} from './organizationContext'; import {RouteContext} from './routeContext'; jest.mock('sentry/actionCreators/sudoModal'); describe('OrganizationContext', function () { let getOrgMock: jest.Mock; let getProjectsMock: jest.Mock; let getTeamsMock: jest.Mock; const organization = OrganizationFixture(); const project = ProjectFixture(); const team = TeamFixture(); const router: RouteContextInterface = { router: RouterFixture(), location: LocationFixture(), routes: [], params: {orgId: organization.slug}, }; function setupOrgMocks(org: Organization) { const orgMock = MockApiClient.addMockResponse({ url: `/organizations/${org.slug}/`, body: org, }); const projectMock = MockApiClient.addMockResponse({ url: `/organizations/${org.slug}/projects/`, body: [project], }); const teamMock = MockApiClient.addMockResponse({ url: `/organizations/${org.slug}/teams/`, body: [team], }); return {orgMock, projectMock, teamMock}; } beforeEach(function () { MockApiClient.clearMockResponses(); const {orgMock, projectMock, teamMock} = setupOrgMocks(organization); getOrgMock = orgMock; getProjectsMock = projectMock; getTeamsMock = teamMock; jest.spyOn(TeamStore, 'loadInitialData'); jest.spyOn(ProjectsStore, 'loadInitialData'); ConfigStore.init(); OrganizationStore.reset(); jest.spyOn(console, 'error').mockImplementation(jest.fn()); }); afterEach(function () { // eslint-disable-next-line no-console jest.mocked(console.error).mockRestore(); }); function OrganizationLoaderStub() { useEnsureOrganization(); return null; } /** * Used to test that the organization context is propegated */ function OrganizationName() { const org = useOrganization({allowNull: true}); return