Skip to content

Commit

Permalink
add tests for focusing sections
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Mar 14, 2023
1 parent f926e43 commit f9c4f35
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
64 changes: 64 additions & 0 deletions extension/src/test/suite/setup/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import * as Python from '../../../extensions/python'
import { STUDIO_ACCESS_TOKEN_KEY } from '../../../setup/token'
import { ContextKey } from '../../../vscode/context'
import { Setup } from '../../../setup'
import { Section } from '../../../setup/webview/contract'

suite('Setup Test Suite', () => {
const disposable = Disposable.fn()
Expand Down Expand Up @@ -789,5 +790,68 @@ suite('Setup Test Suite', () => {

expect(mockDelete).to.be.calledWithExactly(STUDIO_ACCESS_TOKEN_KEY)
})

it('should send the appropriate messages to the webview to focus different sections', async () => {
const { setup, messageSpy } = buildSetup(disposable)
messageSpy.restore()

const webview = await setup.showSetup()
await webview.isReady()

const mockShow = stub(webview, 'show')

const getNewMessageReceived = () => {
mockShow.resetHistory()
mockShow.resetBehavior()
return new Promise(resolve =>
mockShow.callsFake(() => {
resolve(undefined)
return Promise.resolve(true)
})
)
}

const initialMessage = getNewMessageReceived()

void setup.showSetup()

await initialMessage

expect(mockShow).to.be.calledWithMatch({ sectionCollapsed: undefined })

const focusExperiments = getNewMessageReceived()

void setup.showSetup(Section.EXPERIMENTS)

await focusExperiments

expect(mockShow).to.be.calledWithMatch({
sectionCollapsed: {
[Section.EXPERIMENTS]: false,
[Section.STUDIO]: true
}
})

const focusStudio = getNewMessageReceived()

void setup.showSetup(Section.STUDIO)

await focusStudio

expect(mockShow).to.be.calledWithMatch({
sectionCollapsed: {
[Section.EXPERIMENTS]: true,
[Section.STUDIO]: false
}
})

const openUnchanged = getNewMessageReceived()

void setup.showSetup()

await openUnchanged

expect(mockShow).to.be.calledWithMatch({ sectionCollapsed: undefined })
})
})
})
55 changes: 54 additions & 1 deletion webview/src/setup/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'dvc/src/webview/contract'
import '@testing-library/jest-dom/extend-expect'
import React from 'react'
import { SetupData } from 'dvc/src/setup/webview/contract'
import { Section, SetupData } from 'dvc/src/setup/webview/contract'
import { App } from './App'
import { vsCodeApi } from '../../shared/api'

Expand All @@ -24,6 +24,7 @@ const renderApp = ({
needsGitInitialized,
projectInitialized,
pythonBinPath,
sectionCollapsed,
shareLiveToStudio
}: SetupData) => {
render(<App />)
Expand All @@ -40,6 +41,7 @@ const renderApp = ({
needsGitInitialized,
projectInitialized,
pythonBinPath,
sectionCollapsed,
shareLiveToStudio
},
type: MessageToWebviewType.SET_DATA
Expand Down Expand Up @@ -539,4 +541,55 @@ describe('App', () => {
})
})
})

describe('focused section', () => {
const testData = {
canGitInitialize: false,
cliCompatible: true,
hasData: false,
isPythonExtensionInstalled: true,
isStudioConnected: true,
needsGitCommit: false,
needsGitInitialized: false,
projectInitialized: true,
pythonBinPath: 'python',
shareLiveToStudio: false
}
const experimentsText = 'Your project contains no data'
const studioButtonText = 'Update Token'

it('should render the app with the Studio section collapsed if the Experiments section is focused', () => {
renderApp({
...testData,
sectionCollapsed: {
[Section.EXPERIMENTS]: false,
[Section.STUDIO]: true
}
})
mockPostMessage.mockClear()
const studio = screen.getByText('Studio')
expect(studio).toBeVisible()
expect(screen.queryByText(studioButtonText)).not.toBeVisible()
const experiments = screen.getByText('Experiments')
expect(experiments).toBeVisible()
expect(screen.getByText(experimentsText)).toBeVisible()
})

it('should render the app with the Experiments section collapsed if the Studio section is focused', () => {
renderApp({
...testData,
sectionCollapsed: {
[Section.EXPERIMENTS]: true,
[Section.STUDIO]: false
}
})
mockPostMessage.mockClear()
const studio = screen.getByText('Studio')
expect(studio).toBeVisible()
expect(screen.queryByText(studioButtonText)).toBeVisible()
const experiments = screen.getByText('Experiments')
expect(experiments).toBeVisible()
expect(screen.getByText(experimentsText)).not.toBeVisible()
})
})
})

0 comments on commit f9c4f35

Please sign in to comment.