Skip to content
Merged
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
73 changes: 72 additions & 1 deletion packages/query-devtools/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest'
import { deleteNestedDataByPath, updateNestedDataByPath } from '../utils'
import {
deleteNestedDataByPath,
getMutationStatusColor,
getQueryStatusColorByLabel,
updateNestedDataByPath,
} from '../utils'
import type { MutationStatus } from '@tanstack/query-core'

describe('Utils tests', () => {
describe('updatedNestedDataByPath', () => {
Expand Down Expand Up @@ -729,4 +735,69 @@ describe('Utils tests', () => {
})
})
})

describe('getMutationStatusColor', () => {
const cases: Array<{
label: string
status: MutationStatus
isPaused: boolean
expected: string
}> = [
{
label: 'paused',
status: 'pending',
isPaused: true,
expected: 'purple',
},
{
label: 'paused even when status is "error"',
status: 'error',
isPaused: true,
expected: 'purple',
},
{ label: '"error"', status: 'error', isPaused: false, expected: 'red' },
{
label: '"pending"',
status: 'pending',
isPaused: false,
expected: 'yellow',
},
{
label: '"success"',
status: 'success',
isPaused: false,
expected: 'green',
},
{ label: '"idle"', status: 'idle', isPaused: false, expected: 'gray' },
]

it.each(cases)(
'should return "$expected" when mutation is $label',
({ status, isPaused, expected }) => {
expect(getMutationStatusColor({ status, isPaused })).toBe(expected)
},
)
})

describe('getQueryStatusColorByLabel', () => {
it('should return "green" for "fresh"', () => {
expect(getQueryStatusColorByLabel('fresh')).toBe('green')
})

it('should return "yellow" for "stale"', () => {
expect(getQueryStatusColorByLabel('stale')).toBe('yellow')
})

it('should return "purple" for "paused"', () => {
expect(getQueryStatusColorByLabel('paused')).toBe('purple')
})

it('should return "gray" for "inactive"', () => {
expect(getQueryStatusColorByLabel('inactive')).toBe('gray')
})

it('should return "blue" for "fetching"', () => {
expect(getQueryStatusColorByLabel('fetching')).toBe('blue')
})
})
})
Loading