2016-06-13 15:40:41 +03:00
import destroyApp from '../helpers/destroy-app' ;
2017-05-29 21:50:03 +03:00
import startApp from '../helpers/start-app' ;
import { afterEach , beforeEach , describe , it } from 'mocha' ;
2016-11-14 16:16:51 +03:00
import { authenticateSession } from 'ghost-admin/tests/helpers/ember-simple-auth' ;
2017-05-29 21:50:03 +03:00
import { expect } from 'chai' ;
2016-06-13 15:40:41 +03:00
2016-08-06 10:04:06 +03:00
const originalAgent = window . navigator . userAgent ;
const setUserAgent = function ( userAgent ) {
let userAgentProp = {
get ( ) {
return userAgent ;
} ,
configurable : true
} ;
try {
Object . defineProperty ( window . navigator , 'userAgent' , userAgentProp ) ;
} catch ( e ) {
window . navigator = Object . create ( window . navigator , {
userAgent : userAgentProp
} ) ;
2016-06-13 15:40:41 +03:00
}
} ;
const restoreUserAgent = function ( ) {
2016-08-06 10:04:06 +03:00
setUserAgent ( originalAgent ) ;
2016-06-13 15:40:41 +03:00
} ;
2018-01-05 18:38:23 +03:00
describe ( 'Acceptance: Ghost Desktop' , function ( ) {
2016-06-13 15:40:41 +03:00
let application ;
2018-01-05 18:38:23 +03:00
beforeEach ( function ( ) {
2016-06-13 15:40:41 +03:00
application = startApp ( ) ;
} ) ;
2018-01-05 18:38:23 +03:00
afterEach ( function ( ) {
2016-06-13 15:40:41 +03:00
destroyApp ( application ) ;
} ) ;
describe ( 'update alerts for broken versions' , function ( ) {
2018-01-05 18:38:23 +03:00
beforeEach ( function ( ) {
2016-06-13 15:40:41 +03:00
let role = server . create ( 'role' , { name : 'Administrator' } ) ;
2016-11-14 16:16:51 +03:00
server . create ( 'user' , { roles : [ role ] } ) ;
2016-06-13 15:40:41 +03:00
return authenticateSession ( application ) ;
} ) ;
2018-01-05 18:38:23 +03:00
afterEach ( function ( ) {
2016-06-13 15:40:41 +03:00
restoreUserAgent ( ) ;
} ) ;
2018-01-05 18:38:23 +03:00
it ( 'displays alert for broken version' , async function ( ) {
2016-08-06 10:04:06 +03:00
setUserAgent ( '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' ) ;
2016-06-13 15:40:41 +03:00
2017-04-24 15:29:48 +03:00
await visit ( '/' ) ;
2016-06-13 15:40:41 +03:00
2017-04-24 15:29:48 +03:00
// has an alert with matching text
2017-07-20 17:00:41 +03:00
expect ( find ( '.gh-alert-blue' ) . length , 'number of warning alerts' ) . to . equal ( 1 ) ;
expect ( find ( '.gh-alert-blue' ) . text ( ) . trim ( ) , 'alert text' ) . to . match ( /Your version of Ghost Desktop needs to be manually updated/ ) ;
2016-06-13 15:40:41 +03:00
} ) ;
2017-04-24 15:29:48 +03:00
it ( 'doesn\'t display alert for working version' , async function ( ) {
2016-08-06 10:04:06 +03:00
setUserAgent ( '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' ) ;
2016-06-13 15:40:41 +03:00
2017-04-24 15:29:48 +03:00
await visit ( '/' ) ;
2016-06-13 15:40:41 +03:00
2017-04-24 15:29:48 +03:00
// no alerts
expect ( find ( '.gh-alert' ) . length , 'number of alerts' ) . to . equal ( 0 ) ;
2016-06-13 15:40:41 +03:00
} ) ;
} ) ;
} ) ;