Skip to content

Commit dc021d3

Browse files
author
Jason Madsen
committed
ember quiz index loads all quiz records
closes CNVS-10206 test plan: - enable fabulous ember quizzes - create more than 10 quizzes - visit quiz index - verify that all quizzes are showing Change-Id: I05d6d428edffa9b564f444c9326fcd6bef034138 Reviewed-on: https://gerrit.instructure.com/27999 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Product-Review: Jason Madsen <jmadsen@instructure.com>
1 parent 5370d2d commit dc021d3

9 files changed

Lines changed: 135 additions & 95 deletions

File tree

app/coffeescripts/ember/quizzes/config/app.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ define [
44
'../../shared/components/ic_publish_icon_component'
55
], (Ember) ->
66

7+
Ember.$.ajaxPrefilter (options, originalOptions, xhr) ->
8+
options.dataType = 'json'
9+
options.headers = 'Accept': 'application/vnd.api+json'
10+
711
Ember.Application.extend
812

913
rootElement: '#content'
10-
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
define [
22
'ember',
3-
'ic-ajax',
3+
'../shared/fetch_all_jsonapi',
44
'../shared/environment'
5-
], (Ember, ajax, environment) ->
6-
7-
# http://emberjs.com/guides/routing/
8-
# http://emberjs.com/api/classes/Ember.Route.html
5+
], (Ember, fetchAll, environment) ->
96

107
QuizzesRoute = Ember.Route.extend
118

