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

Replace "Generate Tests" with "Analyze Test Coverage" in Repository Node #2510

17 changes: 15 additions & 2 deletions src/components/Universe/Graph/UI/NodeControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useUserStore } from '~/stores/useUserStore'
import { NodeExtended } from '~/types'
import { colors } from '~/utils/colors'
import { buttonColors } from './constants'
import { analyzeGitHubRepository } from '~/network/analyzeGithubRepo'

const reuseableVector3 = new Vector3()

Expand All @@ -38,7 +39,7 @@ export const NodeControls = memo(() => {
const { open: createBountyModal } = useModal('createBounty')

const [isAdmin] = useUserStore((s) => [s.isAdmin])
const [addNewNode] = useDataStore((s) => [s.addNewNode])
const { addNewNode } = useDataStore((s) => s)

const selectedNode = useSelectedNode()

Expand Down Expand Up @@ -165,6 +166,14 @@ export const NodeControls = memo(() => {
setAnchorEl(null)
}

const handleAnalyzeTestCoverage = async (githubName: string) => {
try {
await analyzeGitHubRepository(githubName)
} catch (error) {
console.error('error during test coverage analysis:', error)
}
}

const open = Boolean(anchorEl)

const id = open ? 'simple-popover' : undefined
Expand Down Expand Up @@ -250,13 +259,17 @@ export const NodeControls = memo(() => {
<PopoverOption
data-testid="generate_tests"
onClick={() => {
if (selectedNode?.name) {
handleAnalyzeTestCoverage(selectedNode.name)
}

handleClose()
}}
>
<IconWrapper>
<AddCircleIcon data-testid="AddCircleIcon" />
</IconWrapper>
Generate Tests
Analyze Test Coverage
</PopoverOption>
<PopoverOption
data-testid="add_comments"
Expand Down
14 changes: 14 additions & 0 deletions src/network/analyzeGithubRepo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { api } from '~/network/api'
import { NodeExtended } from '~/types'

type GithubRepositoryResponse = {
functions: NodeExtended[]
}

export const analyzeGitHubRepository = async (githubRepository: string): Promise<GithubRepositoryResponse> => {
const url = `/github/analyze?github_repository=${githubRepository}&analysis=["coverage"]`

const res = await api.get<GithubRepositoryResponse>(url)

return res
}
Loading