123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import {enforceActOnUseLegacyStoreHook, mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {act} from 'sentry-test/reactTestingLibrary';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- import UserFeedback from 'sentry/views/userFeedback';
- describe('UserFeedback', function () {
- enforceActOnUseLegacyStoreHook();
- const {organization, routerContext} = initializeOrg();
- const pageLinks =
- '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1", ' +
- '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"';
- const project = TestStubs.Project({isMember: true});
- beforeEach(function () {
- act(() => ProjectsStore.loadInitialData([project]));
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/user-feedback/',
- body: [TestStubs.UserFeedback()],
- headers: {Link: pageLinks},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/environments/',
- body: TestStubs.Environments(),
- });
- });
- afterEach(function () {
- act(() => ProjectsStore.reset());
- });
- it('renders', async function () {
- const params = {
- organization: TestStubs.Organization(),
- location: {query: {}, search: ''},
- params: {
- orgId: organization.slug,
- },
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [project],
- headers: {Link: pageLinks},
- });
- const wrapper = mountWithTheme(
- <OrganizationContext.Provider value={organization}>
- <UserFeedback {...params} />
- </OrganizationContext.Provider>,
- routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('CompactIssue')).toHaveLength(1);
- });
- it('renders no project message', function () {
- act(() => ProjectsStore.loadInitialData([]));
- const params = {
- organization: TestStubs.Organization(),
- location: {query: {}, search: ''},
- params: {
- orgId: organization.slug,
- },
- };
- const wrapper = mountWithTheme(
- <OrganizationContext.Provider value={organization}>
- <UserFeedback {...params} />
- </OrganizationContext.Provider>,
- routerContext
- );
- expect(wrapper.find('NoProjectMessage').exists()).toBe(true);
- expect(wrapper.find('UserFeedbackEmpty').exists()).toBe(false);
- });
- it('renders empty state', function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/user-feedback/',
- body: [],
- });
- const params = {
- organization: TestStubs.Organization({
- projects: [TestStubs.Project({isMember: true})],
- }),
- location: {query: {}, search: ''},
- params: {
- orgId: organization.slug,
- },
- };
- const wrapper = mountWithTheme(
- <OrganizationContext.Provider value={organization}>
- <UserFeedback {...params} />
- </OrganizationContext.Provider>,
- routerContext
- );
- expect(wrapper.find('UserFeedbackEmpty').prop('projectIds')).toEqual([]);
- });
- it('renders empty state with project query', function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/user-feedback/',
- body: [],
- });
- const params = {
- organization: TestStubs.Organization({
- projects: [TestStubs.Project({isMember: true})],
- }),
- location: {query: {project: '112'}, search: ''},
- params: {
- orgId: organization.slug,
- },
- };
- const wrapper = mountWithTheme(
- <OrganizationContext.Provider value={organization}>
- <UserFeedback {...params} />
- </OrganizationContext.Provider>,
- routerContext
- );
- expect(wrapper.find('UserFeedbackEmpty').prop('projectIds')).toEqual(['112']);
- });
- it('renders empty state with multi project query', function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/user-feedback/',
- body: [],
- });
- const params = {
- organization: TestStubs.Organization({
- projects: [TestStubs.Project({isMember: true})],
- }),
- location: {query: {project: ['112', '113']}, search: ''},
- params: {
- orgId: organization.slug,
- },
- };
- const wrapper = mountWithTheme(
- <OrganizationContext.Provider value={organization}>
- <UserFeedback {...params} />
- </OrganizationContext.Provider>,
- routerContext
- );
- expect(wrapper.find('UserFeedbackEmpty').prop('projectIds')).toEqual(['112', '113']);
- });
- });
|