mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fix and add tests for Ghost Desktop manual update notification
closes #51 - move the check into the `afterModel` hook so that it's always performed on app load (previously it would only be displayed after going through the sign-in process) - change the alert type to `warn` so that it matches our existing types (success, warn, error) - don't rely on the `.htmlSafe()` prototype extension - add basic tests for the upgrade alert display
This commit is contained in:
parent
289742a7b5
commit
b521e4dba4
2 changed files with 84 additions and 3 deletions
|
@ -7,6 +7,7 @@ import windowProxy from 'ghost-admin/utils/window-proxy';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Route,
|
Route,
|
||||||
|
String: {htmlSafe},
|
||||||
inject: {service},
|
inject: {service},
|
||||||
run
|
run
|
||||||
} = Ember;
|
} = Ember;
|
||||||
|
@ -34,6 +35,7 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
if (this.get('session.isAuthenticated')) {
|
if (this.get('session.isAuthenticated')) {
|
||||||
this.set('appLoadTransition', transition);
|
this.set('appLoadTransition', transition);
|
||||||
transition.send('loadServerNotifications');
|
transition.send('loadServerNotifications');
|
||||||
|
transition.send('checkForOutdatedDesktopApp');
|
||||||
|
|
||||||
// return the feature loading promise so that we block until settings
|
// return the feature loading promise so that we block until settings
|
||||||
// are loaded in order for synchronous access everywhere
|
// are loaded in order for synchronous access everywhere
|
||||||
|
@ -96,7 +98,6 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
signedIn() {
|
signedIn() {
|
||||||
this.get('notifications').clearAll();
|
this.get('notifications').clearAll();
|
||||||
this.send('loadServerNotifications', true);
|
this.send('loadServerNotifications', true);
|
||||||
this.send('checkForOutdatedDesktopApp');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
invalidateSession() {
|
invalidateSession() {
|
||||||
|
@ -135,8 +136,8 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, {
|
||||||
let msg = `Your version of Ghost Desktop needs to be manually updated. Please ${link} to get started.`;
|
let msg = `Your version of Ghost Desktop needs to be manually updated. Please ${link} to get started.`;
|
||||||
|
|
||||||
if (updateCheck.test(ua)) {
|
if (updateCheck.test(ua)) {
|
||||||
this.get('notifications').showAlert(msg.htmlSafe(), {
|
this.get('notifications').showAlert(htmlSafe(msg), {
|
||||||
type: 'upgrade',
|
type: 'warn',
|
||||||
key: 'desktop.manual.upgrade'
|
key: 'desktop.manual.upgrade'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
80
ghost/admin/tests/acceptance/ghost-desktop-test.js
Normal file
80
ghost/admin/tests/acceptance/ghost-desktop-test.js
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/* jshint expr:true */
|
||||||
|
import {
|
||||||
|
describe,
|
||||||
|
it,
|
||||||
|
beforeEach,
|
||||||
|
afterEach
|
||||||
|
} from 'mocha';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import startApp from '../helpers/start-app';
|
||||||
|
import destroyApp from '../helpers/destroy-app';
|
||||||
|
import { authenticateSession } from 'ghost-admin/tests/helpers/ember-simple-auth';
|
||||||
|
|
||||||
|
const originalUserAgent = window.navigator.userAgent;
|
||||||
|
|
||||||
|
const _setUserAgent = function (userAgent) {
|
||||||
|
let userAgentProp = {get() { return userAgent; }, configurable: true};
|
||||||
|
Object.defineProperty(window.navigator, 'userAgent', userAgentProp);
|
||||||
|
};
|
||||||
|
|
||||||
|
const stubUserAgent = function (userAgent) {
|
||||||
|
if (window.navigator.userAgent !== userAgent) {
|
||||||
|
_setUserAgent(userAgent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreUserAgent = function () {
|
||||||
|
if (window.navigator.userAgent !== originalUserAgent) {
|
||||||
|
_setUserAgent(originalUserAgent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Acceptance: Ghost Desktop', function() {
|
||||||
|
let application;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
application = startApp();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
destroyApp(application);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('update alerts for broken versions', function () {
|
||||||
|
beforeEach(function() {
|
||||||
|
let role = server.create('role', {name: 'Administrator'});
|
||||||
|
let user = server.create('user', {roles: [role]});
|
||||||
|
|
||||||
|
server.loadFixtures();
|
||||||
|
|
||||||
|
return authenticateSession(application);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
restoreUserAgent();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays alert for broken version', function() {
|
||||||
|
stubUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) ghost-desktop/0.4.0 Chrome/51.0.2704.84 Electron/1.2.2 Safari/537.36');
|
||||||
|
|
||||||
|
visit('/');
|
||||||
|
|
||||||
|
andThen(function () {
|
||||||
|
// has an alert with matching text
|
||||||
|
expect(find('.gh-alert-yellow').length, 'number of warning alerts').to.equal(1);
|
||||||
|
expect(find('.gh-alert-yellow').text().trim(), 'alert text').to.match(/Your version of Ghost Desktop needs to be manually updated/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('doesn\'t display alert for working version', function () {
|
||||||
|
stubUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) ghost-desktop/0.5.1 Chrome/51.0.2704.84 Electron/1.2.2 Safari/537.36');
|
||||||
|
|
||||||
|
visit('/');
|
||||||
|
|
||||||
|
andThen(function () {
|
||||||
|
// no alerts
|
||||||
|
expect(find('.gh-alert').length, 'number of alerts').to.equal(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue