-
Notifications
You must be signed in to change notification settings - Fork 28
Add tests for column depth configuration #2471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fcba9ce
b8b2300
252020b
3e27203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,30 +9,62 @@ import outputFixture from '../../test/fixtures/expShow/output' | |
| import columnsFixture from '../../test/fixtures/expShow/columns' | ||
| import { | ||
| deeplyNestedOutput, | ||
| columns as deeplyNestedColumns | ||
| columns as deeplyNestedColumns, | ||
| columnsWithDepthOf10 as deeplyNestedColumnsWithDepthOf10, | ||
| columnsWithDepthOf3 as deeplyNestedColumnsWithDepthOf3 | ||
| } from '../../test/fixtures/expShow/deeplyNested' | ||
| import { | ||
| dataTypesOutput, | ||
| columns as dataTypesColumns | ||
| } from '../../test/fixtures/expShow/dataTypes' | ||
| import { getConfigValue } from '../../vscode/config' | ||
|
|
||
| jest.mock('../../vscode/config') | ||
|
|
||
| const mockedGetConfigValue = jest.mocked(getConfigValue) | ||
| mockedGetConfigValue.mockImplementation(() => 5) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [I] Can also use a |
||
|
|
||
| describe('ColumnsModel', () => { | ||
| const exampleDvcRoot = 'test' | ||
|
|
||
| it('should return the expected columns when given the default output fixture', async () => { | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(outputFixture) | ||
| expect(mockedGetConfigValue).toHaveBeenCalled() | ||
| expect(model.getSelected()).toStrictEqual(columnsFixture) | ||
| }) | ||
|
|
||
| it('should return the expected columns when given the deeply nested output fixture', async () => { | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(deeplyNestedOutput) | ||
| expect(mockedGetConfigValue).toHaveBeenCalled() | ||
| expect(model.getSelected()).toStrictEqual(deeplyNestedColumns) | ||
| }) | ||
|
|
||
| it('should return the expected columns when the max depth config is set to 10', async () => { | ||
| mockedGetConfigValue.mockImplementation(() => 10) | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(deeplyNestedOutput) | ||
| expect(mockedGetConfigValue).toHaveBeenCalled() | ||
| expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf10) | ||
| }) | ||
|
|
||
| it('should return the expected columns when the max depth config is set to 3', async () => { | ||
| mockedGetConfigValue.mockImplementation(() => 3) | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(deeplyNestedOutput) | ||
| expect(mockedGetConfigValue).toHaveBeenCalled() | ||
| expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf3) | ||
| }) | ||
|
|
||
| it('should return the expected columns when the max depth config is set to -1', async () => { | ||
| mockedGetConfigValue.mockImplementation(() => -1) | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(deeplyNestedOutput) | ||
| expect(mockedGetConfigValue).toHaveBeenCalled() | ||
| expect(model.getSelected()).toStrictEqual(deeplyNestedColumnsWithDepthOf3) | ||
| }) | ||
|
|
||
| it('should return the expected columns when given the data types output fixture', async () => { | ||
| const model = new ColumnsModel('', buildMockMemento()) | ||
| await model.transformAndSet(dataTypesOutput) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,11 @@ export enum ConfigKey { | |
| PYTHON_PATH = 'dvc.pythonPath' | ||
| } | ||
|
|
||
| export const getConfigValue = <T = string>(key: ConfigKey): T => | ||
| workspace.getConfiguration().get(key, '') as unknown as T | ||
| export const getConfigValue = <T = string, D = string>( | ||
| key: ConfigKey, | ||
| defaultValue?: D | T | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this translates to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could be |
||
| ): T => | ||
| workspace.getConfiguration().get(key, defaultValue ?? '') as unknown as T | ||
|
|
||
| export const setConfigValue = (key: ConfigKey, value: unknown) => | ||
| workspace.getConfiguration().update(key, value) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[I] The usual pattern is to use
beforeEachwithresetAllMocksto keep tests independentI thin you could use
mockReturnValueOnceinstead ofmockImplementationas well. Final code would probably befor this particular file as we are not varying the option.