-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add error handling for Plot Wizard plots with x fields #4798
Merged
julieg18
merged 9 commits into
allow-plot-wizard-multi-x-selection
from
add-error-handling-for-plot-wizard-field-dict
Oct 13, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
93cb1e8
Add missing code updates
julieg18 fe3a820
Cleanup code
julieg18 1872da3
Merge branch 'allow-plot-wizard-multi-x-selection' into add-error-han…
julieg18 6e2a19e
fix incorrectly written y test
julieg18 9728e8f
Add testing for toast messages
julieg18 fab565c
Merge branch 'allow-plot-wizard-multi-x-selection' into add-error-han…
julieg18 17e2e52
Merge branch 'allow-plot-wizard-multi-x-selection' into add-error-han…
julieg18 57716d3
Fix typo
julieg18 6c7823f
Apply review comments
julieg18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -560,6 +560,35 @@ describe('pickPlotConfiguration', () => { | |
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(2) | ||
expect(noFieldsResult).toStrictEqual(undefined) | ||
}) | ||
|
||
it('should show a toast if user selects more than one key in a file for an x field', async () => { | ||
mockedPickFiles.mockResolvedValueOnce(['/file.json']) | ||
mockedLoadDataFiles.mockResolvedValueOnce([ | ||
{ data: mockValidData, file: 'file.json' } | ||
]) | ||
mockedQuickPickOne.mockResolvedValueOnce('simple') | ||
mockedGetInput.mockResolvedValueOnce('simple_plot') | ||
mockedQuickPickUserOrderedValues.mockResolvedValueOnce([ | ||
{ | ||
file: 'file.json', | ||
key: 'actual' | ||
}, | ||
{ | ||
file: 'file.json', | ||
key: 'prob' | ||
} | ||
]) | ||
|
||
const result = await pickPlotConfiguration('/') | ||
|
||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(1) | ||
expect(result).toStrictEqual(undefined) | ||
expect(mockedShowError).toHaveBeenCalledTimes(1) | ||
expect(mockedShowError).toHaveBeenCalledWith( | ||
'file.json cannot have more than one metric selected. See [an example](https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#available-configuration-fields) of a plot with multiple x metrics.' | ||
) | ||
}) | ||
|
||
it('should return early if the user does not pick a y field', async () => { | ||
mockedPickFiles.mockResolvedValue(['/file.json']) | ||
mockedLoadDataFiles.mockResolvedValue([ | ||
|
@@ -568,17 +597,109 @@ describe('pickPlotConfiguration', () => { | |
mockedQuickPickOne.mockResolvedValue('simple') | ||
mockedGetInput.mockResolvedValue('simple_plot') | ||
mockedQuickPickUserOrderedValues | ||
.mockResolvedValueOnce([ | ||
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. This test was actually incorrectly written. See https://github.com/iterative/vscode-dvc/pull/4797/files#r1355869332 |
||
{ | ||
file: 'file.json', | ||
key: 'actual' | ||
} | ||
]) | ||
.mockResolvedValueOnce(undefined) | ||
.mockResolvedValueOnce([ | ||
{ | ||
file: 'file.json', | ||
key: 'actual' | ||
} | ||
]) | ||
.mockResolvedValueOnce([]) | ||
|
||
const undefinedResult = await pickPlotConfiguration('/') | ||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(1) | ||
|
||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(2) | ||
expect(undefinedResult).toStrictEqual(undefined) | ||
|
||
const emptyFieldsResult = await pickPlotConfiguration('/') | ||
const noFieldsResult = await pickPlotConfiguration('/') | ||
|
||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(4) | ||
expect(noFieldsResult).toStrictEqual(undefined) | ||
}) | ||
|
||
it('should show a toast if user does not select the same amount of x and y fields (if there are multiple x fields)', async () => { | ||
mockedPickFiles.mockResolvedValueOnce(['/file.json']) | ||
mockedLoadDataFiles.mockResolvedValueOnce([ | ||
{ data: mockValidData, file: 'file.json' }, | ||
{ data: mockValidData, file: 'file2.json' } | ||
]) | ||
mockedQuickPickOne.mockResolvedValueOnce('simple') | ||
mockedGetInput.mockResolvedValueOnce('simple_plot') | ||
mockedQuickPickUserOrderedValues | ||
.mockResolvedValueOnce([ | ||
{ | ||
file: 'file.json', | ||
key: 'actual' | ||
}, | ||
{ | ||
file: 'file2.json', | ||
key: 'prob' | ||
} | ||
]) | ||
.mockResolvedValueOnce([ | ||
{ | ||
file: 'file.json', | ||
key: 'prob' | ||
} | ||
]) | ||
|
||
const result = await pickPlotConfiguration('/') | ||
|
||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(2) | ||
expect(emptyFieldsResult).toStrictEqual(undefined) | ||
expect(result).toStrictEqual(undefined) | ||
expect(mockedShowError).toHaveBeenCalledTimes(1) | ||
expect(mockedShowError).toHaveBeenCalledWith( | ||
'Found 2 x metrics and 1 y metric(s). When there are multiple x metrics selected there must be an equal number of y metrics. See [an example](https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#available-configuration-fields) of a plot with multiple x metrics.' | ||
) | ||
}) | ||
|
||
it('should show a toast if user selects multiple x fields and more than one key in a file for an y field', async () => { | ||
mockedPickFiles.mockResolvedValueOnce(['/file.json']) | ||
mockedLoadDataFiles.mockResolvedValueOnce([ | ||
{ data: mockValidData, file: 'file.json' }, | ||
{ | ||
data: mockValidData.map((value, ind) => ({ ...value, step: ind })), | ||
file: 'file2.json' | ||
} | ||
]) | ||
mockedQuickPickOne.mockResolvedValueOnce('simple') | ||
mockedGetInput.mockResolvedValueOnce('simple_plot') | ||
mockedQuickPickUserOrderedValues | ||
.mockResolvedValueOnce([ | ||
{ | ||
file: 'file.json', | ||
key: 'actual' | ||
}, | ||
{ | ||
file: 'file2.json', | ||
key: 'prob' | ||
} | ||
]) | ||
.mockResolvedValueOnce([ | ||
{ | ||
file: 'file2.json', | ||
key: 'actual' | ||
}, | ||
{ | ||
file: 'file2.json', | ||
key: 'step' | ||
} | ||
]) | ||
|
||
const result = await pickPlotConfiguration('/') | ||
|
||
expect(mockedQuickPickUserOrderedValues).toHaveBeenCalledTimes(2) | ||
expect(result).toStrictEqual(undefined) | ||
expect(mockedShowError).toHaveBeenCalledTimes(1) | ||
expect(mockedShowError).toHaveBeenCalledWith( | ||
'file2.json cannot have more than one metric selected. See [an example](https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#available-configuration-fields) of a plot with multiple x metrics.' | ||
) | ||
}) | ||
|
||
it('should return early if the user does not pick a title', async () => { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
At this point, we've got around 20 different tests in this
describe
block. I'd like to break group these tests to make things more readable but I'll do it in a separate pr since that would involve touching the whole file. Updated #4654.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.
[Q] What is the problem with having 20 tests in a block?
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.
Not necessarily a problem but I find it easier to navigate/update a test file when tests are grouped. Looking at this file, we could group file picking and field picking into its own blocks. Though, of course, no strong preference, I'm happy to leave it as is if preferred.