|
| 1 | +import { getValue } from './util' |
| 2 | +import rowsFixture from '../../test/fixtures/expShow/base/rows' |
| 3 | +import columnsFixture from '../../test/fixtures/expShow/base/columns' |
| 4 | +import { ColumnType } from '../webview/contract' |
| 5 | + |
| 6 | +describe('getValue', () => { |
| 7 | + const experiment = rowsFixture[0] |
| 8 | + |
| 9 | + const getPathArrayFromType = (columnType: ColumnType) => { |
| 10 | + const column = columnsFixture.find( |
| 11 | + ({ type, hasChildren }) => type === columnType && !hasChildren |
| 12 | + ) |
| 13 | + |
| 14 | + if (!column) { |
| 15 | + throw new Error('column not defined') |
| 16 | + } |
| 17 | + const { pathArray } = column |
| 18 | + expect(pathArray).toBeDefined() |
| 19 | + if (!pathArray) { |
| 20 | + throw new Error('pathArray not defined') |
| 21 | + } |
| 22 | + return pathArray |
| 23 | + } |
| 24 | + |
| 25 | + it('should return the expected value for an experiment given a metric', () => { |
| 26 | + const pathArray = getPathArrayFromType(ColumnType.METRICS) |
| 27 | + expect(getValue(experiment, pathArray)).toStrictEqual(1.775016188621521) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should return the expected value for an experiment given a param', () => { |
| 31 | + const pathArray = getPathArrayFromType(ColumnType.PARAMS) |
| 32 | + expect(getValue(experiment, pathArray)).toStrictEqual([0, 1]) |
| 33 | + }) |
| 34 | + |
| 35 | + it('should return the expected value for an experiment given a dep', () => { |
| 36 | + const pathArray = getPathArrayFromType(ColumnType.DEPS) |
| 37 | + expect(getValue(experiment, pathArray)).toStrictEqual('22a1a29') |
| 38 | + }) |
| 39 | + |
| 40 | + it('should not mutate the original array', () => { |
| 41 | + const pathArray = getPathArrayFromType(ColumnType.DEPS) |
| 42 | + const copy = [...pathArray] |
| 43 | + getValue(experiment, pathArray) |
| 44 | + expect(pathArray).toStrictEqual(copy) |
| 45 | + }) |
| 46 | +}) |
0 commit comments