@@ -44,9 +44,16 @@ import { isErrorItem } from '../../../tree'
4444import { RegisteredCommands } from '../../../commands/external'
4545import { REVISIONS } from '../../fixtures/plotsDiff'
4646import * as FileSystem from '../../../fileSystem'
47- import { ExpShowOutput , experimentHasError } from '../../../cli/dvc/contract'
47+ import {
48+ EXPERIMENT_WORKSPACE_ID ,
49+ ExpShowOutput ,
50+ experimentHasError
51+ } from '../../../cli/dvc/contract'
52+ import { Experiment } from '../../../experiments/webview/contract'
4853import { COMMITS_SEPARATOR } from '../../../cli/git/constants'
4954import { BaseWebview } from '../../../webview'
55+ import * as PlotsCollectUtils from '../../../plots/model/collect'
56+ import { Operator } from '../../../experiments/model/filterBy'
5057
5158suite ( 'Plots Test Suite' , ( ) => {
5259 const disposable = Disposable . fn ( )
@@ -172,6 +179,84 @@ suite('Plots Test Suite', () => {
172179 )
173180 } )
174181
182+ describe ( 'Custom Plots Creation' , ( ) => {
183+ it ( 'should only use unfiltered experiments and commits in custom plots' , async ( ) => {
184+ const { plots, plotsModel, experimentsModel } = await buildPlots ( {
185+ disposer : disposable ,
186+ plotsDiff : plotsDiffFixture
187+ } )
188+
189+ const plotsCustomPlotsSpy = spy ( PlotsCollectUtils , 'collectCustomPlots' )
190+
191+ await plots . isReady ( )
192+
193+ stub ( experimentsModel , 'getFilters' )
194+ . onFirstCall ( )
195+ . returns ( [
196+ {
197+ operator : Operator . EQUAL ,
198+ path : 'params:params.yaml:epochs' ,
199+ value : 2
200+ }
201+ ] )
202+
203+ plotsModel . getCustomPlots ( )
204+
205+ const allExperiments : Experiment [ ] =
206+ experimentsModel . getWorkspaceCommitsAndExperiments ( )
207+
208+ const { experiments } = plotsCustomPlotsSpy . firstCall . args [ 0 ]
209+
210+ expect ( experiments ) . to . deep . equal (
211+ allExperiments . filter (
212+ ( { id, params } ) =>
213+ id !== EXPERIMENT_WORKSPACE_ID &&
214+ params ?. [ 'params.yaml' ] ?. epochs === 2
215+ )
216+ )
217+ } )
218+
219+ it ( 'should handle all experiments/commits being filtered' , async ( ) => {
220+ const { plots, plotsModel, experimentsModel } = await buildPlots ( {
221+ disposer : disposable ,
222+ plotsDiff : plotsDiffFixture
223+ } )
224+
225+ await plots . isReady ( )
226+
227+ stub ( experimentsModel , 'getUnfilteredCommitsAndExperiments' )
228+ . onFirstCall ( )
229+ . returns ( [ ] )
230+
231+ const customPlots = plotsModel . getCustomPlots ( )
232+
233+ expect ( customPlots ) . to . deep . equal ( {
234+ ...customPlotsFixture ,
235+ hasUnfilteredExperiments : false ,
236+ plots : [ ]
237+ } )
238+ } )
239+
240+ it ( 'should handle no plots being added yet' , async ( ) => {
241+ const { plots, plotsModel } = await buildPlots ( {
242+ disposer : disposable ,
243+ plotsDiff : plotsDiffFixture
244+ } )
245+
246+ await plots . isReady ( )
247+
248+ stub ( plotsModel , 'getCustomPlotsOrder' ) . onFirstCall ( ) . returns ( [ ] )
249+
250+ const customPlots = plotsModel . getCustomPlots ( )
251+
252+ expect ( customPlots ) . to . deep . equal ( {
253+ ...customPlotsFixture ,
254+ hasAddedPlots : false ,
255+ plots : [ ]
256+ } )
257+ } )
258+ } )
259+
175260 it ( 'should handle a section resized message from the webview' , async ( ) => {
176261 const { mockMessageReceived, plotsModel } = await buildPlotsWebview ( {
177262 disposer : disposable
0 commit comments