From e8168f02c5492f303765ab397047470c997aeabe Mon Sep 17 00:00:00 2001 From: Jason Madsen Date: Thu, 5 Jun 2014 16:30:43 -0600 Subject: [PATCH] update page titles in ember quizzes update the document.title to be consistent with the page that the user is viewing. update existing moderate page title to be consistent closes CNVS-12974 test plan: - enable :quiz_stats feature - enable :quiz_moderate feature - visit quiz index - title should display 'Quizzes' - select a quiz - title should display ': Overview' - select the moderate tab - title should display ': Moderate' - select the statistics tab - title should display ': Statistics' Change-Id: I36d94014e2225d78d59d35c77b16bb82af48d644 Reviewed-on: https://gerrit.instructure.com/36016 Reviewed-by: Derek DeVries Tested-by: Jenkins QA-Review: Clare Strong Product-Review: Jason Madsen --- .../quizzes/routes/quiz_moderate_route.coffee | 9 +++++- .../ember/quizzes/routes/quiz_route.coffee | 4 ++- .../quizzes/routes/quiz_show_route.coffee | 11 +++++-- .../routes/quiz_statistics_route.coffee | 13 ++++++++- .../ember/quizzes/routes/quizzes_route.coffee | 10 +++++-- .../ember/quizzes/shared/title_builder.coffee | 15 ++++++++++ .../integration/quiz_moderate.spec.coffee | 12 ++++++-- .../quiz_show_integration.spec.coffee | 8 +++-- .../quiz_statistics_integration.spec.coffee | 3 +- .../quizzes_index_integration.spec.coffee | 7 ++++- .../tests/shared/title_builder.spec.coffee | 29 +++++++++++++++++++ .../ember/quizzes/tests/test_title.coffee | 8 +++++ app/views/quizzes/quizzes/moderate.html.erb | 2 +- 13 files changed, 116 insertions(+), 15 deletions(-) create mode 100644 app/coffeescripts/ember/quizzes/shared/title_builder.coffee create mode 100644 app/coffeescripts/ember/quizzes/tests/shared/title_builder.spec.coffee create mode 100644 app/coffeescripts/ember/quizzes/tests/test_title.coffee diff --git a/app/coffeescripts/ember/quizzes/routes/quiz_moderate_route.coffee b/app/coffeescripts/ember/quizzes/routes/quiz_moderate_route.coffee index 10afa4c2fb6..04c7ddcdc84 100644 --- a/app/coffeescripts/ember/quizzes/routes/quiz_moderate_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quiz_moderate_route.coffee @@ -2,7 +2,9 @@ define [ 'ember' '../mixins/redirect' '../shared/environment' -], (Em, Redirect, env) -> + 'i18n!quiz_moderate_route', + '../shared/title_builder' +], (Em, Redirect, env, I18n, titleBuilder) -> ModerateRoute = Em.Route.extend Redirect, @@ -12,6 +14,11 @@ define [ model: -> @combinedUsersSubmissionsPromise() + afterModel: -> + title = @modelFor('quiz').get('title') + desc = I18n.t('moderate', "Moderate") + titleBuilder([title, desc]) + combinedUsersSubmissionsPromise: -> quiz = @modelFor('quiz') _this = this diff --git a/app/coffeescripts/ember/quizzes/routes/quiz_route.coffee b/app/coffeescripts/ember/quizzes/routes/quiz_route.coffee index 7e5108ebea7..00f37d8c6b0 100644 --- a/app/coffeescripts/ember/quizzes/routes/quiz_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quiz_route.coffee @@ -3,7 +3,8 @@ define [ '../mixins/redirect' '../shared/environment' 'i18n!quiz_route' -], (Ember, Redirect, env, I18n) -> + '../shared/title_builder' +], (Ember, Redirect, env, I18n, titleBuilder) -> QuizRoute = Ember.Route.extend Redirect, @@ -11,6 +12,7 @@ define [ afterModel: (quiz, transition) -> # set the quiz in the env so that we can use it for nested routes env.set("quizId", quiz.id) + titleBuilder([quiz.get('title')]) if quiz.get("deleted") quiz.unloadRecord() diff --git a/app/coffeescripts/ember/quizzes/routes/quiz_show_route.coffee b/app/coffeescripts/ember/quizzes/routes/quiz_show_route.coffee index ae4b34bf343..6cdf5441f24 100644 --- a/app/coffeescripts/ember/quizzes/routes/quiz_show_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quiz_show_route.coffee @@ -1,7 +1,14 @@ define [ - 'ember' -], (Em) -> + 'ember', + 'i18n!quiz_overview_route', + '../shared/title_builder' +], (Em, I18n, titleBuilder) -> Em.Route.extend model: -> @modelFor 'quiz' + + afterModel: (quiz, transition) -> + title = quiz.get('title') + desc = I18n.t('overview', 'Overview') + titleBuilder([title, desc]) diff --git a/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee b/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee index 4a33d5e5256..7e8b8a542f0 100644 --- a/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee @@ -1,4 +1,10 @@ -define [ 'ember', '../mixins/redirect' ], (Ember, Redirect) -> +define [ + 'ember', + '../mixins/redirect', + 'i18n!quiz_statistics_route' + '../shared/title_builder' +], (Ember, Redirect, I18n, titleBuilder) -> + Ember.Route.extend Redirect, beforeModel: (transition) -> @validateRoute('canManage', 'quiz.show') @@ -13,6 +19,11 @@ define [ 'ember', '../mixins/redirect' ], (Ember, Redirect) -> quiz.get('quizReports').then -> latestStatistics + afterModel: () -> + title = @modelFor('quiz').get('title') + desc = I18n.t('quiz_statistics', "Statistics") + titleBuilder([title, desc]) + actions: showDiscriminationIndexHelp: -> @render 'quiz/statistics/questions/multiple_choice/discrimination_index_help', diff --git a/app/coffeescripts/ember/quizzes/routes/quizzes_route.coffee b/app/coffeescripts/ember/quizzes/routes/quizzes_route.coffee index 23e02904383..2a2e786cfc9 100644 --- a/app/coffeescripts/ember/quizzes/routes/quizzes_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quizzes_route.coffee @@ -1,7 +1,9 @@ define [ 'ember' - '../shared/environment' -], (Ember, env) -> + '../shared/environment', + 'i18n!quizzes_route', + '../shared/title_builder' +], (Ember, env, I18n, titleBuilder) -> QuizzesRoute = Ember.Route.extend @@ -17,3 +19,7 @@ define [ perms.create = @store.metadataFor('quiz').permissions.quizzes.create env.set 'env.PERMISSIONS', perms quizzes + + afterModel: -> + title = I18n.t('quizzes_route_title', 'Quizzes') + titleBuilder([title]) diff --git a/app/coffeescripts/ember/quizzes/shared/title_builder.coffee b/app/coffeescripts/ember/quizzes/shared/title_builder.coffee new file mode 100644 index 00000000000..32e90472227 --- /dev/null +++ b/app/coffeescripts/ember/quizzes/shared/title_builder.coffee @@ -0,0 +1,15 @@ +define [ + 'ember' +], (Ember) -> + + updateTitle = (title) -> + Ember.$(document).attr('title', title) + + (tokens, separator = ': ') -> + if tokens instanceof Array + tokens = tokens || [] + title = tokens.join(separator) + else + title = tokens || '' + updateTitle(title) + title diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee index 9c0ea9f4f0c..a0ce9198e95 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee @@ -4,8 +4,9 @@ define [ '../shared_ajax_fixtures' '../environment_setup' '../test_redirection' + '../test_title' ] -, (Ember, startApp, fixtures, env, testRedirection) -> +, (Ember, startApp, fixtures, env, testRedirection, testTitle) -> module "Quiz Moderate: Integration", @@ -16,10 +17,15 @@ define [ teardown: -> Ember.run App, 'destroy' - # something about quizSubmissions and users association isn't resolving - # and cause instability in this + # something about quizSubmissions and users association is causing promises + # to not resolve and cause issues with getting `then` to resolve correctly # TODO: determine why + # testRedirection # path: '/1/moderate' # defaultRoute: 'quiz.moderate' # redirectRoute: 'quiz.show' + + # testTitle + # path: '/', + # title: 'Alt practices test: Moderate' diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quiz_show_integration.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quiz_show_integration.spec.coffee index 7f08af53e33..44e2b860f6e 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quiz_show_integration.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quiz_show_integration.spec.coffee @@ -5,8 +5,9 @@ define [ '../environment_setup' 'ic-ajax' 'jquery' + '../test_title' 'jqueryui/dialog' -], (Ember, startApp, fixtures, env, ajax, $) -> +], (Ember, startApp, fixtures, env, ajax, $, testTitle) -> App = null QUIZ = fixtures.QUIZZES[0] @@ -26,6 +27,10 @@ define [ test desc, -> visit('/1').then callback + testTitle + path: '/1', + title: 'Alt practice test: Overview' + testShowPage 'shows attributes', -> html = find('#quiz-show').html() @@ -147,4 +152,3 @@ define [ testShowPage 'doesnt show tabs', -> ok !find('#quiz-show-tabs').length, "should not have tabs" - diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee index 8629ef62202..0604516f528 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee @@ -4,7 +4,8 @@ define [ '../environment_setup' '../shared_ajax_fixtures' '../test_redirection' -], (Ember, startApp, env, fixtures, testRedirection) -> + '../test_title' +], (Ember, startApp, env, fixtures, testRedirection, testTitle) -> App = null {$} = Ember diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quizzes_index_integration.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quizzes_index_integration.spec.coffee index b91d0e8f213..54d8754135f 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quizzes_index_integration.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quizzes_index_integration.spec.coffee @@ -4,9 +4,10 @@ define [ 'ic-ajax', '../shared_ajax_fixtures', '../../shared/environment' + '../test_title', '../environment_setup', '../../../../behaviors/elementToggler' -], (startApp, Ember, ajax, fixtures, env) -> +], (startApp, Ember, ajax, fixtures, env, testTitle) -> App = null @@ -18,6 +19,10 @@ define [ teardown: -> Ember.run App, 'destroy' + testTitle + path: '/', + title: 'Quizzes' + test 'Quizzes pages load appropriately', -> visit('/').then -> equal(find('.quiz').length, 2, 'Loads data into controller appropriately') diff --git a/app/coffeescripts/ember/quizzes/tests/shared/title_builder.spec.coffee b/app/coffeescripts/ember/quizzes/tests/shared/title_builder.spec.coffee new file mode 100644 index 00000000000..dffee0097ad --- /dev/null +++ b/app/coffeescripts/ember/quizzes/tests/shared/title_builder.spec.coffee @@ -0,0 +1,29 @@ +define [ + '../../shared/title_builder' +], (titleBuilder) -> + + module 'title_builder - Unit - ' + + test 'uses default separator', -> + result = titleBuilder(['foo', 'bar']) + equal result, 'foo: bar' + + test 'uses separator from arguments', -> + result = titleBuilder(['foo', 'bar'], ' - ') + equal result, 'foo - bar' + + test 'concats tokens in order given', -> + result = titleBuilder(['foo', 'bar', 'baz'], ' ') + equal result, 'foo bar baz' + + test 'handles empty tokens', -> + result = titleBuilder([], '!') + equal result, '' + + test 'handles no arguments', -> + result = titleBuilder() + equal result, '' + + test 'handles first argument as a string', -> + result = titleBuilder('baz') + equal result, 'baz' diff --git a/app/coffeescripts/ember/quizzes/tests/test_title.coffee b/app/coffeescripts/ember/quizzes/tests/test_title.coffee new file mode 100644 index 00000000000..7ff42f4bc9a --- /dev/null +++ b/app/coffeescripts/ember/quizzes/tests/test_title.coffee @@ -0,0 +1,8 @@ +define ['ember'], (Ember) -> + + # {path: '/1/moderate, title: 'Expected Title'} + (options) -> + test "updates document.title for #{options.path} correctly", -> + visit(options.path) + andThen -> + equal document.title, options.title diff --git a/app/views/quizzes/quizzes/moderate.html.erb b/app/views/quizzes/quizzes/moderate.html.erb index ba5dc3cc3e5..4903450fd2a 100644 --- a/app/views/quizzes/quizzes/moderate.html.erb +++ b/app/views/quizzes/quizzes/moderate.html.erb @@ -2,7 +2,7 @@ add_crumb @quiz.title, context_url(@context, :context_quiz_url, @quiz) add_crumb t(:page_title, 'Moderate Quiz') %> -<% content_for :page_title do %><%= t(:page_title, "Moderate Quiz") %><% end %> +<% content_for :page_title do %><%= t(:moderate_page_title, "%{title}: Moderate", :title => @quiz.title) %><% end %>

<%= t(:page_title, "Moderate Quiz") %>