Skip to content

Commit

Permalink
test creation of children from encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Sep 28, 2022
1 parent c4d23b6 commit e10c8d6
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions extension/src/plots/paths/tree.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Uri } from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import { EncodingType } from './collect'
import { PlotsPathsTree } from './tree'
import { WorkspacePlots } from '../workspace'
import { ResourceLocator } from '../../resourceLocator'
import { InternalCommands } from '../../commands/internal'
import { Plots } from '..'
import { buildMockedEventEmitter } from '../../test/util/jest'
import { Shape, StrokeDash } from '../multiSource/constants'
import { join } from '../../test/util/path'

const mockedDisposable = jest.mocked(Disposable)
const mockedGetChildPaths = jest.fn()

jest.mock('vscode')
jest.mock('@hediet/std/disposable')

beforeEach(() => {
jest.resetAllMocks()
mockedDisposable.fn.mockReturnValue({
track: function <T>(disposable: T): T {
return disposable
}
} as unknown as (() => void) & Disposer)
})

describe('PlotsPathsTree', () => {
it('should return the correct children for multi source plots (encoding elements)', () => {
const mockedWorkspacePlots = {
getRepository: () =>
({ getChildPaths: mockedGetChildPaths } as unknown as Plots),
pathsChanged: buildMockedEventEmitter()
} as unknown as WorkspacePlots
const mockedInternalCommands = {
registerExternalCommand: jest.fn()
} as unknown as InternalCommands
const resourceLocator = new ResourceLocator(Uri.file(__filename))

const plotsPathTree = new PlotsPathsTree(
mockedWorkspacePlots,
mockedInternalCommands,
resourceLocator
)

mockedGetChildPaths.mockReturnValueOnce([
{
label: 'A',
type: EncodingType.STROKE_DASH,
value: StrokeDash[0]
},
{
label: 'Y',
type: EncodingType.SHAPE,
value: Shape[1]
}
])

const children = plotsPathTree.getRepositoryChildren(__dirname, undefined)
expect(children).toStrictEqual([
{
collapsibleState: 0,
description: undefined,
dvcRoot: __dirname,
iconPath: Uri.file(
join(__filename, 'resources', 'plots', 'stroke-dash-1-0.svg')
),
label: 'A',
path: 'A'
},
{
collapsibleState: 0,
description: undefined,
dvcRoot: __dirname,
iconPath: Uri.file(
join(__filename, 'resources', 'plots', 'circle.svg')
),
label: 'Y',
path: 'Y'
}
])
})
})

0 comments on commit e10c8d6

Please sign in to comment.