I'm working on an app that combines Ember with jquery-terminal
to help users learn. I apologise for the long question up front!
I love to work in a TDD style, but am struggling to get this working.
What I want to do is simulate user input into jquery-terminal
and assert that the correct response is displayed in the terminal. I've dug through the source code and perhaps I'm missing something, but I can't seem to find a place to add the user input. The terminal ends up outputting this:-
<div id="terminal" class="terminal">
<div class="terminal-output"></div>
<div class="cmd" style="width: 100%;">
<span class="prompt">TryRuby:> </span>
<span></span>
<span class="cursor blink"> </span>
<span></span>
<textarea class="clipboard"></textarea>
</div>
</div>
The text entered by the user is rendered in the first unnamed span, but inserting text here does not make it available to jquery-terminal
on submit I get the same response as if it were blank.
What I want to simulate is this (pseudocode)
test('user enters help and submits', function() {
var input = $('#terminal') // find the right node / place to bind is my problem
input.text = 'help'
keyEvent(input, 'keydown', 13) // simulate hitting enter
var match = /next: move to the next lesson/
ok(match.test($('.terminal-output'), 'Expected to find "next: move to the next lesson"')
})
Now it all works perfectly if I visit the page and manually type in, but I want this done programatically.
Any suggestions would be welcome!