123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import {Fragment} from 'react';
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import GlobalModal from 'sentry/components/globalModal';
- import ProjectLatestReleases from 'sentry/views/projectDetail/projectLatestReleases';
- describe('ProjectDetail > ProjectLatestReleases', function () {
- let endpointMock, endpointOlderReleasesMock;
- const {organization, project, router} = initializeOrg();
- beforeEach(function () {
- endpointMock = MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/releases/`,
- body: [
- TestStubs.Release({version: '1.0.0'}),
- TestStubs.Release({version: '1.0.1'}),
- ],
- });
- endpointOlderReleasesMock = MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/releases/stats/`,
- body: [TestStubs.Release({version: '1.0.0'})],
- });
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- });
- it('renders a list', function () {
- const wrapper = mountWithTheme(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={router.location}
- projectId={project.slug}
- isProjectStabilized
- />
- );
- expect(endpointMock).toHaveBeenCalledTimes(1);
- expect(endpointMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: {per_page: 5},
- })
- );
- expect(endpointOlderReleasesMock).toHaveBeenCalledTimes(0);
- expect(wrapper.find('SectionHeading').text()).toBe('Latest Releases');
- expect(wrapper.find('Version').length).toBe(2);
- expect(wrapper.find('DateTime').at(0).text()).toBe('Mar 23, 2020 1:02 AM');
- expect(wrapper.find('Version').at(1).text()).toBe('1.0.1');
- });
- it('shows the empty state', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/releases/`,
- body: [],
- });
- const wrapper = mountWithTheme(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={router.location}
- projectId={project.slug}
- isProjectStabilized
- />
- );
- await tick();
- wrapper.update();
- expect(endpointOlderReleasesMock).toHaveBeenCalledTimes(1);
- expect(wrapper.find('Version').length).toBe(0);
- expect(wrapper.text()).toContain('No releases found');
- });
- it('shows configure releases buttons', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/releases/`,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/releases/stats/`,
- body: [],
- });
- const wrapper = mountWithTheme(
- <Fragment>
- <GlobalModal />
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={router.location}
- projectId={project.slug}
- isProjectStabilized
- />
- </Fragment>
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('Version').length).toBe(0);
- const docsButton = wrapper.find('Button').at(0);
- const tourButton = wrapper.find('Button').at(1);
- expect(docsButton.text()).toBe('Start Setup');
- expect(docsButton.prop('href')).toBe('https://docs.sentry.io/product/releases/');
- expect(tourButton.text()).toBe('Get Tour');
- expect(wrapper.find('GlobalModal').props().visible).toEqual(false);
- tourButton.simulate('click');
- await tick();
- wrapper.update();
- expect(wrapper.find('GlobalModal').props().visible).toEqual(true);
- });
- it('calls API with the right params', function () {
- mountWithTheme(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={{
- query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
- }}
- projectId={project.slug}
- isProjectStabilized
- />
- );
- expect(endpointMock).toHaveBeenCalledTimes(1);
- expect(endpointMock).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: {per_page: 5, statsPeriod: '7d', environment: 'staging'},
- })
- );
- });
- it('does not call API if project is not stabilized yet', function () {
- mountWithTheme(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={{
- query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
- }}
- projectId={project.slug}
- isProjectStabilized={false}
- />
- );
- expect(endpointMock).toHaveBeenCalledTimes(0);
- });
- });
|