123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- import {
- render,
- renderGlobalModal,
- screen,
- userEvent,
- } from 'sentry-test/reactTestingLibrary';
- import {Client} from 'sentry/api';
- import RepositoryRow from 'sentry/components/repositoryRow';
- describe('RepositoryRow', function () {
- beforeEach(function () {
- Client.clearMockResponses();
- });
- const repository = TestStubs.Repository();
- const pendingRepo = TestStubs.Repository({
- status: 'pending_deletion',
- });
- const customRepo = TestStubs.Repository({
- provider: {
- id: 'integrations:custom_scm',
- },
- });
- const customPendingRepo = TestStubs.Repository({
- provider: {
- id: 'integrations:custom_scm',
- },
- status: 'pending_deletion',
- });
- const api = new Client();
- describe('rendering with access', function () {
- const organization = TestStubs.Organization({
- access: ['org:integrations'],
- });
- const routerContext = TestStubs.routerContext([{organization}]);
- it('displays provider information', function () {
- render(
- <RepositoryRow
- repository={repository}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- expect(screen.getByText(repository.name)).toBeInTheDocument();
- expect(screen.getByText('github.com/example/repo-name')).toBeInTheDocument();
- // Trash button should display enabled
- expect(screen.getByRole('button', {name: 'delete'})).toBeEnabled();
- // No cancel button
- expect(screen.queryByRole('button', {name: 'Cancel'})).not.toBeInTheDocument();
- });
- it('displays cancel pending button', function () {
- render(
- <RepositoryRow
- repository={pendingRepo}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- // Trash button should be disabled
- expect(screen.getByRole('button', {name: 'delete'})).toBeDisabled();
- // Cancel button active
- expect(screen.getByRole('button', {name: 'Cancel'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Cancel'})).toBeEnabled();
- });
- });
- describe('rendering without access', function () {
- const organization = TestStubs.Organization({
- access: ['org:write'],
- });
- const routerContext = TestStubs.routerContext([{organization}]);
- it('displays disabled trash', function () {
- render(
- <RepositoryRow
- repository={repository}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- // Trash button should be disabled
- expect(screen.getByRole('button', {name: 'delete'})).toBeDisabled();
- });
- it('displays disabled cancel', function () {
- render(
- <RepositoryRow
- repository={pendingRepo}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- // Cancel should be disabled
- expect(screen.getByRole('button', {name: 'Cancel'})).toBeDisabled();
- });
- });
- describe('deletion', function () {
- const organization = TestStubs.Organization({
- access: ['org:integrations'],
- });
- const routerContext = TestStubs.routerContext([{organization}]);
- it('sends api request on delete', function () {
- const deleteRepo = Client.addMockResponse({
- url: `/organizations/${organization.slug}/repos/${repository.id}/`,
- method: 'DELETE',
- statusCode: 204,
- body: {},
- });
- render(
- <RepositoryRow
- repository={repository}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- renderGlobalModal();
- userEvent.click(screen.getByRole('button', {name: 'delete'}));
- // Confirm modal
- userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
- expect(deleteRepo).toHaveBeenCalled();
- });
- });
- describe('cancel deletion', function () {
- const organization = TestStubs.Organization({
- access: ['org:integrations'],
- });
- const routerContext = TestStubs.routerContext([{organization}]);
- it('sends api request to cancel', function () {
- const cancel = Client.addMockResponse({
- url: `/organizations/${organization.slug}/repos/${pendingRepo.id}/`,
- method: 'PUT',
- statusCode: 204,
- body: {},
- });
- render(
- <RepositoryRow
- repository={pendingRepo}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
- expect(cancel).toHaveBeenCalled();
- });
- });
- describe('renders custom_scm repo', function () {
- const organization = TestStubs.Organization({
- access: ['org:integrations'],
- features: ['integrations-custom-scm'],
- });
- const routerContext = TestStubs.routerContext([{organization}]);
- it('displays edit button', function () {
- render(
- <RepositoryRow
- repository={customRepo}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- // Trash button should display enabled
- expect(screen.getByRole('button', {name: 'delete'})).toBeEnabled();
- // No cancel button
- expect(screen.queryByRole('button', {name: 'Cancel'})).not.toBeInTheDocument();
- // Edit button should display enabled
- expect(screen.getByRole('button', {name: 'edit'})).toBeEnabled();
- });
- it('disables edit button when cancel pending', function () {
- render(
- <RepositoryRow
- repository={customPendingRepo}
- api={api}
- orgId={organization.slug}
- organization={organization}
- />,
- {context: routerContext}
- );
- // Trash button should be disabled
- expect(screen.getByRole('button', {name: 'delete'})).toBeDisabled();
- // Edit button should be disabled
- expect(screen.getByRole('button', {name: 'edit'})).toBeDisabled();
- // Cancel button active
- expect(screen.queryByRole('button', {name: 'Cancel'})).toBeEnabled();
- });
- });
- });
|