|
@@ -9,7 +9,7 @@ jest.mock('sentry/utils/useMedia', () => ({
|
|
|
default: jest.fn(() => true),
|
|
|
}));
|
|
|
|
|
|
-const mockEventsUrl = '/organizations/org-slug/events/';
|
|
|
+const mockReplayCountUrl = '/organizations/org-slug/replay-count/';
|
|
|
const mockReplayUrl = '/organizations/org-slug/replays/';
|
|
|
|
|
|
type InitializeOrgProps = {
|
|
@@ -18,6 +18,9 @@ type InitializeOrgProps = {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+const REPLAY_ID_1 = '346789a703f6454384f1de473b8b9fcc';
|
|
|
+const REPLAY_ID_2 = 'b05dae9b6be54d21a4d5ad9f8f02b780';
|
|
|
+
|
|
|
function init({
|
|
|
organizationProps = {features: ['session-replay-ui']},
|
|
|
}: InitializeOrgProps) {
|
|
@@ -75,16 +78,13 @@ describe('GroupReplays', () => {
|
|
|
describe('Replay Feature Enabled', () => {
|
|
|
const {router, organization, routerContext} = init({});
|
|
|
|
|
|
- it('should query the events endpoint with the fetched replayIds', async () => {
|
|
|
+ it('should query the replay-count endpoint with the fetched replayIds', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -102,16 +102,14 @@ describe('GroupReplays', () => {
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledWith(
|
|
|
- mockEventsUrl,
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledWith(
|
|
|
+ mockReplayCountUrl,
|
|
|
expect.objectContaining({
|
|
|
query: {
|
|
|
- environment: [],
|
|
|
- field: ['replayId', 'count()'],
|
|
|
- per_page: 50,
|
|
|
- project: ['2'],
|
|
|
- query: `issue.id:${mockGroup.id} !replayId:""`,
|
|
|
+ returnIds: true,
|
|
|
+ query: `issue.id:[${mockGroup.id}]`,
|
|
|
statsPeriod: '14d',
|
|
|
+ project: '2',
|
|
|
},
|
|
|
})
|
|
|
);
|
|
@@ -134,8 +132,7 @@ describe('GroupReplays', () => {
|
|
|
],
|
|
|
per_page: 50,
|
|
|
project: ['2'],
|
|
|
- query:
|
|
|
- 'id:[346789a703f6454384f1de473b8b9fcc,b05dae9b6be54d21a4d5ad9f8f02b780]',
|
|
|
+ query: `id:[${REPLAY_ID_1},${REPLAY_ID_2}]`,
|
|
|
sort: '-started_at',
|
|
|
statsPeriod: '14d',
|
|
|
}),
|
|
@@ -147,13 +144,10 @@ describe('GroupReplays', () => {
|
|
|
it('should show empty message when no replays are found', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -173,7 +167,7 @@ describe('GroupReplays', () => {
|
|
|
expect(
|
|
|
await screen.findByText('There are no items to display')
|
|
|
).toBeInTheDocument();
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledTimes(1);
|
|
|
expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
expect(container).toSnapshot();
|
|
|
});
|
|
@@ -181,13 +175,10 @@ describe('GroupReplays', () => {
|
|
|
it('should display error message when api call fails', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -206,7 +197,7 @@ describe('GroupReplays', () => {
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledTimes(1);
|
|
|
expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
expect(
|
|
|
screen.getByText('Invalid number: asdf. Expected number.')
|
|
@@ -217,13 +208,10 @@ describe('GroupReplays', () => {
|
|
|
it('should display default error message when api call fails without a body', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -240,7 +228,7 @@ describe('GroupReplays', () => {
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledTimes(1);
|
|
|
expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
expect(
|
|
|
screen.getByText(
|
|
@@ -253,13 +241,10 @@ describe('GroupReplays', () => {
|
|
|
it('should show loading indicator when loading replays', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -279,7 +264,7 @@ describe('GroupReplays', () => {
|
|
|
|
|
|
expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
|
|
|
await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledTimes(1);
|
|
|
expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
});
|
|
|
});
|
|
@@ -287,13 +272,10 @@ describe('GroupReplays', () => {
|
|
|
it('should show a list of replays and have the correct values', async () => {
|
|
|
const mockGroup = TestStubs.Group();
|
|
|
|
|
|
- const mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
+ const mockReplayCountApi = MockApiClient.addMockResponse({
|
|
|
+ url: mockReplayCountUrl,
|
|
|
body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
+ [mockGroup.id]: [REPLAY_ID_1, REPLAY_ID_2],
|
|
|
},
|
|
|
});
|
|
|
|
|
@@ -306,7 +288,7 @@ describe('GroupReplays', () => {
|
|
|
count_errors: 1,
|
|
|
duration: 52346,
|
|
|
finished_at: '2022-09-15T06:54:00+00:00',
|
|
|
- id: '346789a703f6454384f1de473b8b9fcc',
|
|
|
+ id: REPLAY_ID_1,
|
|
|
project_id: '2',
|
|
|
started_at: '2022-09-15T06:50:03+00:00',
|
|
|
urls: [
|
|
@@ -325,7 +307,7 @@ describe('GroupReplays', () => {
|
|
|
count_errors: 4,
|
|
|
duration: 400,
|
|
|
finished_at: '2022-09-21T21:40:38+00:00',
|
|
|
- id: 'b05dae9b6be54d21a4d5ad9f8f02b780',
|
|
|
+ id: REPLAY_ID_2,
|
|
|
project_id: '2',
|
|
|
started_at: '2022-09-21T21:30:44+00:00',
|
|
|
urls: [
|
|
@@ -355,7 +337,7 @@ describe('GroupReplays', () => {
|
|
|
});
|
|
|
|
|
|
await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
+ expect(mockReplayCountApi).toHaveBeenCalledTimes(1);
|
|
|
expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
});
|
|
|
|
|
@@ -368,13 +350,13 @@ describe('GroupReplays', () => {
|
|
|
// Expect the first row to have the correct href
|
|
|
expect(screen.getAllByRole('link', {name: 'testDisplayName'})[0]).toHaveAttribute(
|
|
|
'href',
|
|
|
- `/organizations/org-slug/replays/project-slug:346789a703f6454384f1de473b8b9fcc/?${expectedQuery}`
|
|
|
+ `/organizations/org-slug/replays/project-slug:${REPLAY_ID_1}/?${expectedQuery}`
|
|
|
);
|
|
|
|
|
|
// Expect the second row to have the correct href
|
|
|
expect(screen.getAllByRole('link', {name: 'testDisplayName'})[1]).toHaveAttribute(
|
|
|
'href',
|
|
|
- `/organizations/org-slug/replays/project-slug:b05dae9b6be54d21a4d5ad9f8f02b780/?${expectedQuery}`
|
|
|
+ `/organizations/org-slug/replays/project-slug:${REPLAY_ID_2}/?${expectedQuery}`
|
|
|
);
|
|
|
|
|
|
// Expect the first row to have the correct duration
|
|
@@ -400,69 +382,4 @@ describe('GroupReplays', () => {
|
|
|
expect(screen.getByText('7 days ago')).toBeInTheDocument();
|
|
|
});
|
|
|
});
|
|
|
- describe('sorting', () => {
|
|
|
- let mockEventsApi;
|
|
|
- let mockReplayApi;
|
|
|
-
|
|
|
- beforeEach(() => {
|
|
|
- mockEventsApi = MockApiClient.addMockResponse({
|
|
|
- url: mockEventsUrl,
|
|
|
- body: {
|
|
|
- data: [
|
|
|
- {replayId: '346789a703f6454384f1de473b8b9fcc', 'count()': 1},
|
|
|
- {replayId: 'b05dae9b6be54d21a4d5ad9f8f02b780', 'count()': 1},
|
|
|
- ],
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- mockReplayApi = MockApiClient.addMockResponse({
|
|
|
- url: mockReplayUrl,
|
|
|
- body: {
|
|
|
- data: [],
|
|
|
- },
|
|
|
- statusCode: 200,
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- it('should not call the events api again when sorting the visible rows', async () => {
|
|
|
- const mockGroup = TestStubs.Group();
|
|
|
-
|
|
|
- const {router, organization, routerContext} = init({});
|
|
|
- const {rerender} = render(<GroupReplays group={mockGroup} />, {
|
|
|
- context: routerContext,
|
|
|
- organization,
|
|
|
- router,
|
|
|
- });
|
|
|
-
|
|
|
- await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
- expect(mockReplayApi).toHaveBeenCalledTimes(1);
|
|
|
- expect(mockReplayApi).toHaveBeenLastCalledWith(
|
|
|
- mockReplayUrl,
|
|
|
- expect.objectContaining({
|
|
|
- query: expect.objectContaining({
|
|
|
- sort: '-started_at',
|
|
|
- }),
|
|
|
- })
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- // Change the sort order then tell react to re-render
|
|
|
- router.location.query.sort = 'duration';
|
|
|
- rerender(<GroupReplays group={mockGroup} />);
|
|
|
-
|
|
|
- await waitFor(() => {
|
|
|
- expect(mockEventsApi).toHaveBeenCalledTimes(1);
|
|
|
- expect(mockReplayApi).toHaveBeenCalledTimes(2);
|
|
|
- expect(mockReplayApi).toHaveBeenLastCalledWith(
|
|
|
- mockReplayUrl,
|
|
|
- expect.objectContaining({
|
|
|
- query: expect.objectContaining({
|
|
|
- sort: 'duration',
|
|
|
- }),
|
|
|
- })
|
|
|
- );
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
});
|