Skip to content

Commit bd1fbc5

Browse files
authored
Add tests for column depth configuration (#2471)
1 parent fb25a1f commit bd1fbc5

File tree

6 files changed

+311
-10
lines changed

6 files changed

+311
-10
lines changed

extension/src/experiments/columns/collect/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import columnsFixture from '../../../test/fixtures/expShow/columns'
88
import workspaceChangesFixture from '../../../test/fixtures/expShow/workspaceChanges'
99
import uncommittedDepsFixture from '../../../test/fixtures/expShow/uncommittedDeps'
1010
import { ExperimentsOutput } from '../../../cli/dvc/reader'
11+
import { getConfigValue } from '../../../vscode/config'
1112

1213
jest.mock('../../../vscode/config')
1314

15+
const mockedGetConfigValue = jest.mocked(getConfigValue)
16+
mockedGetConfigValue.mockImplementation(() => 5)
17+
1418
describe('collectColumns', () => {
1519
it('should return a value equal to the columns fixture when given the output fixture', () => {
1620
const columns = collectColumns(outputFixture)

extension/src/experiments/columns/collect/util.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { Column, ColumnType } from '../../webview/contract'
22
import { Value } from '../../../cli/dvc/reader'
33
import { ConfigKey, getConfigValue } from '../../../vscode/config'
4-
import { INITIAL_TABLE_HEAD_MAX_LAYERS } from '../consts'
54

65
export type ColumnAccumulator = Record<string, Column>
76

8-
export const limitAncestorDepth = (ancestors: string[], sep: string) => {
7+
export const limitAncestorDepth = (
8+
ancestors: string[],
9+
sep: string,
10+
limit = 5
11+
) => {
912
const [path, ...rest] = ancestors
1013
/*
1114
The depth is only limited for the middle of the path array.
1215
The first and final layer are excluded, and the
1316
concatenated layer itself counts as one; because of this, we must subtract 3
1417
from what we want the final layer count to be.
1518
*/
16-
const collectedLimit =
17-
Number(getConfigValue(ConfigKey.EXP_TABLE_HEAD_MAX_LAYERS)) ||
18-
INITIAL_TABLE_HEAD_MAX_LAYERS
19-
19+
const collectedLimit = Number(
20+
getConfigValue(ConfigKey.EXP_TABLE_HEAD_MAX_LAYERS, limit)
21+
)
2022
const convertedLimit = (collectedLimit >= 3 ? collectedLimit : 3) - 3
2123
if (rest.length <= convertedLimit) {
2224
return ancestors

extension/src/experiments/columns/consts.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

extension/src/experiments/columns/model.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,62 @@ import outputFixture from '../../test/fixtures/expShow/output'
99
import columnsFixture from '../../test/fixtures/expShow/columns'
1010
import {
1111
deeplyNestedOutput,
12-
columns as deeplyNestedColumns
12+
columns as deeplyNestedColumns,
13+
columnsWithDepthOf10 as deeplyNestedColumnsWithDepthOf10,
14+
columnsWithDepthOf3 as deeplyNestedColumnsWithDepthOf3
1315
} from '../../test/fixtures/expShow/deeplyNested'
1416
import {
1517
dataTypesOutput,
1618
columns as dataTypesColumns
1719
} from '../../test/fixtures/expShow/dataTypes'
20+
import { getConfigValue } from '../../vscode/config'
1821

1922
jest.mock('../../vscode/config')
2023

24+
const mockedGetConfigValue = jest.mocked(getConfigValue)
25+
mockedGetConfigValue.mockImplementation(() => 5)
26+
2127
describe('ColumnsModel', () => {
2228
const exampleDvcRoot = 'test'
2329

2430
it('should return the expected columns when given the default output fixture', async () => {
2531
const model = new ColumnsModel('', buildMockMemento())
2632
await model.transformAndSet(outputFixture)
33+
expect(mockedGetConfigValue).toHaveBeenCalled()
2734
expect(model.getSelected()).toStrictEqual(columnsFixture)
2835
})
2936

3037
it('should return the expected columns when given the deeply nested output fixture', async () => {
3138
const model = new ColumnsModel('', buildMockMemento())
3239
await model.transformAndSet(deeplyNestedOutput)
40+
expect(mockedGetConfigValue).toHaveBeenCalled()
3341
expect(model.getSelected()).toStrictEqual(deeplyNestedColumns)
3442
})
3543

44+
it('should return the expected columns when the max depth config is set to 10', async () => {
45+
mockedGetConfigValue.mockImplementation(() => 10)
46+
const model = new ColumnsModel('', buildMockMemento())
47+
await model.transformAndSet(deeplyNestedOutput)
48+
expect(mockedGetConfigValue).toHaveBeenCalled()
49+
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf10)
50+
})
51+
52+
it('should return the expected columns when the max depth config is set to 3', async () => {
53+
mockedGetConfigValue.mockImplementation(() => 3)
54+
const model = new ColumnsModel('', buildMockMemento())
55+
await model.transformAndSet(deeplyNestedOutput)
56+
expect(mockedGetConfigValue).toHaveBeenCalled()
57+
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf3)
58+
})
59+
60+
it('should return the expected columns when the max depth config is set to -1', async () => {
61+
mockedGetConfigValue.mockImplementation(() => -1)
62+
const model = new ColumnsModel('', buildMockMemento())
63+
await model.transformAndSet(deeplyNestedOutput)
64+
expect(mockedGetConfigValue).toHaveBeenCalled()
65+
expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf3)
66+
})
67+
3668
it('should return the expected columns when given the data types output fixture', async () => {
3769
const model = new ColumnsModel('', buildMockMemento())
3870
await model.transformAndSet(dataTypesOutput)

extension/src/test/fixtures/expShow/deeplyNested.ts

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,267 @@ export const columns: Column[] = [
216216
}
217217
]
218218

219+
export const columnsWithDepthOf10: Column[] = [
220+
timestampColumn,
221+
{
222+
hasChildren: true,
223+
label: 'params.yaml',
224+
parentPath: 'params',
225+
path: 'params:params.yaml',
226+
type: ColumnType.PARAMS
227+
},
228+
{
229+
hasChildren: true,
230+
label: 'nested1',
231+
parentPath: 'params:params.yaml',
232+
path: 'params:params.yaml:nested1',
233+
type: ColumnType.PARAMS
234+
},
235+
{
236+
hasChildren: false,
237+
label: 'doubled',
238+
maxStringLength: 15,
239+
parentPath: 'params:params.yaml:nested1',
240+
path: 'params:params.yaml:nested1.doubled',
241+
pathArray: ['params', 'params.yaml', 'nested1', 'doubled'],
242+
type: ColumnType.PARAMS,
243+
types: ['string']
244+
},
245+
{
246+
hasChildren: true,
247+
label: 'nested2',
248+
parentPath: 'params:params.yaml:nested1',
249+
path: 'params:params.yaml:nested1.nested2',
250+
type: ColumnType.PARAMS
251+
},
252+
253+
{
254+
hasChildren: true,
255+
label: 'nested3',
256+
parentPath: 'params:params.yaml:nested1.nested2',
257+
path: 'params:params.yaml:nested1.nested2.nested3',
258+
type: ColumnType.PARAMS
259+
},
260+
{
261+
hasChildren: true,
262+
label: 'nested4',
263+
parentPath: 'params:params.yaml:nested1.nested2.nested3',
264+
path: 'params:params.yaml:nested1.nested2.nested3.nested4',
265+
type: ColumnType.PARAMS
266+
},
267+
{
268+
hasChildren: true,
269+
label: 'nested5',
270+
parentPath: 'params:params.yaml:nested1.nested2.nested3.nested4',
271+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5',
272+
type: ColumnType.PARAMS
273+
},
274+
{
275+
hasChildren: true,
276+
label: 'nested6',
277+
parentPath: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5',
278+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5.nested6',
279+
type: ColumnType.PARAMS
280+
},
281+
{
282+
hasChildren: false,
283+
label: 'nested7',
284+
maxStringLength: 6,
285+
parentPath:
286+
'params:params.yaml:nested1.nested2.nested3.nested4.nested5.nested6',
287+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5.nested6.nested7',
288+
pathArray: [
289+
'params',
290+
'params.yaml',
291+
'nested1',
292+
'nested2',
293+
'nested3',
294+
'nested4',
295+
'nested5',
296+
'nested6',
297+
'nested7'
298+
],
299+
type: ColumnType.PARAMS,
300+
types: ['string']
301+
},
302+
{
303+
hasChildren: true,
304+
label: 'nested5b',
305+
parentPath: 'params:params.yaml:nested1.nested2.nested3.nested4',
306+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5b',
307+
type: ColumnType.PARAMS
308+
},
309+
{
310+
hasChildren: false,
311+
label: 'nested6',
312+
maxStringLength: 23,
313+
parentPath: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5b',
314+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5b.nested6',
315+
pathArray: [
316+
'params',
317+
'params.yaml',
318+
'nested1',
319+
'nested2',
320+
'nested3',
321+
'nested4',
322+
'nested5b',
323+
'nested6'
324+
],
325+
type: ColumnType.PARAMS,
326+
types: ['string']
327+
},
328+
{
329+
hasChildren: false,
330+
label: 'doubled',
331+
maxStringLength: 16,
332+
parentPath: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5b',
333+
path: 'params:params.yaml:nested1.nested2.nested3.nested4.nested5b.doubled',
334+
pathArray: [
335+
'params',
336+
'params.yaml',
337+
'nested1',
338+
'nested2',
339+
'nested3',
340+
'nested4',
341+
'nested5b',
342+
'doubled'
343+
],
344+
type: ColumnType.PARAMS,
345+
types: ['string']
346+
},
347+
{
348+
hasChildren: false,
349+
label: 'outlier',
350+
maxStringLength: 1,
351+
parentPath: 'params:params.yaml',
352+
path: 'params:params.yaml:outlier',
353+
pathArray: ['params', 'params.yaml', 'outlier'],
354+
type: ColumnType.PARAMS,
355+
types: ['number'],
356+
maxNumber: 1,
357+
minNumber: 1
358+
}
359+
]
360+
361+
export const columnsWithDepthOf3: Column[] = [
362+
timestampColumn,
363+
{
364+
hasChildren: true,
365+
label: 'params.yaml',
366+
parentPath: 'params',
367+
path: 'params:params.yaml',
368+
type: ColumnType.PARAMS
369+
},
370+
{
371+
hasChildren: true,
372+
label: 'nested1',
373+
parentPath: 'params:params.yaml',
374+
path: 'params:params.yaml:nested1',
375+
type: ColumnType.PARAMS
376+
},
377+
378+
{
379+
hasChildren: false,
380+
label: 'doubled',
381+
maxStringLength: 15,
382+
parentPath: 'params:params.yaml:nested1',
383+
path: 'params:params.yaml:nested1.doubled',
384+
pathArray: ['params', 'params.yaml', 'nested1', 'doubled'],
385+
type: ColumnType.PARAMS,
386+
types: ['string']
387+
},
388+
{
389+
hasChildren: true,
390+
label: 'nested1.nested2.nested3.nested4.nested5.nested6',
391+
parentPath: 'params:params.yaml',
392+
path: 'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5%2Enested6',
393+
type: ColumnType.PARAMS
394+
},
395+
{
396+
hasChildren: false,
397+
label: 'nested7',
398+
maxStringLength: 6,
399+
parentPath:
400+
'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5%2Enested6',
401+
path: 'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5%2Enested6.nested7',
402+
pathArray: [
403+
'params',
404+
'params.yaml',
405+
'nested1',
406+
'nested2',
407+
'nested3',
408+
'nested4',
409+
'nested5',
410+
'nested6',
411+
'nested7'
412+
],
413+
type: ColumnType.PARAMS,
414+
types: ['string']
415+
},
416+
417+
{
418+
hasChildren: true,
419+
label: 'nested1.nested2.nested3.nested4.nested5b',
420+
parentPath: 'params:params.yaml',
421+
path: 'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5b',
422+
type: ColumnType.PARAMS
423+
},
424+
{
425+
hasChildren: false,
426+
label: 'nested6',
427+
maxStringLength: 23,
428+
parentPath:
429+
'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5b',
430+
path: 'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5b.nested6',
431+
pathArray: [
432+
'params',
433+
'params.yaml',
434+
'nested1',
435+
'nested2',
436+
'nested3',
437+
'nested4',
438+
'nested5b',
439+
'nested6'
440+
],
441+
type: ColumnType.PARAMS,
442+
types: ['string']
443+
},
444+
445+
{
446+
hasChildren: false,
447+
label: 'doubled',
448+
maxStringLength: 16,
449+
parentPath:
450+
'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5b',
451+
path: 'params:params.yaml:nested1%2Enested2%2Enested3%2Enested4%2Enested5b.doubled',
452+
pathArray: [
453+
'params',
454+
'params.yaml',
455+
'nested1',
456+
'nested2',
457+
'nested3',
458+
'nested4',
459+
'nested5b',
460+
'doubled'
461+
],
462+
type: ColumnType.PARAMS,
463+
types: ['string']
464+
},
465+
466+
{
467+
hasChildren: false,
468+
label: 'outlier',
469+
maxStringLength: 1,
470+
parentPath: 'params:params.yaml',
471+
path: 'params:params.yaml:outlier',
472+
pathArray: ['params', 'params.yaml', 'outlier'],
473+
type: ColumnType.PARAMS,
474+
types: ['number'],
475+
maxNumber: 1,
476+
minNumber: 1
477+
}
478+
]
479+
219480
export const rows = [
220481
{
221482
id: 'workspace',

extension/src/vscode/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ export enum ConfigKey {
1010
PYTHON_PATH = 'dvc.pythonPath'
1111
}
1212

13-
export const getConfigValue = <T = string>(key: ConfigKey): T =>
14-
workspace.getConfiguration().get(key, '') as unknown as T
13+
export const getConfigValue = <T = string, D = string>(
14+
key: ConfigKey,
15+
defaultValue?: D | T
16+
): T =>
17+
workspace.getConfiguration().get(key, defaultValue ?? '') as unknown as T
1518

1619
export const setConfigValue = (key: ConfigKey, value: unknown) =>
1720
workspace.getConfiguration().update(key, value)

0 commit comments

Comments
 (0)