Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 62 additions & 130 deletions static/app/views/alerts/list/rules/alertRulesList.spec.tsx

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions static/app/views/auth/loginForm.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {RouterFixture} from 'sentry-fixture/routerFixture';

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

import ConfigStore from 'sentry/stores/configStore';
Expand Down Expand Up @@ -32,16 +30,13 @@ describe('LoginForm', () => {
},
});

render(<LoginForm authConfig={emptyAuthConfig} />, {
deprecatedRouterMocks: true,
});
render(<LoginForm authConfig={emptyAuthConfig} />);
await doLogin();

expect(await screen.findByText('Bad username password')).toBeInTheDocument();
});

it('handles success', async () => {
const router = RouterFixture();
const userObject = {
id: 1,
name: 'Joe',
Expand All @@ -57,10 +52,7 @@ describe('LoginForm', () => {
},
});

render(<LoginForm authConfig={emptyAuthConfig} />, {
router,
deprecatedRouterMocks: true,
});
const {router} = render(<LoginForm authConfig={emptyAuthConfig} />);
await doLogin();

expect(mockRequest).toHaveBeenCalledWith(
Expand All @@ -71,7 +63,7 @@ describe('LoginForm', () => {
);

await waitFor(() => expect(ConfigStore.get('user')).toEqual(userObject));
expect(router.push).toHaveBeenCalledWith({pathname: '/next/'});
expect(router.location.pathname).toBe('/next/');
});

it('renders login provider buttons', () => {
Expand All @@ -81,9 +73,7 @@ describe('LoginForm', () => {
githubLoginLink: '/githubLogin',
};

render(<LoginForm authConfig={authConfig} />, {
deprecatedRouterMocks: true,
});
render(<LoginForm authConfig={authConfig} />);

expect(screen.getByText('Sign in with GitHub')).toBeInTheDocument();
expect(screen.getByText('Sign in with Azure DevOps')).toBeInTheDocument();
Expand Down
14 changes: 3 additions & 11 deletions static/app/views/auth/registerForm.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {RouterFixture} from 'sentry-fixture/routerFixture';

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

import ConfigStore from 'sentry/stores/configStore';
Expand Down Expand Up @@ -46,16 +44,13 @@ describe('Register', () => {
},
});

render(<RegisterForm authConfig={emptyAuthConfig} />, {
deprecatedRouterMocks: true,
});
render(<RegisterForm authConfig={emptyAuthConfig} />);
await doLogin(mockRequest);

expect(await screen.findByText('Registration failed')).toBeInTheDocument();
});

it('handles success', async () => {
const router = RouterFixture();
const userObject = {
id: 1,
name: 'Joe',
Expand All @@ -71,13 +66,10 @@ describe('Register', () => {
},
});

render(<RegisterForm authConfig={emptyAuthConfig} />, {
router,
deprecatedRouterMocks: true,
});
const {router} = render(<RegisterForm authConfig={emptyAuthConfig} />);
await doLogin(mockRequest);

await waitFor(() => expect(ConfigStore.get('user')).toEqual(userObject));
expect(router.push).toHaveBeenCalledWith({pathname: '/next/'});
expect(router.location.pathname).toBe('/next/');
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {OrganizationFixture} from 'sentry-fixture/organization';
import {RouterFixture} from 'sentry-fixture/routerFixture';

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

Expand All @@ -14,33 +13,20 @@ jest.mock('sentry/utils/useNavigate', () => ({
const mockUseNavigate = jest.mocked(useNavigate);

describe('DatasetSelector', () => {
let router!: ReturnType<typeof RouterFixture>;
let organization!: ReturnType<typeof OrganizationFixture>;
beforeEach(() => {
router = RouterFixture();
organization = OrganizationFixture();
});

it('changes the dataset', async () => {
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);

render(
<WidgetBuilderProvider>
<DatasetSelector />
</WidgetBuilderProvider>,
{
router,
organization,
deprecatedRouterMocks: true,
}
</WidgetBuilderProvider>
);

await userEvent.click(await screen.findByLabelText('Issues'));

expect(mockNavigate).toHaveBeenCalledWith(
expect.objectContaining({
...router.location,
query: expect.objectContaining({dataset: 'issue'}),
}),
expect.anything()
Expand All @@ -60,9 +46,7 @@ describe('DatasetSelector', () => {
<DatasetSelector />
</WidgetBuilderProvider>,
{
router,
organization: organizationWithDeprecation,
deprecatedRouterMocks: true,
}
);

Expand All @@ -83,7 +67,6 @@ describe('DatasetSelector', () => {
// Verify navigation to spans dataset
expect(mockNavigate).toHaveBeenCalledWith(
expect.objectContaining({
...router.location,
query: expect.objectContaining({dataset: 'spans'}),
}),
expect.anything()
Expand All @@ -103,9 +86,7 @@ describe('DatasetSelector', () => {
<DatasetSelector />
</WidgetBuilderProvider>,
{
router,
organization: organizationWithoutDeprecation,
deprecatedRouterMocks: true,
}
);

Expand All @@ -117,7 +98,6 @@ describe('DatasetSelector', () => {

expect(mockNavigate).toHaveBeenCalledWith(
expect.objectContaining({
...router.location,
query: expect.objectContaining({dataset: 'transaction-like'}),
}),
expect.anything()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {LocationFixture} from 'sentry-fixture/locationFixture';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {RouterFixture} from 'sentry-fixture/routerFixture';

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

Expand Down Expand Up @@ -117,16 +115,17 @@ describe('WidgetBuilderGroupBySelector', () => {
</TraceItemAttributeProvider>
</WidgetBuilderProvider>,
{
organization: organizationWithFeature,
router: RouterFixture({
location: LocationFixture({
initialRouterConfig: {
route: '/organizations/:orgId/dashboard/:dashboardId/',
location: {
pathname: '/organizations/org-slug/dashboard/1/',
query: {
dataset: WidgetType.TRANSACTIONS,
displayType: DisplayType.LINE,
},
}),
}),
deprecatedRouterMocks: true,
},
},
organization: organizationWithFeature,
}
);

Expand All @@ -150,16 +149,17 @@ describe('WidgetBuilderGroupBySelector', () => {
</TraceItemAttributeProvider>
</WidgetBuilderProvider>,
{
organization: organizationWithoutFeature,
router: RouterFixture({
location: LocationFixture({
initialRouterConfig: {
route: '/organizations/:orgId/dashboard/:dashboardId/',
location: {
pathname: '/organizations/org-slug/dashboard/1/',
query: {
dataset: WidgetType.TRANSACTIONS,
displayType: DisplayType.LINE,
},
}),
}),
deprecatedRouterMocks: true,
},
},
organization: organizationWithoutFeature,
}
);

Expand All @@ -182,16 +182,17 @@ describe('WidgetBuilderGroupBySelector', () => {
</TraceItemAttributeProvider>
</WidgetBuilderProvider>,
{
organization: organizationWithFeature,
router: RouterFixture({
location: LocationFixture({
initialRouterConfig: {
route: '/organizations/:orgId/dashboard/:dashboardId/',
location: {
pathname: '/organizations/org-slug/dashboard/1/',
query: {
dataset: WidgetType.ERRORS,
displayType: DisplayType.LINE,
},
}),
}),
deprecatedRouterMocks: true,
},
},
organization: organizationWithFeature,
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,36 @@
import {OrganizationFixture} from 'sentry-fixture/organization';
import {RouterFixture} from 'sentry-fixture/routerFixture';

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

import {useNavigate} from 'sentry/utils/useNavigate';
import WidgetBuilderNameAndDescription from 'sentry/views/dashboards/widgetBuilder/components/nameAndDescFields';
import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';

jest.mock('sentry/utils/useNavigate', () => ({
useNavigate: jest.fn(),
}));

const mockUseNavigate = jest.mocked(useNavigate);

describe('WidgetBuilder', () => {
let router!: ReturnType<typeof RouterFixture>;
let organization!: ReturnType<typeof OrganizationFixture>;
beforeEach(() => {
router = RouterFixture({
location: {
pathname: '/organizations/org-slug/dashboard/1/',
query: {project: '-1'},
},
params: {},
});
organization = OrganizationFixture();
});
const initialRouterConfig = {
route: '/organizations/:orgId/dashboard/:dashboardId/',
location: {
pathname: '/organizations/org-slug/dashboard/1/',
query: {project: '-1'},
},
};

it('edits name and description', async () => {
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);

render(
const {router} = render(
<WidgetBuilderProvider>
<WidgetBuilderNameAndDescription />
</WidgetBuilderProvider>,
{
router,
organization,
deprecatedRouterMocks: true,
initialRouterConfig,
}
);

await userEvent.type(await screen.findByPlaceholderText('Name'), 'some name');

// trigger blur
await userEvent.tab();
expect(mockNavigate).toHaveBeenLastCalledWith(
expect(router.location).toEqual(
expect.objectContaining({
...router.location,
...initialRouterConfig.location,
query: expect.objectContaining({title: 'some name'}),
}),
expect.anything()
})
);

await userEvent.click(await screen.findByTestId('add-description'));
Expand All @@ -63,12 +42,11 @@ describe('WidgetBuilder', () => {

// trigger blur
await userEvent.tab();
expect(mockNavigate).toHaveBeenLastCalledWith(
expect(router.location).toEqual(
expect.objectContaining({
...router.location,
...initialRouterConfig.location,
query: expect.objectContaining({description: 'some description'}),
}),
expect.anything()
})
);
});

Expand All @@ -80,9 +58,7 @@ describe('WidgetBuilder', () => {
/>
</WidgetBuilderProvider>,
{
router,
organization,
deprecatedRouterMocks: true,
initialRouterConfig,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ResourcesLandingPage', () => {
});

it('renders a list of resources', async () => {
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
render(<ResourcesLandingPage />, {organization});
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));

expect(
Expand All @@ -59,7 +59,7 @@ describe('ResourcesLandingPage', () => {
});

it('fetches domain data', async () => {
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
render(<ResourcesLandingPage />, {organization});
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));

expect(requestMocks.domainSelector!.mock.calls).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('ResourcesLandingPage', () => {
});

it('contains correct query in charts', async () => {
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
render(<ResourcesLandingPage />, {organization});
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));

expect(requestMocks.mainTable!.mock.calls).toMatchInlineSnapshot(`
Expand Down
Loading
Loading