import { CommandShape, TestShape } from '@seleniumhq/side-model' import { randomUUID } from 'crypto' import BaseController from '../Base' export default class TestsController extends BaseController { static commandFromData(step: Partial = {}): CommandShape { return { ...step, command: step.command || 'click', target: step.target || '', value: step.value || '', id: randomUUID(), } } getByID(id: string): TestShape { return this.session.projects.project.tests.find( (t) => t.id === id ) as TestShape } getByName(name: string): TestShape { return this.session.projects.project.tests.find( (t) => t.name === name ) as TestShape } async addSteps( _testID: string, _index: number, stepFields: Partial[] = [] ): Promise { if (stepFields.length < 1) { return [TestsController.commandFromData()] } return stepFields.map(TestsController.commandFromData) } async create(name?: string): Promise { return { id: randomUUID(), name: name===undefined? 'New Test' : name, commands: [ { id: randomUUID(), command: 'open', target: '/', value: '', }, ], } } }