Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword the "Erase Repo" action #3670

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import SettingsDescriptor from 'ui/SettingsDescriptor'

import EraseRepoContent from './EraseRepoContent'
import EraseRepo from './EraseRepo'
import RepoState from './RepoState'

function DangerZone() {
return (
<SettingsDescriptor
title="Danger Zone"
description="Erase repo coverage data and pause upload ability"
description="Erase repository or pause upload ability"
content={
<>
<EraseRepoContent />
<EraseRepo />
<RepoState />
</>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import PropTypes from 'prop-types'
import { useState } from 'react'

import { useEraseRepoContent } from 'services/repo'
import { useEraseRepo } from 'services/repo'
import Button from 'ui/Button'

import EraseRepoContentModal from './EraseRepoContentModal'
import EraseRepoModal from './EraseRepoModal'

function EraseRepoButton({ isLoading, setShowModal }) {
if (isLoading) {
Expand All @@ -21,7 +21,7 @@ function EraseRepoButton({ isLoading, setShowModal }) {
hook="show-modal"
onClick={() => setShowModal(true)}
>
Erase Content
Erase Repository
</Button>
)
}
Expand All @@ -31,31 +31,31 @@ EraseRepoButton.propTypes = {
isLoading: PropTypes.bool.isRequired,
}

function EraseRepoContent() {
function EraseRepo() {
const [showModal, setShowModal] = useState(false)
const { mutate: eraseRepoContent, isLoading } = useEraseRepoContent()
const { mutate: eraseRepo, isLoading } = useEraseRepo()

return (
<div className="flex flex-col sm:flex-row">
<div className="flex flex-1 flex-col gap-1">
<h2 className="font-semibold">Erase repo coverage content</h2>
<h2 className="font-semibold">Erase repository</h2>
<p className="max-w-md">
This will remove all coverage reporting from the repo. For larger
repositories, this process may not be able to complete automatically.
In that case, please reach out to support for help.
This will erase the repository, including all of its contents. The
repository itself will be re-created when resync-ing the organization
contents.
</p>
</div>
<div>
<EraseRepoButton isLoading={isLoading} setShowModal={setShowModal} />
<EraseRepoContentModal
<EraseRepoModal
showModal={showModal}
closeModal={() => setShowModal(false)}
eraseRepoContent={eraseRepoContent}
eraseRepo={eraseRepo}
isLoading={isLoading}
/>
</div>
</div>
)
}

export default EraseRepoContent
export default EraseRepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { delay, graphql, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import EraseRepoContent from './EraseRepoContent'
import EraseRepo from './EraseRepo'

const mocks = vi.hoisted(() => ({
useAddNotification: vi.fn(),
Expand Down Expand Up @@ -70,7 +70,7 @@ const mockResponse = {
},
}

describe('EraseRepoContent', () => {
describe('EraseRepository', () => {
function setup(
{ failedMutation = false, isLoading = false, unauthorized = false } = {
failedMutation: false,
Expand Down Expand Up @@ -103,45 +103,45 @@ describe('EraseRepoContent', () => {
return { user, mutate, addNotification }
}

describe('renders EraseRepoContent component', () => {
describe('renders EraseRepo component', () => {
beforeEach(() => setup())

it('renders title', async () => {
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const title = await screen.findByText(/Erase repo coverage content/)
const title = await screen.findByText(/Erase repository/)
expect(title).toBeInTheDocument()
})

it('renders body', async () => {
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const firstBlock = await screen.findByText(
/This will remove all coverage reporting from the repo./
/This will erase the repository, including all of its contents./
)
expect(firstBlock).toBeInTheDocument()
})

it('renders erase button', async () => {
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
expect(eraseButton).toBeInTheDocument()
})

it('renders processing copy when isLoading is true', async () => {
const { user } = setup({ isLoading: true })
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

const modalCancelButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(modalCancelButton)

Expand All @@ -152,56 +152,56 @@ describe('EraseRepoContent', () => {
})
})

describe('when the user clicks on erase content button', () => {
describe('displays Erase Content Modal', () => {
describe('when the user clicks on erase repository button', () => {
describe('displays Erase Repository Modal', () => {
beforeEach(() => setup())

it('displays erase content button', async () => {
it('displays erase repository button', async () => {
const { user } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
expect(modalEraseButton).toBeInTheDocument()
})

it('displays modal body', async () => {
const { user } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
user.click(eraseButton)

const p1 = await screen.findByText(
/Are you sure you want to erase the repo coverage content?/
/Are you sure you want to erase the repository?/
)
expect(p1).toBeInTheDocument()

const p2 = await screen.findByText(
/This will erase repo coverage content should erase all coverage data contained in the repo. This action is irreversible and if you proceed, you will permanently erase any historical code coverage in Codecov for this repository./
/This will erase the repository, including all of its contents. This action is irreversible/
)
expect(p2).toBeInTheDocument()
})

it('displays modal buttons', async () => {
const { user } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
expect(modalEraseButton).toBeInTheDocument()

Expand All @@ -215,10 +215,10 @@ describe('EraseRepoContent', () => {
describe('when user clicks on Cancel button', () => {
it('does not call the mutation', async () => {
const { user, mutate } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

Expand All @@ -232,18 +232,18 @@ describe('EraseRepoContent', () => {
})
})

describe('when user clicks on Erase Content button', () => {
describe('when user clicks on Erase Repository button', () => {
it('calls the mutation', async () => {
const { user, mutate } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(modalEraseButton)

Expand All @@ -254,23 +254,23 @@ describe('EraseRepoContent', () => {
describe('when mutation is successful', () => {
it('adds a success notification', async () => {
const { user, mutate, addNotification } = setup()
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(modalEraseButton)

await waitFor(() => expect(mutate).toHaveBeenCalled())
await waitFor(() =>
expect(addNotification).toHaveBeenCalledWith({
type: 'success',
text: 'Repo coverage content erased successfully',
text: 'Repository erased successfully',
})
)
})
Expand All @@ -279,23 +279,23 @@ describe('EraseRepoContent', () => {
describe('when mutation is not successful', () => {
it('adds an error notification', async () => {
const { user, mutate, addNotification } = setup({ failedMutation: true })
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(modalEraseButton)

await waitFor(() => expect(mutate).toHaveBeenCalled())
await waitFor(() =>
expect(addNotification).toHaveBeenCalledWith({
type: 'error',
text: "We were unable to erase this repo's content",
text: 'We were unable to erase this repository',
})
)
})
Expand All @@ -304,23 +304,23 @@ describe('EraseRepoContent', () => {
describe('when user is unauthorized', () => {
it('adds an error notification', async () => {
const { user, mutate, addNotification } = setup({ unauthorized: true })
render(<EraseRepoContent />, { wrapper })
render(<EraseRepo />, { wrapper })

const eraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(eraseButton)

const modalEraseButton = await screen.findByRole('button', {
name: /Erase Content/,
name: /Erase Repository/,
})
await user.click(modalEraseButton)

await waitFor(() => expect(mutate).toHaveBeenCalled())
await waitFor(() =>
expect(addNotification).toHaveBeenCalledWith({
type: 'error',
text: "We were unable to erase this repo's content",
text: 'We were unable to erase this repository',
})
)
})
Expand Down
Loading
Loading