import _ from 'lodash'
import { action } from 'mobx'
import { observer } from 'mobx-react'
import React, { Component, MouseEvent } from 'react'
import events, { Events } from '../lib/events'
import { RunnablesError, RunnablesErrorModel } from './runnable-error'
import Runnable from './runnable-and-suite'
import RunnableHeader from './runnable-header'
import { RunnablesStore, RunnableArray } from './runnables-store'
import { Scroller } from '../lib/scroller'
import { AppState } from '../lib/app-state'
import FileOpener from '../lib/file-opener'
const Loading = () => (
Your tests are loading...
)
interface RunnablesEmptyStateProps {
spec: Cypress.Cypress['spec']
eventManager?: Events
}
const RunnablesEmptyState = ({ spec, eventManager = events }: RunnablesEmptyStateProps) => {
const _launchStudio = (e: MouseEvent) => {
e.preventDefault()
// root runnable always has r1 as id
eventManager.emit('studio:init:suite', 'r1')
}
const isAllSpecs = spec.absolute === '__all' || spec.relative === '__all'
return (
No tests found.
Cypress could not detect tests in this file.
{ !isAllSpecs && (
<>
Open file in IDE
Write a test using your preferred text editor.
Create test with Cypress Studio
Use an interactive tool to author a test right here.
>
)}
Need help? Learn how to test your application with Cypress
)
}
interface RunnablesListProps {
runnables: RunnableArray
}
const RunnablesList = observer(({ runnables }: RunnablesListProps) => (
{_.map(runnables, (runnable) => )}
))
export interface RunnablesContentProps {
runnablesStore: RunnablesStore
spec: Cypress.Cypress['spec']
error?: RunnablesErrorModel
}
const RunnablesContent = observer(({ runnablesStore, spec, error }: RunnablesContentProps) => {
const { isReady, runnables, runnablesHistory } = runnablesStore
if (!isReady) {
return
}
// show error if there are no tests, but only if there
// there isn't an error passed down that supercedes it
if (!error && !runnablesStore.runnables.length) {
return
}
if (error) {
return
}
const specPath = spec.relative
const isRunning = specPath === runnablesStore.runningSpec
return
})
export interface RunnablesProps {
error?: RunnablesErrorModel
runnablesStore: RunnablesStore
spec: Cypress.Cypress['spec']
scroller: Scroller
appState?: AppState
}
@observer
class Runnables extends Component {
render () {
const { error, runnablesStore, spec } = this.props
return (
)
}
componentDidMount () {
const { scroller, appState } = this.props
scroller.setContainer(this.refs.container as Element, action('user:scroll:detected', () => {
if (appState && appState.isRunning) {
appState.temporarilySetAutoScrolling(false)
}
}))
}
}
export { RunnablesList }
export default Runnables