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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 21 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/fetchSourcesData'

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, setGraph } = useDataStore((s) => s)

const selectedNode = useSelectedNode()

Expand Down Expand Up @@ -163,6 +164,20 @@ export const NodeControls = memo(() => {
setAnchorEl(null)
}

const handleAnalyzeTestCoverage = async (githubName: string) => {
try {
const res = await analyzeGitHubRepository(githubName)

if (res) {
setSelectedNode(null)

setGraph({ nodes: res.functions })
}
} catch (error) {
console.error('Error during test coverage analysis:', error)
}
}

const open = Boolean(anchorEl)

const id = open ? 'simple-popover' : undefined
Expand Down Expand Up @@ -248,13 +263,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
12 changes: 12 additions & 0 deletions src/network/fetchSourcesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ export interface UpdateSchemaParams {
}
}

type GithubRepositoryResponse = {
functions: NodeExtended[]
}

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

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

return res
}

export const getNodes = async (): Promise<FetchDataResponse> => {
const url = `/prediction/graph/search?node_type=['Episode']&include_properties=true&includeContent=true&sort_by=date`

Expand Down
22 changes: 22 additions & 0 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
abortFetchData: () => void
resetGraph: () => void
resetData: () => void
setGraph: (graph: { nodes: NodeExtended[] }) => void
}

const defaultData: Omit<
Expand Down Expand Up @@ -117,6 +118,7 @@
| 'abortFetchData'
| 'resetGraph'
| 'resetData'
| 'setGraph'
> = {
categoryFilter: null,
dataInitial: null,
Expand Down Expand Up @@ -318,6 +320,26 @@
})
},

setGraph: (data: { nodes: NodeExtended[] }) => {
const uniqueNodes = deduplicateByRefId(data.nodes)

const nodeTypes = [...new Set(uniqueNodes.map((node) => node.node_type))]
const sidebarFilters = ['all', ...nodeTypes.map((type) => type.toLowerCase())]

const sidebarFilterCounts = sidebarFilters.map((filter) => ({
name: filter,
count: uniqueNodes.filter((node) => filter === 'all' || node.node_type?.toLowerCase() === filter).length,
}))

set({
dataInitial: { nodes: uniqueNodes, links: [] },
dataNew: { nodes: uniqueNodes, links: [] },
nodeTypes,
sidebarFilters,
sidebarFilterCounts,
})
},

nextPage: () => {
const { filters, fetchData, setAbortRequests } = get()
const { setBudget } = useUserStore.getState()
Expand Down Expand Up @@ -345,7 +367,7 @@
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode) => {
console.info(updatedNode)

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 370 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement
},
addNewNode: (data) => {
const { dataInitial: existingData, filters } = get()
Expand Down Expand Up @@ -407,7 +429,7 @@
})
},
removeNode: (id) => {
console.log(id)

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 432 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement
},

setRunningProjectId: (runningProjectId) => set({ runningProjectId, runningProjectMessages: [] }),
Expand Down
Loading