describe('math editor', () => {

    before(waitUntil(() => $('[data-js="tools"]').length > 0 &&  $('[data-js="tools"]').is(':hidden')))

    describe('init', () => {
        it('answer field is contenteditable', () => {
            const $answer = $('[data-js="answer"]')
            expect($answer).to.have.attr('contenteditable', 'true')
        })
        it('tools are hidden', () => expect($('.rich-text-editor-tools')).to.be.hidden)
    })

    describe('focus rich text', () => {
        before(() => $('.answer1').focus())
        before(waitUntil(() => $('[data-js="tools"]').is(':visible')))

        it('shows tools', () => expect($('[data-js="charactersList"]')).to.be.visible)
        it('hide math tools', () => expect($('[data-js="mathToolbar"]')).to.be.hidden)
    })

    describe('start math', () => {
        before(() => $('[data-js="newEquation"]').mousedown())

        it('shows math tools', () => expect($('[data-js="mathToolbar"]')).to.be.visible)
        it('shows math editor', () => expect($('[data-js="mathEditor"]')).to.be.visible)
    })

    describe('keeps both fiels in sync', () => {
        before(() => $('[data-js="latexField"]').focus().val('x+y').keyup())
        before(done => setTimeout(done, 0))

        it('shows math in latex field', () => expect($('[data-js="equationField"]')).to.have.text('x+y​'))
        it('shows math in img', () => expect($('img:first')).to.have.attr('src','/math.svg?latex=x%2By'))
    })
})

function waitUntil(condition) {
    return done => _waitUntil(condition, done)
}

function _waitUntil(condition, done) {
    if (condition()) done()
    else setTimeout(() => _waitUntil(condition, done), 200)
}

@@ -29,32 +29,58 @@
 %3E %7B%0A%0A    before(
+'wait for tools to hide', 
 waitUntil(() =%3E 
@@ -144,21 +144,27 @@
 %5D').
-is(':hidden')
+position().top %3C 0 
 ))%0A%0A
@@ -381,96 +381,8 @@
  %7D)%0A
-        it('tools are hidden', () =%3E expect($('.rich-text-editor-tools')).to.be.hidden)%0A
     
@@ -484,16 +484,42 @@
  before(
+'wait for tools visible', 
 waitUnti
@@ -1156,24 +1156,68 @@
 ').keyup())%0A
+        before(() =%3E $('.answer1').focus())%0A
         befo
@@ -1286,32 +1286,46 @@
 ex field', () =%3E
+ %7B%0A           
  expect($('%5Bdata
@@ -1369,11 +1369,20 @@
 'x+y
-%E2%80%8B
 ')
+%0A        %7D
 )%0A  

Fix tests