Permalink
Browse files

Fix test run navigation

  • Loading branch information...
1 parent 6200cfc commit 28aff9870a770ce0fb48553e5849a88c2cdfd21e @alexanderteinum alexanderteinum committed Apr 26, 2013
View
@@ -22,6 +22,10 @@ tr.dim {
opacity: 0.25;
}
+span.dim {
+ opacity: 0.5;
+}
+
tr.pass {
color: #00a000;
background-color: #f0fff0;
View
@@ -181,13 +181,17 @@
<script type="text/template" id="test-case-template">
<p class="lead"><%= _question %></p>
<div style="margin-bottom: 8px;">
- <a href="<%= previousUrl %>" class="btn btn-link" style="margin-right: 1em;"><i class="icon-angle-left"></i> <%= _previousTest %></a>
+ <% if (!isAtFirst) { %>
+ <a href="<%= previousUrl %>" style="margin-right: 2em;"><i class="icon-angle-left"></i> <%= _previousTest %></a>
+ <% } else { %>
+ <span class="dim" style="margin-right: 2em;"><i class="icon-angle-left"></i> <%= _previousTest %></span>
+ <% } %>
<div class="btn-group">
<% _.each(answers, function(answer) { %>
<button class="answer btn" value="<%= answer.value %>"><%= answer._value %></button>
<% }); %>
</div>
- <a href="<%= nextUrl %>" class="btn btn-link" style="margin-left: 1em;"><%= _skipTest %> <i class="icon-angle-right"></i></a>
+ <a href="<%= nextUrl %>" style="margin-left: 2em;"><%= _skipTest %> <i class="icon-angle-right"></i></a>
</div>
</script>
@@ -8,9 +8,9 @@ define ['backbone', 'socketio', 'collections/tests'], (Backbone, io, Tests) ->
}
initialize: (socket) ->
_.extend(this, Backbone.Events)
- this.set 'socket', socket
+ @set 'socket', socket
- socket.emit('get tests', this.get('webPage'))
+ socket.emit('get tests', @get('webPage'))
that = this
socket.on('tests', (data) ->
@@ -21,38 +21,33 @@ define ['backbone', 'socketio', 'collections/tests'], (Backbone, io, Tests) ->
that.set('state', 'loaded')
)
- this.bind('change:webPage', this.fetchTests, this)
- verifyTests: () ->
- this.get('tests').where({category: 'verify'})
- nextTest: () ->
- this.set('currentTest', this.get('currentTest') + 1)
- previousTest: () ->
- this.set('currentTest', this.get('currentTest') - 1)
+ @bind('change:webPage', @fetchTests, this)
+ fetchTests: () ->
+ @set('state', 'loading')
+ @get('socket').emit('get tests', @get('webPage'))
+ getVerifyTests: () ->
+ _.first(@get('tests').where({category: 'verify'}), 10)
+ @get('tests').where({category: 'verify'})
getCurrentTest: () ->
- if this.get('tests').length == 0
+ if @get('tests').length == 0
null
else
- this.verifyTests()[this.get('currentTest')]
- fetchTests: () ->
- this.set('state', 'loading')
- this.get('socket').emit('get tests', this.get('webPage'))
- testCount: () ->
- Math.min(this.verifyTests().length, 10)
+ @getVerifyTests()[@get('currentTest')]
progress: () ->
- parseInt((this.get('currentTest') / (this.testCount() - 1)) * 100)
- isAtLast: () ->
- this.get('currentTest') == (this.testCount() - 1)
+ parseInt((@get('currentTest') / (@getVerifyTests().length - 1)) * 100)
isAtFirst: () ->
- this.get('currentTest') == 0
+ @get('currentTest') == 0
+ isAtLast: () ->
+ @get('currentTest') == (@getVerifyTests().length - 1)
setAnswer: (answer) ->
- this.verifyTests()[this.get('currentTest')].set('answer', answer)
- this.trigger 'change:answer'
+ @getVerifyTests()[@get('currentTest')].set('answer', answer)
+ @trigger 'change:answer'
setWebPage: (url) ->
addProtocol = (url) ->
if url.substring(0, 7) isnt 'http://' and url.substring(0, 8) isnt 'https://'
'http://' + url
else
url
- this.set 'webPage', addProtocol(url)
+ @set 'webPage', addProtocol(url)
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -7,9 +7,12 @@ define ['jquery', 'underscore', 'backbone'], ($, _, Backbone) ->
}
getCurrentRoute: () ->
if not Backbone.history.fragment
- 'home'
+ return 'home'
+ else if Backbone.history.fragment.substr(0, 4) is 'test'
+ return 'test'
else
- Backbone.history.fragment
+ return Backbone.history.fragment
+
initialize: () ->
@render()
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -27,7 +27,7 @@ define ['jquery', 'underscore', 'backbone'], ($, _, Backbone) ->
results = []
testIndex = 0
_.each(@options.testRun.get('tests').models, (element, index, list) ->
- results.push(that.transformResult(element.attributes, testIndex, that.options.testRun.testCount(), that))
+ results.push(that.transformResult(element.attributes, testIndex, that.options.testRun.getVerifyTests().length, that))
if element.attributes.category == 'verify'
testIndex++
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -45,7 +45,7 @@ define ['jquery', 'underscore', 'backbone'], ($, _, Backbone) ->
'answers': answers
'nextUrl': @nextUrl()
'previousUrl': @previousUrl()
- 'previousExtraClass': @previousExtraClass()
+ 'isAtFirst': @options.testRun.isAtFirst()
})
)
@@ -65,8 +65,8 @@ define ['jquery', 'underscore', 'backbone'], ($, _, Backbone) ->
return '#test/' + (@options.testRun.get('currentTest') + 1)
clickAnswer: (el) ->
@options.testRun.setAnswer(el.currentTarget.value)
- if (@options.testRun.isAtLast() == true)
- return '#result'
+ if @options.testRun.isAtLast()
+ @options.router.navigate('result', { trigger: true })
else
- @options.testRun.nextTest()
+ @options.router.navigate('test/' + (@options.testRun.get('currentTest') + 1), { trigger: true })
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 28aff98

Please sign in to comment.