Skip to content
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
17 changes: 17 additions & 0 deletions redisinsight/ui/src/components/virtual-grid/tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getColumnWidth } from '../utils'

const getColumnWidthTests: any[] = [
[0, 500, [{ maxWidth: 70, minWidth: 50 }], 50],
[1, 500, [{ maxWidth: 70, minWidth: 50 }, { maxWidth: 170, minWidth: 20 }], 20],
[0, 500, [{ maxWidth: 470, minWidth: 450 }, { maxWidth: 170, minWidth: 20 }], 450],
]

const minColumnWidth = 10

describe('getColumnWidth', () => {
it.each(getColumnWidthTests)('for input: %s (i), %s (width), %s (columns) should be output: %s',
(i, width, columns, expected) => {
const result = getColumnWidth(i, width, columns, minColumnWidth)
expect(result).toBe(expected)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
import { IFetchKeyArgs } from 'uiSrc/constants/prop-types/keys'
import { resetStringValue, stringDataSelector, stringSelector } from 'uiSrc/slices/browser/string'
import { isFormatEditable, isFullStringLoaded } from 'uiSrc/utils'
import { StringDetailsTable } from './string-details-table'
import { StringDetailsValue } from './string-details-value'
import { EditItemAction } from '../key-details-actions'

export interface Props extends KeyDetailsHeaderProps {}
Expand Down Expand Up @@ -77,7 +77,7 @@ const StringDetails = (props: Props) => {
<div className="key-details-body" key="key-details-body">
{!loading && (
<div className="flex-column" style={{ flex: '1', height: '100%' }}>
<StringDetailsTable
<StringDetailsValue
isEditItem={editItem}
setIsEdit={(isEdit: boolean) => {
setEditItem(isEdit)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'uiSrc/utils/tests/decompressors'
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
import { downloadFile } from 'uiSrc/utils/dom/downloadFile'
import { StringDetailsTable, Props } from './StringDetailsTable'
import { StringDetailsValue, Props } from './StringDetailsValue'

const STRING_VALUE = 'string-value'
const STRING_VALUE_SPACE = 'string value'
Expand Down Expand Up @@ -70,11 +70,11 @@ jest.mock('react-redux', () => ({
useDispatch: () => jest.fn().mockReturnValue(() => jest.fn()),
}))

describe('StringDetailsTable', () => {
describe('StringDetailsValue', () => {
it('should render', () => {
expect(
render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
/>
)
Expand All @@ -83,7 +83,7 @@ describe('StringDetailsTable', () => {

it('should render textarea if edit mode', () => {
render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand All @@ -95,7 +95,7 @@ describe('StringDetailsTable', () => {

it('should update string value', () => {
render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand All @@ -111,7 +111,7 @@ describe('StringDetailsTable', () => {

it('should stay empty string after cancel', async () => {
render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand All @@ -132,7 +132,7 @@ describe('StringDetailsTable', () => {

it('should update value after apply', () => {
render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand All @@ -155,7 +155,7 @@ describe('StringDetailsTable', () => {
stringDataSelector.mockImplementation(stringDataSelectorMock)

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
/>
)
Expand All @@ -173,7 +173,7 @@ describe('StringDetailsTable', () => {
stringDataSelector.mockImplementation(stringDataSelectorMock)

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
onRefresh={onRefresh}
/>
Expand All @@ -197,7 +197,7 @@ describe('StringDetailsTable', () => {
stringDataSelector.mockImplementation(stringDataSelectorMock)

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
/>
)
Expand All @@ -211,7 +211,7 @@ describe('StringDetailsTable', () => {
stringDataSelector.mockImplementation(stringDataSelectorMock)

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
/>
)
Expand All @@ -225,7 +225,7 @@ describe('StringDetailsTable', () => {
stringDataSelector.mockImplementation(stringDataSelectorMock)

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
/>
)
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('StringDetailsTable', () => {
}))

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand All @@ -275,7 +275,7 @@ describe('StringDetailsTable', () => {
}))

render(
<StringDetailsTable
<StringDetailsValue
{...instance(mockedProps)}
isEditItem
setIsEdit={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Props {
onRefresh: (key: RedisResponseBuffer, type: KeyTypes | ModulesKeyTypes, args: IFetchKeyArgs) => void;
}

const StringDetailsTable = (props: Props) => {
const StringDetailsValue = (props: Props) => {
const { isEditItem, setIsEdit, onRefresh } = props

const { compressor = null } = useSelector(connectedInstanceSelector)
Expand Down Expand Up @@ -291,4 +291,4 @@ const StringDetailsTable = (props: Props) => {
)
}

export { StringDetailsTable }
export { StringDetailsValue }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StringDetailsValue } from './StringDetailsValue'
7 changes: 5 additions & 2 deletions redisinsight/ui/src/utils/monitorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { format } from 'date-fns'
import { isFinite } from 'lodash'

export const getFormatTime = (time: string = '') =>
format(new Date(+time * 1_000), 'HH:mm:ss.SSS')
export const getFormatTime = (time: string) =>
(typeof time === 'string' && isFinite(+time)
? format(new Date(+time * 1_000), 'HH:mm:ss.SSS')
: 'Invalid time')
19 changes: 13 additions & 6 deletions redisinsight/ui/src/utils/tests/monitorUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { getFormatTime } from '../monitorUtils'

const getOutputForFormatTime: any[] = [
['1641450853.668074', '09:34:13.668'],
['1641450854.612083', '09:34:14.612'],
['1641450856.616102', '09:34:16.616'],
['1641450858.616121', '09:34:18.616'],
[undefined, 'Invalid time'],
[null, 'Invalid time'],
[{}, 'Invalid time'],
['oeuoeu', 'Invalid time'],
[1, 'Invalid time'],
[11641450853, 'Invalid time'],
['1641450853.668074[0', 'Invalid time'],
['1641450853.668074', ':34:13.668'],
['1641450854.612083', ':34:14.612'],
['1641450856.616102', ':34:16.616'],
['1641450858.616121', ':34:18.616'],
]

describe.skip('formatToText', () => {
describe('formatToText', () => {
it.each(getOutputForFormatTime)('for input: %s (reply), should be output: %s',
(reply, expected) => {
const result = getFormatTime(reply)
expect(result).toBe(expected)
expect(result).toContain(expected)
})
})