Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Reflect page title in document title #679

Merged
merged 30 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1fbd821
docs: clarify setTitle() with function-level doc
apetro Jan 25, 2018
0a6caac
refactor: clarify setTitle() implementation
apetro Jan 25, 2018
305e17b
fix: simplify setTitle() to handle app with same name as portal case
apetro Jan 25, 2018
362399e
refactor: handle true branch first
apetro Jan 25, 2018
57c16aa
docs: clarify inline comment
apetro Jan 25, 2018
4ed9820
fix: handle edge case where theme lacks title
apetro Jan 25, 2018
f7aa6d1
fix: handle case where there isn't an active theme with a title
apetro Jan 25, 2018
186864b
docs: copy edit inline comment
apetro Jan 25, 2018
f3b8182
refactor: build windowTitle from pieces
apetro Jan 25, 2018
e71dcb9
feat: support per-page window titles
apetro Jan 25, 2018
83e8bde
test(main-service): unit test setTitle
apetro Jan 25, 2018
e2b15a9
fix(set-title): handle null or empty app name edge case
apetro Jan 26, 2018
ac6eb3a
refactor: order tests to match examples
apetro Jan 26, 2018
3c078f3
test: describe tests conceptually rather than literally
apetro Jan 26, 2018
6f3979a
test: match test cases with documented examples
apetro Jan 26, 2018
61b4622
test: cover more setTitle edge cases
apetro Jan 26, 2018
9794ad6
Merge branch 'master' into page-title-takes-string
apetro Jan 29, 2018
8ff8529
refactor: split title computation from title setting
apetro Jan 30, 2018
e37ba9d
feat: app-header directive side effect sets document title
apetro Jan 30, 2018
dd505df
Merge branch 'master' into page-title-takes-string
apetro Jan 30, 2018
9d07002
test: test that PortalMainController sets title to reflect theme
apetro Jan 30, 2018
fe6e427
test: note problematic specificity of document title setting test
apetro Jan 30, 2018
19fcbb6
docs: JSDocs PortalMainController.updateTitle(pageTitle)
apetro Jan 30, 2018
03698b2
test: test AppHeaderOptionsController updateTitle( pageTitle )
apetro Jan 30, 2018
4af8ddb
docs: note frame-page directive document title setting side-effect
apetro Jan 30, 2018
bffb3a3
docs(changelog): note window title changes
apetro Jan 31, 2018
8580be1
refactor: rename updateTitle to updateWindowTitle in Controller layer
apetro Jan 31, 2018
ae441b4
docs: note window title update side-effect in appHeader source comment
apetro Jan 31, 2018
1ce21d2
Merge branch 'master' into page-title-takes-string
apetro Feb 1, 2018
9590884
docs: use idiomatic JSDoc syntax for optional pageTitle
apetro Feb 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions components/portal/main/main_service_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at the following location:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict';
/* eslint-env node */
/* global inject */
define(['angular-mocks', 'portal'], function() {
describe('mainService', function() {
var service;

var loginSilentUrl;
var httpBackend;

var $document;
var $scope;
var NAMES;

beforeEach(function() {
module('portal');
});

beforeEach(inject(function(
_mainService_, _$httpBackend_,
_$document_, _$rootScope_,
SERVICE_LOC, MESSAGES, APP_FLAGS, _NAMES_
) {
$scope = _$rootScope_.$new();
service = _mainService_;
$document = _$document_;
httpBackend = _$httpBackend_;
NAMES = _NAMES_;
loginSilentUrl = APP_FLAGS.loginOnLoad;

if (loginSilentUrl) {
httpBackend.whenGET(loginSilentUrl)
.respond({'status': 'success', 'username': 'admin'});
}

httpBackend.whenGET(SERVICE_LOC.sessionInfo).respond();
}));

it('should set title to MyUW'
+ 'when MyUW is both portal name and app name '
+ 'and there is no page name', function() {
// setup
NAMES.title = 'MyUW';
$scope.portal.theme.title = 'MyUW';

// test
service.setTitle();

expect($document[0].title).toEqual('MyUW');

httpBackend.flush();
});

it('should set title to STAR | MyUW '
+ 'when STAR is app name and MyUW is portal name '
+ 'and there is no page name', function() {
// setup
NAMES.title = 'STAR';
$scope.portal.theme.title = 'MyUW';

// test
service.setTitle();

expect($document[0].title).toEqual('STAR | MyUW');

httpBackend.flush();
});

it('should set title to Timesheets | STAR | MyUW '
+ 'when STAR is app name and MyUW is portal name '
+ 'and Timesheets is page name', function() {
// setup
NAMES.title = 'STAR';
$scope.portal.theme.title = 'MyUW';

// test
service.setTitle('Timesheets');

expect($document[0].title).toEqual('Timesheets | STAR | MyUW');

httpBackend.flush();
});

it('should set title to Notifications | MyUW '
+ 'when MyUW is app name and MyUW is portal name '
+ 'and Notifications is page name', function() {
// setup
NAMES.title = 'MyUW';
$scope.portal.theme.title = 'MyUW';

// test
service.setTitle('Notifications');

expect($document[0].title).toEqual('Notifications | MyUW');

httpBackend.flush();
});
});
});
80 changes: 69 additions & 11 deletions components/portal/main/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,78 @@ define(['angular'], function(angular) {
};

/**
* set the frame title using theme
* set the window title
*
* results in title
* page-title | app-title | portal-title (in an application), or
* page-title | portal-title (if the app has same name as the portal), or
* app-title | portal-title (if page name unknown or redundant)
* portal-title (if page name unknown or redundant and app name redundant)
*
* Examples:
* "Timesheets | STAR Time Entry | MyUW" ,
* for the Timesheets page in an app named "STAR Time Entry" in
* a portal named "MyUW", or
*
* "Notifications | MyUW",
* for the notifications page in an app named "MyUW" in
* a portal named "MyUW".
*
* "STAR Time Entry | MyUW"
* in an app named "STAR Time Entry" in a portal named "MyUW"
* when the page name is unspecified.
*
* "MyUW"
* in an app named "MyUW" in a portal named "MyUW"
* when the page name is unspecified.
*/
function setTitle() {
var frameTitle = '';
if ($rootScope.portal && $rootScope.portal.theme) {
frameTitle = $rootScope.portal.theme.title;
if (frameTitle !== NAMES.title && !APP_FLAGS.isWeb) {
frameTitle = ' | ' + frameTitle;
} else {
// since frame title equals the title in NAMES lets not duplicate it
frameTitle = '';
function setTitle(pageTitle) {
var windowTitle = ''; // we finally set the window title to this.

// first, gather pieces of the desired window title

var portalTitle = ''; // the name of the portal if we can determine it
var appTitle = ''; // the name of the app

if ($rootScope.portal && $rootScope.portal.theme &&
$rootScope.portal.theme.title) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to do something with the theme title, we should pass it in via parameters. $rootScope or even $scope shouldn't bleed out to services

// there's an active theme with a title.
// consider that title the name of the portal
portalTitle = $rootScope.portal.theme.title;
}

appTitle = NAMES.title;

// assemble the window title from the gathered pieces,
// starting from the end of the window title and working back to the
// beginning.

// if the portal has a name, end the window title with that
// (if the portal lacks a name, portalTitle is still empty string)
windowTitle = portalTitle;

// if the app name differs from the portal, prepend it.
// if it's the same name, omit it to avoid silly redundancy like
// "MyUW | MyUW"
if (appTitle !== portalTitle) {
// if the windowTitle already has content, first add a separator
if (windowTitle !== '') {
windowTitle = ' | ' + windowTitle;
}
windowTitle = appTitle + windowTitle;
}

// if there's a page name not redundant with the app name, prepend it.
if (pageTitle && pageTitle !== '' && pageTitle !== appTitle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (pageTitle && pageTitle !== appTitle) { Should be enough, check the If() tab here: https://dorey.github.io/JavaScript-Equality-Table/

// if the windowTitle already has content, first add a separator
if (windowTitle !== '') {
windowTitle = ' | ' + windowTitle;
}
windowTitle = pageTitle + windowTitle;
}
$document[0].title = NAMES.title + frameTitle;

// finally, use the built up windowTitle
$document[0].title = windowTitle;
}

return {
Expand Down