Skip to content

Commit

Permalink
Add new tests, fix old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSun48 committed Jan 7, 2025
1 parent b341d06 commit 8c83319
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions static/app/views/issueList/issueViewsHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ describe('IssueViewsHeader', () => {
method: 'GET',
body: getRequestViews,
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});
});

it('renders all tabs, selects the first one by default, and replaces the query params accordingly', async () => {
Expand Down Expand Up @@ -120,6 +125,11 @@ describe('IssueViewsHeader', () => {
},
],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});

render(<IssueViewsIssueListHeader {...defaultProps} />, {router: defaultRouter});

Expand Down Expand Up @@ -153,6 +163,11 @@ describe('IssueViewsHeader', () => {
},
],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});

render(<IssueViewsIssueListHeader {...defaultProps} router={queryOnlyRouter} />, {
router: queryOnlyRouter,
Expand Down Expand Up @@ -277,6 +292,11 @@ describe('IssueViewsHeader', () => {
},
],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});

const defaultTabDifferentQueryRouter = RouterFixture({
location: LocationFixture({
Expand Down Expand Up @@ -320,6 +340,11 @@ describe('IssueViewsHeader', () => {
method: 'GET',
body: getRequestViews,
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});
});

it('switches tabs when clicked, and updates the query params accordingly', async () => {
Expand Down Expand Up @@ -453,6 +478,11 @@ describe('IssueViewsHeader', () => {
method: 'GET',
body: getRequestViews,
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {},
});
});

it('should render the correct set of actions for an unchanged tab', async () => {
Expand Down Expand Up @@ -792,4 +822,95 @@ describe('IssueViewsHeader', () => {
});
});
});

describe('Issue views query counts', () => {
it('should render the correct count for a single view', async () => {
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/group-search-views/`,
method: 'GET',
body: [getRequestViews[0]],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
query: {
query: getRequestViews[0]!.query,
},
body: {
[getRequestViews[0]!.query]: 42,
},
});

render(<IssueViewsIssueListHeader {...defaultProps} />, {router: defaultRouter});

expect(await screen.findByText('42')).toBeInTheDocument();
});

it('should render the correct count for multiple views', async () => {
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/group-search-views/`,
method: 'GET',
body: getRequestViews,
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
body: {
[getRequestViews[0]!.query]: 42,
[getRequestViews[1]!.query]: 6,
[getRequestViews[2]!.query]: 98,
},
});

render(<IssueViewsIssueListHeader {...defaultProps} />, {router: defaultRouter});

expect(await screen.findByText('42')).toBeInTheDocument();
expect(screen.getByText('6')).toBeInTheDocument();
expect(screen.getByText('98')).toBeInTheDocument();
});

it('should show a max count of 99+ if the count is greater than 99', async () => {
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/group-search-views/`,
method: 'GET',
body: [getRequestViews[0]],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
query: {
query: getRequestViews[0]!.query,
},
body: {
[getRequestViews[0]!.query]: 101,
},
});

render(<IssueViewsIssueListHeader {...defaultProps} />, {router: defaultRouter});

expect(await screen.findByText('99+')).toBeInTheDocument();
});

it('should show stil show a 0 query count if the count is 0', async () => {
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/group-search-views/`,
method: 'GET',
body: [getRequestViews[0]],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues-count/`,
method: 'GET',
query: {
query: getRequestViews[0]!.query,
},
body: {
[getRequestViews[0]!.query]: 0,
},
});

render(<IssueViewsIssueListHeader {...defaultProps} />, {router: defaultRouter});

expect(await screen.findByText('0')).toBeInTheDocument();
});
});
});

0 comments on commit 8c83319

Please sign in to comment.