yodaos-project / yoda.js

Application Framework that powered YodaOS
Apache License 2.0
187 stars 48 forks source link

app: ui testing API proposal #671

Closed legendecas closed 5 years ago

legendecas commented 5 years ago

Is your feature request related to a problem? Please describe. Provides a series naïve API(s) to enable application UI testing.

Describe the solution you'd like

API Shapes

Bootstrap

bootstrap(): TestSuite

TestSuite

TestSuite#application(): TSApplication

TestSuite#audioFocus(): TSAudioFocus

TestSuite#speechSynthesis(): TSSpeechSynthesis

TSApplication

TSApplication#openUrl()

TSAudioFocus

TSAudioFocus#on('gain')

TSAudioFocus#on('loss')

TSSpeechSynthesis

TSSpeechSynthesis#startRecord()

TSSpeechSynthesis#stopRecord()

TSSpeechSynthesis#getRecords()

TSSpeechSynthesis#clearRecords()

Usage

var bootstrap = require('@yodaos/volksempfanger/bootstrap')
var test = require('tape')

test('speech synthesis test example', t => {
  var tt = bootstrap()
  var app = tt.application()
  var speechSynthesis = tt.speechSynthesis()
  var audioFocus = tt.audioFocus()
  audioFocus.on('gain', focus => {
    speechSynthesis.startRecord()
  })
  audioFocus.on('loss', focus => {
    speechSynthesis.stopRecord()
    var utters = speechSynthesis.getRecords()
    speechSynthesis.clearRecords()
    t.deepEqual(utters, [{ text: 'foo' }])
    tt.teardown()
    t.end()
  })
  app.openUrl('yoda-app://cloud-player/play?text=foo')
})

A wrapper over @yodaos/volksempfanger/bootstrap with tape example:

var test = require('@yodaos/volksempfanger/tape')

test('speech synthesis test example', t => {
  var app = t.application()
  var speechSynthesis = t.speechSynthesis()
  var audioFocus = t.audioFocus()
  audioFocus.on('gain', focus => {
    speechSynthesis.startRecord()
  })
  audioFocus.on('loss', focus => {
    speechSynthesis.stopRecord()
    var utters = speechSynthesis.getRecords()
    speechSynthesis.clearRecords()
    t.deepEqual(utters, [{ text: 'foo' }])
    t.end()
  })
  app.openUrl('yoda-app://cloud-player/play?text=foo')
})

Describe alternatives you've considered Please describe alternative solutions or features you have considered.

yorkie commented 5 years ago

Some methods description?

legendecas commented 5 years ago

Landed on https://github.com/yodaos-project/yodart/pull/700