123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, waitFor, within} from 'sentry-test/reactTestingLibrary';
- import MemberListStore from 'sentry/stores/memberListStore';
- import GroupSidebar from './groupSidebar';
- describe('GroupSidebar', function () {
- let group = TestStubs.Group({tags: TestStubs.Tags()});
- const {organization, project} = initializeOrg();
- const environment = {name: 'production', displayName: 'Production', id: '1'};
- let tagsMock;
- beforeEach(function () {
- MemberListStore.loadInitialData([]);
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/events/1/committers/',
- body: {committers: []},
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/events/1/owners/',
- body: {
- owners: [],
- rules: [],
- },
- });
- MockApiClient.addMockResponse({
- url: '/groups/1/integrations/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/1/',
- body: group,
- });
- MockApiClient.addMockResponse({
- url: '/issues/1/current-release/',
- body: {},
- });
- MockApiClient.addMockResponse({
- url: '/groups/1/external-issues/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/prompts-activity/`,
- body: {},
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/code-mappings/`,
- query: {project: -1},
- method: 'GET',
- body: [],
- });
- tagsMock = MockApiClient.addMockResponse({
- url: '/issues/1/tags/',
- body: TestStubs.Tags(),
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/users/`,
- body: [],
- });
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- describe('sidebar', () => {
- it('should make a request to the /tags/ endpoint to get top values', async () => {
- render(
- <GroupSidebar
- group={group}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- expect(await screen.findByText('browser')).toBeInTheDocument();
- expect(tagsMock).toHaveBeenCalled();
- });
- });
- describe('renders with tags', function () {
- it('renders', async function () {
- render(
- <GroupSidebar
- group={group}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- expect(await screen.findByText('browser')).toBeInTheDocument();
- expect(screen.getByText('device')).toBeInTheDocument();
- expect(screen.getByText('url')).toBeInTheDocument();
- expect(screen.getByText('environment')).toBeInTheDocument();
- expect(screen.getByText('user')).toBeInTheDocument();
- });
- });
- describe('environment toggle', function () {
- it('re-requests tags with correct environment', async function () {
- const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
- const {rerender} = render(
- <GroupSidebar
- group={group}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- expect(await screen.findByText('browser')).toBeInTheDocument();
- expect(tagsMock).toHaveBeenCalledTimes(1);
- rerender(
- <GroupSidebar
- group={group}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[stagingEnv]}
- />,
- {organization}
- );
- expect(await screen.findByText('browser')).toBeInTheDocument();
- expect(tagsMock).toHaveBeenCalledTimes(2);
- expect(tagsMock).toHaveBeenCalledWith(
- '/issues/1/tags/',
- expect.objectContaining({
- query: expect.objectContaining({
- environment: ['staging'],
- }),
- })
- );
- });
- });
- describe('renders without tags', function () {
- beforeEach(function () {
- group = TestStubs.Group();
- MockApiClient.addMockResponse({
- url: '/issues/1/',
- body: group,
- });
- MockApiClient.addMockResponse({
- url: '/issues/1/tags/',
- body: [],
- });
- });
- it('renders empty text', async function () {
- render(
- <GroupSidebar
- group={group}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- expect(
- await screen.findByText('No tags found in the selected environments')
- ).toBeInTheDocument();
- });
- });
- it('renders participants and viewers', async () => {
- const users = [
- TestStubs.User({
- id: '2',
- name: 'John Smith',
- email: 'johnsmith@example.com',
- }),
- TestStubs.User({
- id: '3',
- name: 'Sohn Jmith',
- email: 'sohnjmith@example.com',
- }),
- ];
- render(
- <GroupSidebar
- group={{
- ...group,
- participants: users,
- seenBy: users,
- }}
- project={project}
- organization={organization}
- event={TestStubs.Event()}
- environments={[]}
- />,
- {organization}
- );
- expect(await screen.findByText('Participants (2)')).toBeInTheDocument();
- expect(screen.getByText('Viewers (2)')).toBeInTheDocument();
- });
- describe('displays mobile tags when issue platform is mobile', function () {
- beforeEach(function () {
- group = TestStubs.Group();
- MockApiClient.addMockResponse({
- url: '/issues/1/',
- body: group,
- });
- });
- it('renders mobile tags on top of tag summary for mobile platforms', async function () {
- render(
- <GroupSidebar
- group={group}
- project={{...project, platform: 'react-native'}}
- organization={{
- ...organization,
- features: [...organization.features, 'issue-details-tag-improvements'],
- }}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- await waitFor(() => expect(tagsMock).toHaveBeenCalled());
- expect(
- within(screen.getByTestId('top-distribution-wrapper')).getByText('device')
- ).toBeInTheDocument();
- });
- it('does not render mobile tags on top of tag summary for non mobile platforms', async function () {
- render(
- <GroupSidebar
- group={group}
- project={project}
- organization={{
- ...organization,
- features: [...organization.features, 'issue-details-tag-improvements'],
- }}
- event={TestStubs.Event()}
- environments={[environment]}
- />,
- {organization}
- );
- await waitFor(() => expect(tagsMock).toHaveBeenCalled());
- expect(
- within(screen.getByTestId('top-distribution-wrapper')).queryByText('device')
- ).not.toBeInTheDocument();
- });
- });
- });
|