-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test creation of children from encoding
- Loading branch information
1 parent
2f78335
commit 1211442
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 items for 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' | ||
} | ||
]) | ||
}) | ||
}) |