123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- } from 'sentry-test/reactTestingLibrary';
- import ProjectLatestReleases from 'sentry/views/projectDetail/projectLatestReleases';
- describe('ProjectDetail > ProjectLatestReleases', function () {
- let endpointMock: jest.Mock;
- let endpointOlderReleasesMock: jest.Mock;
- 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 () {
- render(
- <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(screen.getByText('Latest Releases')).toBeInTheDocument();
- expect(screen.getByText('1.0.0')).toBeInTheDocument();
- expect(screen.getByText('1.0.1')).toBeInTheDocument();
- expect(screen.getAllByText('Mar 23, 2020 1:02 AM')).toHaveLength(2);
- });
- it('shows the empty state', async function () {
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/releases/`,
- body: [],
- });
- render(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={router.location}
- projectId={project.slug}
- isProjectStabilized
- />
- );
- expect(await screen.findByText('No releases found')).toBeInTheDocument();
- });
- 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: [],
- });
- render(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={router.location}
- projectId={project.slug}
- isProjectStabilized
- />
- );
- expect(await screen.findByRole('button', {name: 'Start Setup'})).toHaveAttribute(
- 'href',
- 'https://docs.sentry.io/product/releases/'
- );
- await userEvent.click(screen.getByRole('button', {name: 'Get Tour'}));
- renderGlobalModal();
- expect(screen.getByRole('dialog')).toBeInTheDocument();
- });
- it('calls API with the right params', function () {
- render(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={TestStubs.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 () {
- render(
- <ProjectLatestReleases
- organization={organization}
- projectSlug={project.slug}
- location={TestStubs.location({
- query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
- })}
- projectId={project.slug}
- isProjectStabilized={false}
- />
- );
- expect(endpointMock).toHaveBeenCalledTimes(0);
- });
- });
|