Skip to content

Commit

Permalink
Refactor to use a impacted files enum as requested.
Browse files Browse the repository at this point in the history
  • Loading branch information
terry-codecov committed Oct 26, 2023
1 parent 0cb7bf5 commit 6bea3b5
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import isNil from 'lodash/isNil'

import { CommitStateEnum } from 'shared/utils/commit'
import { ComparisonReturnType } from 'shared/utils/comparison'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'
import Spinner from 'ui/Spinner'

import { useImpactedFilesTable } from './hooks'
Expand Down Expand Up @@ -53,7 +54,7 @@ function FilesChangedTab() {
)
}

if (data?.impactedFilesType === 'UnknownFlags') {
if (data?.impactedFilesType === ImpactedFilesReturnType.UNKNOWN_FLAGS) {
return (
<div className="flex flex-col gap-2">
<p className="mt-4">
Expand All @@ -65,7 +66,7 @@ function FilesChangedTab() {
}

if (
data?.impactedFilesType === 'ImpactedFiles' &&
data?.impactedFilesType === ImpactedFilesReturnType.IMPACTED_FILES &&
data?.impactedFiles.length > 0
) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MemoryRouter, Route } from 'react-router-dom'

import { CommitStateEnum } from 'shared/utils/commit'
import { ComparisonReturnType } from 'shared/utils/comparison'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import FilesChanged from './FilesChanged'

Expand Down Expand Up @@ -68,7 +69,7 @@ const mockPull = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockImpactedFiles,
},
},
Expand Down Expand Up @@ -148,7 +149,10 @@ describe('FilesChanged', () => {
percentCovered: 27.35,
},
changeCoverage: 38.94,
impactedFiles: { __typename: 'ImpactedFiles', results: [] },
impactedFiles: {
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [],
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import Table from './Table'

jest.mock('../../shared/FileDiff', () => () => 'FileDiff Component')
Expand Down Expand Up @@ -48,7 +50,10 @@ const mockPull = {
percentCovered: 27.35,
},
changeCoverage: 38.94,
impactedFiles: { __typename: 'ImpactedFiles', results: mockTable },
impactedFiles: {
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockTable,
},
},
},
},
Expand All @@ -75,7 +80,10 @@ const mockNoTable = {
percentCovered: 27.35,
},
changeCoverage: 38.94,
impactedFiles: { __typename: 'ImpactedFiles', results: [] },
impactedFiles: {
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [],
},
},
},
},
Expand Down Expand Up @@ -103,7 +111,7 @@ const mockNoChange = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [
{
isCriticalFile: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useCallback, useState } from 'react'
import { useLocation, useParams } from 'react-router-dom'

import { usePull } from 'services/pull'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

const orderingDirection = Object.freeze({
desc: 'DESC',
Expand Down Expand Up @@ -61,7 +62,8 @@ function transformImpactedFilesData({ pull }) {
)
// Keep old way but just pass the plain impactedFiles if the status is not ImpactedFile
const impactedFiles =
compareWithBase?.impactedFiles?.__typename === 'ImpactedFiles'
compareWithBase?.impactedFiles?.__typename ===
ImpactedFilesReturnType.IMPACTED_FILES
? mutatedImpactedFiles
: compareWithBase?.impactedFiles

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'
import { act } from 'react-test-renderer'

import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import {
orderingParameter,
useImpactedFilesTable,
Expand Down Expand Up @@ -66,7 +68,7 @@ let mockPull = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockImpactedFiles,
},
},
Expand Down Expand Up @@ -171,7 +173,7 @@ describe('useImpactedFilesTable', () => {
pullId: 14,
},
],
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
pullBaseCoverage: 27.35,
pullHeadCoverage: 74.2,
pullPatchCoverage: 92.12,
Expand All @@ -185,7 +187,7 @@ describe('useImpactedFilesTable', () => {
beforeEach(() => {
const pull = mockPull
const mockImpactedFilesWithoutCoverage = {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [
{
missesCount: 0,
Expand Down Expand Up @@ -217,7 +219,7 @@ describe('useImpactedFilesTable', () => {

await waitFor(() =>
expect(result.current.data).toEqual({
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
compareWithBaseType: 'Comparison',
headState: 'PROCESSED',
impactedFiles: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import { MemoryRouter, Route } from 'react-router-dom'

import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import IndirectChangedFiles from './IndirectChangedFiles'

jest.mock('../FileDiff', () => () => 'FileDiff Component')
Expand Down Expand Up @@ -48,7 +50,7 @@ const mockPull = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockImpactedFiles,
},
},
Expand Down Expand Up @@ -77,7 +79,7 @@ const mockNoImpactedFiles = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [],
},
},
Expand Down Expand Up @@ -106,7 +108,7 @@ const mockNoChange = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [
{
isCriticalFile: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useState } from 'react'
import { useParams } from 'react-router-dom'

import { usePull } from 'services/pull'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

const orderingDirection = Object.freeze({
desc: 'DESC',
Expand Down Expand Up @@ -63,7 +64,8 @@ function transformIndirectChangesData({ pull }) {

// Keep old way but just pass the plain impactedFiles if the status is not ImpactedFile
const impactedFiles =
compareWithBase?.impactedFiles?.__typename === 'ImpactedFiles'
compareWithBase?.impactedFiles?.__typename ===
ImpactedFilesReturnType.IMPACTED_FILES
? mutatedImpactedFiles
: compareWithBase?.impactedFiles

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom'
import { act } from 'react-test-renderer'

import { usePull } from 'services/pull'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import { useIndirectChangedFilesTable } from './useIndirectChangedFilesTable'

Expand Down Expand Up @@ -50,7 +51,7 @@ let mockPull = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockImpactedFiles,
},
},
Expand Down Expand Up @@ -132,7 +133,7 @@ describe('useRepoContentsTable', () => {
expect(result.current.data).toEqual({
headState: 'PROCESSED',
compareWithBaseType: 'Comparison',
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
impactedFiles: [
{
changeCoverage: 44.85,
Expand All @@ -145,7 +146,7 @@ describe('useRepoContentsTable', () => {
patchCoverage: 27.43,
pullId: 14,
compareWithBaseType: 'Comparison',
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
},
],
pullBaseCoverage: 27.35,
Expand All @@ -158,7 +159,7 @@ describe('useRepoContentsTable', () => {
describe('when called with no head or base coverage on the impacted files', () => {
beforeEach(() => {
const mockImpactedFilesWithoutCoverage = {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [
{
missesCount: 0,
Expand Down Expand Up @@ -188,11 +189,11 @@ describe('useRepoContentsTable', () => {
expect(result.current.data).toEqual({
headState: 'PROCESSED',
compareWithBaseType: 'Comparison',
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
impactedFiles: [
{
compareWithBaseType: 'Comparison',
impactedFilesType: 'ImpactedFiles',
impactedFilesType: ImpactedFilesReturnType.IMPACTED_FILES,
changeCoverage: NaN,
fileName: 'mafs.js',
hasHeadOrPatchCoverage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import isNil from 'lodash/isNil'

import { CommitStateEnum } from 'shared/utils/commit'
import { ComparisonReturnType } from 'shared/utils/comparison'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'
import Spinner from 'ui/Spinner'

import ImpactedFiles from './IndirectChangedFiles'
Expand Down Expand Up @@ -67,7 +68,7 @@ function IndirectChangesTab() {
}

if (
data?.impactedFilesType === 'ImpactedFiles' &&
data?.impactedFilesType === ImpactedFilesReturnType.IMPACTED_FILES &&
data?.impactedFiles.length > 0
) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MemoryRouter, Route } from 'react-router-dom'

import { CommitStateEnum } from 'shared/utils/commit'
import { ComparisonReturnType } from 'shared/utils/comparison'
import { ImpactedFilesReturnType } from 'shared/utils/impactedFiles'

import IndirectChangesTab from './IndirectChangesTab'

Expand Down Expand Up @@ -84,7 +85,7 @@ const mockPull = {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'ImpactedFiles',
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: mockImpactedFiles,
},
},
Expand Down Expand Up @@ -151,7 +152,10 @@ describe('IndirectChangesTab', () => {
percentCovered: 27.35,
},
changeCoverage: 38.94,
impactedFiles: { __typename: 'ImpactedFiles', results: [] },
impactedFiles: {
__typename: ImpactedFilesReturnType.IMPACTED_FILES,
results: [],
},
},
},
},
Expand Down Expand Up @@ -319,7 +323,7 @@ describe('IndirectChangesTab', () => {
},
changeCoverage: 38.94,
impactedFiles: {
__typename: 'UnknownFlags',
__typename: ImpactedFilesReturnType.UNKNOWN_FLAGS,
message: 'Unkown flags detected',
},
},
Expand Down
4 changes: 4 additions & 0 deletions src/shared/utils/impactedFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const ImpactedFilesReturnType = Object.freeze({
UNKNOWN_FLAGS: 'UnknownFlags',
IMPACTED_FILES: 'ImpactedFiles',
})

0 comments on commit 6bea3b5

Please sign in to comment.