Skip to content

Commit

Permalink
test(ui): Add types to test mocks (#79255)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored Oct 17, 2024
1 parent a17ab1d commit 17c7471
Show file tree
Hide file tree
Showing 43 changed files with 143 additions and 107 deletions.
2 changes: 1 addition & 1 deletion static/app/components/modals/widgetViewerModal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jest.mock('echarts-for-react/lib/core', () => {

const stubEl = (props: {children?: React.ReactNode}) => <div>{props.children}</div>;

let eventsMetaMock;
let eventsMetaMock: jest.Mock;

const waitForMetaToHaveBeenCalled = async () => {
await waitFor(() => {
Expand Down
5 changes: 3 additions & 2 deletions static/app/components/quickTrace/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {render, screen} from 'sentry-test/reactTestingLibrary';

import QuickTrace from 'sentry/components/quickTrace';
import type {Event} from 'sentry/types/event';
import type {Organization} from 'sentry/types/organization';
import type {QuickTraceEvent} from 'sentry/utils/performance/quickTrace/types';

describe('Quick Trace', function () {
let location;
let organization;
let location: any;
let organization: Organization;

const initialize = () => {
const context = initializeOrg();
Expand Down
14 changes: 7 additions & 7 deletions static/app/components/search/sources/apiSource.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import ConfigStore from 'sentry/stores/configStore';

describe('ApiSource', function () {
const {organization, router} = initializeOrg();
let orgsMock;
let projectsMock;
let teamsMock;
let membersMock;
let shortIdMock;
let eventIdMock;
let configState;
let orgsMock: jest.Mock;
let projectsMock: jest.Mock;
let teamsMock: jest.Mock;
let membersMock: jest.Mock;
let shortIdMock: jest.Mock;
let eventIdMock: jest.Mock;
let configState: ReturnType<typeof ConfigStore.getState>;

const defaultProps: ComponentProps<typeof ApiSource> = {
query: '',
Expand Down
2 changes: 1 addition & 1 deletion static/app/stores/groupingStore.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as GroupActionCreators from 'sentry/actionCreators/group';
import GroupingStore from 'sentry/stores/groupingStore';

describe('Grouping Store', function () {
let trigger;
let trigger!: jest.SpyInstance;

beforeAll(function () {
MockApiClient.asyncDelay = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('replayPlayerEventsContext', () => {
errors: [],
replayRecord: ReplayRecordFixture(),
});
const mockRRwebFrames = [];
const mockRRwebFrames: any[] = [];
mockReplay!.getRRWebFrames = jest.fn().mockReturnValue(mockRRwebFrames);

const {result} = renderHook(useReplayPlayerEvents, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('replayPlayerPluginsContext', () => {

it('should return no plugins if you dont use the Provider', () => {
const mockOrganization = OrganizationFixture();
const mockEvents = [];
const mockEvents: any[] = [];

const {result} = renderHook(useReplayPlayerPlugins, {
wrapper: ({children}: {children?: ReactNode}) => (
Expand All @@ -57,7 +57,7 @@ describe('replayPlayerPluginsContext', () => {
const mockOrganizationWithCanvas = OrganizationFixture({
features: ['session-replay-enable-canvas-replayer'],
});
const mockEvents = [];
const mockEvents: any[] = [];

const {result: noCanvasResult} = renderHook(useReplayPlayerPlugins, {
wrapper: makeWrapper(mockOrganizationNoCanvas),
Expand Down
3 changes: 2 additions & 1 deletion static/app/views/dashboards/dashboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ describe('Dashboards > Dashboard', () => {
],
};

let initialData, tagsMock;
let initialData: ReturnType<typeof initializeOrg>;
let tagsMock: jest.Mock;

beforeEach(() => {
initialData = initializeOrg({organization, router: {}, projects: []});
Expand Down
7 changes: 5 additions & 2 deletions static/app/views/dashboards/manage/dashboardList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import {
} from 'sentry-test/reactTestingLibrary';

import DashboardList from 'sentry/views/dashboards/manage/dashboardList';
import {DisplayType} from 'sentry/views/dashboards/types';
import {type DashboardListItem, DisplayType} from 'sentry/views/dashboards/types';

describe('Dashboards - DashboardList', function () {
let dashboards, deleteMock, dashboardUpdateMock, createMock;
let dashboards: DashboardListItem[];
let deleteMock: jest.Mock;
let dashboardUpdateMock: jest.Mock;
let createMock: jest.Mock;
const organization = OrganizationFixture({
features: ['global-views', 'dashboards-basic', 'dashboards-edit', 'discover-query'],
});
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/dashboards/widgetCard/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Dashboards > WidgetCard', function () {
};

const api = new MockApiClient();
let eventsMock;
let eventsMock: jest.Mock;

beforeEach(function () {
MockApiClient.addMockResponse({
Expand Down
18 changes: 9 additions & 9 deletions static/app/views/discover/savedQuery/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';

import {openAddToDashboardModal} from 'sentry/actionCreators/modal';
import type {NewQuery} from 'sentry/types/organization';
import type {NewQuery, Organization, SavedQuery} from 'sentry/types/organization';
import EventView from 'sentry/utils/discover/eventView';
import {DisplayModes, SavedQueryDatasets} from 'sentry/utils/discover/types';
import {WidgetType} from 'sentry/views/dashboards/types';
Expand Down Expand Up @@ -41,12 +41,12 @@ function mount(
}

describe('Discover > SaveQueryButtonGroup', function () {
let organization,
errorsView,
savedQuery,
errorsViewSaved,
errorsViewModified,
errorsQuery;
let organization: Organization;
let errorsView: EventView;
let savedQuery: SavedQuery;
let errorsViewSaved: EventView;
let errorsViewModified: EventView;
let errorsQuery: NewQuery;
const location = {
pathname: '/organization/eventsv2/',
query: {},
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('Discover > SaveQueryButtonGroup', function () {
});

describe('viewing a saved query', () => {
let mockUtils;
let mockUtils: jest.SpyInstance;

beforeEach(() => {
mockUtils = jest
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('Discover > SaveQueryButtonGroup', function () {
});

describe('modifying a saved query', () => {
let mockUtils;
let mockUtils: jest.SpyInstance;

it('renders the correct set of buttons', async () => {
mount(
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/discover/savedQuery/utils.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('SavedQueries API helpers', () => {
errorsView.id = '1'; // set id manually as errorsView.id is undefined
const yAxis = ['count()', 'failure_count()'];

let mockCall;
let mockCall: jest.Mock;

afterEach(() => {
MockApiClient.clearMockResponses();
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/discover/table/cellAction.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Discover -> CellAction', function () {
});

describe('per cell actions', function () {
let handleCellAction;
let handleCellAction!: jest.Mock;

beforeEach(function () {
handleCellAction = jest.fn();
Expand Down
6 changes: 3 additions & 3 deletions static/app/views/discover/table/columnEditModal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {QueryFieldValue} from 'sentry/utils/discover/fields';
import {DiscoverDatasets} from 'sentry/utils/discover/types';
import ColumnEditModal from 'sentry/views/discover/table/columnEditModal';

const stubEl = styled(p => p.children);
const stubEl = styled((p: any) => p.children);

function mountModal(
{
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('Discover -> ColumnEditModal', function () {
});

describe('function & column selection', function () {
let onApply;
let onApply!: jest.Mock;
beforeEach(function () {
onApply = jest.fn();
});
Expand Down Expand Up @@ -632,7 +632,7 @@ describe('Discover -> ColumnEditModal', function () {
});

describe('equation automatic update', function () {
let onApply;
let onApply!: jest.Mock;
beforeEach(function () {
onApply = jest.fn();
});
Expand Down
13 changes: 10 additions & 3 deletions static/app/views/discover/table/tableView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import {act, render, screen, userEvent, within} from 'sentry-test/reactTestingLi
import ProjectsStore from 'sentry/stores/projectsStore';
import TagStore from 'sentry/stores/tagStore';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {TableData} from 'sentry/utils/discover/discoverQuery';
import EventView from 'sentry/utils/discover/eventView';
import {SavedQueryDatasets} from 'sentry/utils/discover/types';
import TableView from 'sentry/views/discover/table/tableView';

describe('TableView > CellActions', function () {
let initialData, rows, onChangeShowTags;
let initialData: ReturnType<typeof initializeOrg>;
let rows: any;
let onChangeShowTags: jest.Mock;

const location = LocationFixture({
pathname: '/organizations/org-slug/discover/results/',
Expand All @@ -37,7 +40,11 @@ describe('TableView > CellActions', function () {
});
const eventView = EventView.fromLocation(location);

function renderComponent(context, tableData, view) {
function renderComponent(
context: ReturnType<typeof initializeOrg>,
tableData: TableData,
view: EventView
) {
return render(
<TableView
organization={context.organization}
Expand All @@ -57,7 +64,7 @@ describe('TableView > CellActions', function () {
);
}

async function openContextMenu(cellIndex) {
async function openContextMenu(cellIndex: number) {
const firstRow = screen.getAllByRole('row')[1];
const emptyValueCell = within(firstRow).getAllByRole('cell')[cellIndex];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('PagePerformanceTable', function () {
const organization = OrganizationFixture();
const router = RouterFixture();

let eventsMock;
let eventsMock: jest.Mock;

beforeEach(function () {
jest.mocked(useLocation).mockReturnValue(router.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jest.mock('sentry/views/insights/common/queries/useOnboardingProject');
describe('DatabaseLandingPage', function () {
const organization = OrganizationFixture();

let spanListRequestMock, spanChartsRequestMock;
let spanListRequestMock: jest.Mock;
let spanChartsRequestMock: jest.Mock;

jest.mocked(useProjects).mockReturnValue({
projects: [ProjectFixture({hasInsightsDb: true})],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('sentry/utils/usePageFilters');
describe('HTTPSamplesPanel', () => {
const organization = OrganizationFixture();

let eventsRequestMock;
let eventsRequestMock: jest.Mock;

jest.mocked(usePageFilters).mockReturnValue({
isReady: true,
Expand Down Expand Up @@ -95,7 +95,9 @@ describe('HTTPSamplesPanel', () => {
});

describe('Status panel', () => {
let eventsStatsRequestMock, samplesRequestMock, spanFieldTagsMock;
let eventsStatsRequestMock: jest.Mock;
let samplesRequestMock: jest.Mock;
let spanFieldTagsMock: jest.Mock;

beforeEach(() => {
jest.mocked(useLocation).mockReturnValue({
Expand Down Expand Up @@ -307,7 +309,9 @@ describe('HTTPSamplesPanel', () => {
});

describe('Duration panel', () => {
let chartRequestMock, samplesRequestMock, spanFieldTagsMock;
let chartRequestMock: jest.Mock;
let samplesRequestMock: jest.Mock;
let spanFieldTagsMock: jest.Mock;

beforeEach(() => {
jest.mocked(useLocation).mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {ProjectFixture} from 'sentry-fixture/project';

import {render, screen, waitFor, within} from 'sentry-test/reactTestingLibrary';

import type {Organization} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {browserHistory} from 'sentry/utils/browserHistory';
import localStorage from 'sentry/utils/localStorage';
import {useLocation} from 'sentry/utils/useLocation';
Expand All @@ -17,7 +19,7 @@ jest.mock('sentry/utils/useLocation');
jest.mock('sentry/utils/usePageFilters');
jest.mock('sentry/utils/useProjects');

function mockResponses(organization, project) {
function mockResponses(organization: Organization, project: Project) {
jest.mocked(useOnboardingProject).mockReturnValue(undefined);

jest.mocked(useProjects).mockReturnValue({
Expand Down Expand Up @@ -109,9 +111,9 @@ function mockResponses(organization, project) {

describe('Screen Summary', function () {
describe('Cross Platform Project', function () {
let eventsMock;
let eventsStatsMock;
let organization;
let eventsMock: jest.Mock;
let eventsStatsMock: jest.Mock;
let organization: Organization;
beforeEach(function () {
const project = ProjectFixture({
platform: 'react-native',
Expand Down Expand Up @@ -205,9 +207,9 @@ describe('Screen Summary', function () {
});

describe('Native Project', function () {
let eventsMock;
let eventsStatsMock;
let organization;
let eventsMock: jest.Mock;
let eventsStatsMock: jest.Mock;
let organization: Organization;
beforeEach(function () {
const project = ProjectFixture({platform: 'android', hasInsightsScreenLoad: true});
organization = OrganizationFixture({features: ['insights-initial-modules']});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('PageloadModule', function () {
},
});

let eventsMock;
let eventsMock: jest.Mock;
beforeEach(function () {
localStorage.clear();
browserHistory.push = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Referrer} from 'sentry/views/insights/queues/referrers';
describe('latencyChart', () => {
const organization = OrganizationFixture();

let eventsStatsMock;
let eventsStatsMock: jest.Mock;

beforeEach(() => {
eventsStatsMock = MockApiClient.addMockResponse({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ jest.mock('sentry/utils/usePageFilters');
describe('messageSpanSamplesPanel', () => {
const organization = OrganizationFixture();

let eventsRequestMock, eventsStatsRequestMock, samplesRequestMock, spanFieldTagsMock;
let eventsRequestMock: jest.Mock;
let eventsStatsRequestMock: jest.Mock;
let samplesRequestMock: jest.Mock;
let spanFieldTagsMock: jest.Mock;

jest.mocked(usePageFilters).mockReturnValue({
isReady: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SpanIndexedField} from 'sentry/views/insights/types';
describe('queuesTable', () => {
const organization = OrganizationFixture();

let eventsMock;
let eventsMock: jest.Mock;

const pageLinks =
'<https://sentry.io/fake/previous>; rel="previous"; results="false"; cursor="0:0:1", ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('sentry/utils/useLocation');
describe('transactionsTable', () => {
const organization = OrganizationFixture();

let eventsMock;
let eventsMock: jest.Mock;

const pageLinks =
'<https://sentry.io/fake/previous>; rel="previous"; results="false"; cursor="0:0:1", ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ describe('destinationSummaryPage', () => {
initiallyLoaded: false,
});

let eventsMock, eventsStatsMock, spanFieldTagsMock;
let eventsMock: jest.Mock;
let eventsStatsMock: jest.Mock;
let spanFieldTagsMock: jest.Mock;

beforeEach(() => {
eventsMock = MockApiClient.addMockResponse({
Expand Down
Loading

0 comments on commit 17c7471

Please sign in to comment.