129
model: (params) ->
1310
environment.setEnv(ENV)
1411
id = environment.get('courseId')
15-
ajax.raw(
16-
url: "/api/v1/courses/#{id}/quizzes",
17-
headers:
18-
Accept : "application/vnd.api+json"
19-
).then ({response}) ->
20-
response.quizzes
12+
13+
fetchAll("/api/v1/courses/#{id}/quizzes")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
define [
2+
'ember'
3+
'ic-ajax'
4+
], ({$, ArrayProxy}, ajax) ->
5+
6+
handlePagination = (result) ->
7+
{meta} = result.response
8+
{pagination} = meta
9+
records = result.response[meta.primaryCollection]
10+
11+
if pagination.next
12+
ajax.raw(pagination.next).then(handlePagination).then (_newRecords) ->
13+
records.concat(_newRecords)
14+
else
15+
Em.RSVP.resolve(records)
16+
17+
fetchAllPages = (url) ->
18+
ajax.raw(url).then(handlePagination)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div id='ember-loading'>
2+
<img src='/images/ajax-loader-medium-444.gif' />
3+
{{#t 'loading'}}Loading{{/t}}
4+
</div>

app/coffeescripts/ember/quizzes/tests/controllers/quizzes.spec.coffee

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ define [
1616
setup: ->
1717
App = startApp()
1818
@qc = new QuizzesController()
19-
@qc.set('model', [
20-
{quiz_type: 'survey', title: 'Test Quiz'},
21-
{quiz_type: 'graded_survey', title: 'Test survey'},
22-
{quiz_type: 'practice_quiz', title: 'Test practice quiz'},
23-
{quiz_type: 'practice_quiz', title: 'Other practice'},
24-
{quiz_type: 'assignment', title: 'Assignment test'}
25-
])
19+
quizzes = Em.A [
20+
{quiz_type: 'survey', title: 'Test Quiz'},
21+
{quiz_type: 'graded_survey', title: 'Test survey'},
22+
{quiz_type: 'practice_quiz', title: 'Test practice quiz'},
23+
{quiz_type: 'practice_quiz', title: 'Other practice'},
24+
{quiz_type: 'assignment', title: 'Assignment test'}
25+
]
26+
@qc.set('model', quizzes)
2627

2728
teardown: ->
2829
Ember.run App, 'destroy'

app/coffeescripts/ember/quizzes/tests/integration/quizzes_index_integration.spec.coffee

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,17 @@ define [
22
'../start_app',
33
'ember',
44
'ic-ajax',
5+
'../shared_ajax_fixtures',
56
'../../shared/environment'
6-
], (startApp, Ember, ajax, environment) ->
7+
], (startApp, Ember, ajax, fixtures, environment) ->
78

89
App = null
910

1011
window.ENV = {
1112
context_asset_string: 'course_1'
1213
}
1314

14-
ajax.defineFixture '/api/v1/courses/1/quizzes',
15-
response: { "quizzes":
16-
[
17-
{
18-
"access_code":null,
19-
"allowed_attempts":1,
20-
"assignment_overrides": [{}],
21-
"assignment_group_id":1,
22-
"cant_go_back":false,
23-
"description":"",
24-
"hide_correct_answers_at":null,
25-
"hide_results":null,
26-
"id":29,
27-
"ip_filter":null,
28-
"due_at":"2013-11-01T06:59:59Z",
29-
"lock_at":"2013-11-01T06:59:59Z",
30-
"unlock_at":"2013-10-27T07:00:00Z",
31-
"one_question_at_a_time":false,
32-
"points_possible":null,
33-
"quiz_type":"practice_quiz",
34-
"scoring_policy":"keep_highest",
35-
"show_correct_answers":true,
36-
"show_correct_answers_at":null,
37-
"shuffle_answers":false,
38-
"time_limit":null,
39-
"title":"Alt practice test",
40-
"html_url":"http://localhost:3000/courses/1/quizzes/29",
41-
"mobile_url":"http://localhost:3000/courses/1/quizzes/29?force_user=1&persist_headless=1",
42-
"question_count":0,
43-
"published":false,
44-
"unpublishable":true,
45-
"locked_for_user":false
46-
},
47-
{
48-
"access_code":null,
49-
"allowed_attempts":1,
50-
"assignment_overrides": [{}],
51-
"assignment_group_id":1,
52-
"cant_go_back":false,
53-
"description":"",
54-
"hide_correct_answers_at":null,
55-
"hide_results":null,
56-
"id":30,
57-
"ip_filter":null,
58-
"due_at":"2013-12-01T06:59:59Z",
59-
"lock_at":"2013-12-01T06:59:59Z",
60-
"unlock_at":"2013-11-27T07:00:00Z",
61-
"one_question_at_a_time":false,
62-
"points_possible":null,
63-
"quiz_type":"practice_quiz",
64-
"scoring_policy":"keep_highest",
65-
"show_correct_answers":true,
66-
"show_correct_answers_at":null,
67-
"shuffle_answers":false,
68-
"time_limit":null,
69-
"title":"Another test",
70-
"html_url":"http://localhost:3000/courses/1/quizzes/29",
71-
"mobile_url":"http://localhost:3000/courses/1/quizzes/29?force_user=1&persist_headless=1",
72-
"question_count":0,
73-
"published":false,
74-
"unpublishable":true,
75-
"locked_for_user":false
76-
}
77-
]
78-
}
79-
jqXHR: {}
80-
testStatus: '200'
15+
fixtures.create()
8116

8217
module 'quizzes index integration',
8318
setup: ->

app/coffeescripts/ember/quizzes/tests/shared/quiz_sorter.spec.coffee

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ define [
77
module 'quiz_sorter',
88
setup: ->
99
@quizzes = Ember.A [
10-
{due_at: null, title: 'null due_at no override' },
11-
{due_at: null, title: 'single_override', all_dates: [{}] },
12-
{due_at: null, title: 'multi_overrides', all_dates: [{},{}] },
13-
{due_at: dateString(3), title: '3 days from now' },
14-
{due_at: dateString(2), title: '2 days from now' },
15-
{due_at: dateString(0), title: 'today' },
16-
{due_at: dateString(-1), title: '1 day ago' }
17-
]
10+
{due_at: null, title: 'null due_at no override' },
11+
{due_at: null, title: 'single_override', all_dates: [{}] },
12+
{due_at: null, title: 'multi_overrides', all_dates: [{},{}] },
13+
{due_at: dateString(3), title: '3 days from now' },
14+
{due_at: dateString(2), title: '2 days from now' },
15+
{due_at: dateString(0), title: 'today' },
16+
{due_at: dateString(-1), title: '1 day ago' }
17+
]
1818

1919
test 'sorts due_at first', ->
2020
sortedQuizzes = quizSorter(@quizzes)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
define [
2+
'ic-ajax',
3+
'ember'
4+
], (ajax, Ember) ->
5+
6+
quiz_index_response = {
7+
"meta": {
8+
"pagination": {},
9+
"primaryCollection": "quizzes"
10+
},
11+
"quizzes":
12+
[
13+
{
14+
"access_code":null,
15+
"allowed_attempts":1,
16+
"assignment_group_id":1,
17+
"cant_go_back":false,
18+
"description":"",
19+
"hide_correct_answers_at":null,
20+
"hide_results":null,
21+
"id":29,
22+
"ip_filter":null,
23+
"due_at":"2013-11-01T06:59:59Z",
24+
"lock_at":"2013-11-01T06:59:59Z",
25+
"unlock_at":"2013-10-27T07:00:00Z",
26+
"one_question_at_a_time":false,
27+
"points_possible":null,
28+
"quiz_type":"practice_quiz",
29+
"scoring_policy":"keep_highest",
30+
"show_correct_answers":true,
31+
"show_correct_answers_at":null,
32+
"shuffle_answers":false,
33+
"time_limit":null,
34+
"title":"Alt practice test",
35+
"html_url":"http://localhost:3000/courses/1/quizzes/29",
36+
"mobile_url":"http://localhost:3000/courses/1/quizzes/29?force_user=1&persist_headless=1",
37+
"question_count":0,
38+
"published":false,
39+
"unpublishable":true,
40+
"locked_for_user":false
41+
},
42+
{
43+
"access_code":null,
44+
"allowed_attempts":1,
45+
"assignment_group_id":1,
46+
"cant_go_back":false,
47+
"description":"",
48+
"hide_correct_answers_at":null,
49+
"hide_results":null,
50+
"id":30,
51+
"ip_filter":null,
52+
"due_at":"2013-12-01T06:59:59Z",
53+
"lock_at":"2013-12-01T06:59:59Z",
54+
"unlock_at":"2013-11-27T07:00:00Z",
55+
"one_question_at_a_time":false,
56+
"points_possible":null,
57+
"quiz_type":"practice_quiz",
58+
"scoring_policy":"keep_highest",
59+
"show_correct_answers":true,
60+
"show_correct_answers_at":null,
61+
"shuffle_answers":false,
62+
"time_limit":null,
63+
"title":"Another test",
64+
"html_url":"http://localhost:3000/courses/1/quizzes/29",
65+
"mobile_url":"http://localhost:3000/courses/1/quizzes/29?force_user=1&persist_headless=1",
66+
"question_count":0,
67+
"published":false,
68+
"unpublishable":true,
69+
"locked_for_user":false
70+
}
71+
]
72+
}
73+
74+
create: ->
75+
ajax.defineFixture '/api/v1/courses/1/quizzes',
76+
response: quiz_index_response,
77+
jqXHR: {}
78+
testStatus: '200'
79+

app/stylesheets/quizzes_ember.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ div#content {
1010
min-width: 763px;
1111
}
1212

13+
#ember-loading {
14+
padding: 10px;
15+
text-align: center;
16+
background-color: #FFF;
17+
border-bottom: 1px solid #C1C7CF;
18+
min-height: 33px;
19+
}
1320
li.quiz .ig-title {
1421
right: 554px;
1522
}

0 commit comments

Comments
 (0)