2023-11-07 16:29:17 +00:00
( function ( ) {
2024-03-24 20:53:43 +00:00
const VALID _UA = 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Mobile Safari/537.36' ;
const VALID _SUPPORTED _NAMESPACES = [ 0 ] ;
const spinner = ( ) => ( {
$el : $ ( '<span>' )
} ) ;
const Deferred = $ . Deferred ;
const windowChrome = { chrome : true } ;
const windowNotChrome = { } ;
const downloadAction = require ( '../../../resources/skins.minerva.scripts/downloadPageAction.js' ) ;
const onClick = downloadAction . test . onClick ;
const isAvailable = downloadAction . test . isAvailable ;
2017-11-15 22:37:37 +00:00
2023-11-07 16:29:17 +00:00
class Page {
constructor ( options ) {
this . isMissing = options . isMissing ;
2024-06-03 11:59:48 +00:00
// eslint-disable-next-line no-underscore-dangle
2023-11-07 16:29:17 +00:00
this . _isMainPage = ! ! options . isMainPage ;
}
2024-01-24 22:02:12 +00:00
2023-11-07 16:29:17 +00:00
isMainPage ( ) {
2024-06-03 11:59:48 +00:00
// eslint-disable-next-line no-underscore-dangle
2023-11-07 16:29:17 +00:00
return this . _isMainPage ;
}
2024-01-24 22:02:12 +00:00
2023-11-07 16:29:17 +00:00
getNamespaceId ( ) {
return 0 ;
}
}
2017-11-15 22:37:37 +00:00
QUnit . module ( 'Minerva DownloadIcon' , {
2018-09-11 13:13:41 +00:00
beforeEach : function ( ) {
2023-11-07 16:29:17 +00:00
this . getOnClickHandler = function ( onLoadAllImages ) {
2024-03-24 20:53:43 +00:00
const portletLink = document . createElement ( 'li' ) ;
2021-09-28 17:00:45 +00:00
return function ( ) {
2023-11-07 16:29:17 +00:00
onClick ( portletLink , spinner ( ) , onLoadAllImages ) ;
2021-09-28 17:00:45 +00:00
} ;
2018-11-08 00:06:54 +00:00
} ;
2017-11-15 22:37:37 +00:00
}
} ) ;
2018-11-08 00:06:54 +00:00
QUnit . test ( '#getOnClickHandler (print after image download)' , function ( assert ) {
2023-11-07 16:29:17 +00:00
const
2017-11-15 22:37:37 +00:00
d = Deferred ( ) ,
2023-11-07 16:29:17 +00:00
handler = this . getOnClickHandler ( ( ) => d . resolve ( ) ) ,
2017-11-15 22:37:37 +00:00
spy = this . sandbox . stub ( window , 'print' ) ;
2018-11-08 00:06:54 +00:00
handler ( ) ;
2024-06-03 12:06:43 +00:00
d . then ( ( ) => {
2018-04-24 22:00:10 +00:00
assert . strictEqual ( spy . callCount , 1 , 'Print occurred.' ) ;
2017-11-15 22:37:37 +00:00
} ) ;
return d ;
} ) ;
2018-11-08 00:06:54 +00:00
QUnit . test ( '#getOnClickHandler (print via timeout)' , function ( assert ) {
2023-11-07 16:29:17 +00:00
const
2017-11-15 22:37:37 +00:00
d = Deferred ( ) ,
2023-11-07 16:29:17 +00:00
handler = this . getOnClickHandler ( ( ) => d . resolve ( ) ) ,
2017-11-15 22:37:37 +00:00
spy = this . sandbox . stub ( window , 'print' ) ;
2024-06-03 12:06:43 +00:00
window . setTimeout ( ( ) => {
2017-11-15 22:37:37 +00:00
d . resolve ( ) ;
} , 3400 ) ;
2018-11-08 00:06:54 +00:00
handler ( ) ;
2024-06-03 12:06:43 +00:00
d . then ( ( ) => {
2018-04-24 22:00:10 +00:00
assert . strictEqual ( spy . callCount , 1 ,
2019-01-08 20:35:28 +00:00
'Print was called once despite loadImages resolving after MAX_PRINT_TIMEOUT' ) ;
2017-11-15 22:37:37 +00:00
} ) ;
return d ;
} ) ;
2018-11-08 00:06:54 +00:00
QUnit . test ( '#getOnClickHandler (multiple clicks)' , function ( assert ) {
2023-11-07 16:29:17 +00:00
const d = Deferred ( ) ,
handler = this . getOnClickHandler ( ( ) => d . resolve ( ) ) ,
2017-11-15 22:37:37 +00:00
spy = this . sandbox . stub ( window , 'print' ) ;
2024-06-03 12:06:43 +00:00
window . setTimeout ( ( ) => {
2017-11-15 22:37:37 +00:00
d . resolve ( ) ;
} , 3400 ) ;
2018-11-08 00:06:54 +00:00
handler ( ) ;
handler ( ) ;
2024-06-03 12:06:43 +00:00
d . then ( ( ) => {
2018-04-24 22:00:10 +00:00
assert . strictEqual ( spy . callCount , 1 ,
2017-11-15 22:37:37 +00:00
'Print was called once despite multiple clicks' ) ;
} ) ;
return d ;
} ) ;
2018-01-12 17:45:39 +00:00
2018-11-08 00:06:54 +00:00
QUnit . module ( 'isAvailable()' , {
2018-09-11 13:13:41 +00:00
beforeEach : function ( ) {
2024-03-24 20:53:43 +00:00
const page = new Page ( {
2018-11-08 00:06:54 +00:00
id : 0 ,
title : 'Test' ,
2019-07-31 23:17:20 +00:00
isMissing : false ,
2018-11-08 00:06:54 +00:00
isMainPage : false
} ) ;
this . page = page ;
this . isAvailable = function ( ua ) {
return isAvailable ( windowChrome , page , ua ,
VALID _SUPPORTED _NAMESPACES ) ;
} ;
this . notChromeIsAvailable = function ( ua ) {
return isAvailable ( windowNotChrome , page , ua ,
VALID _SUPPORTED _NAMESPACES ) ;
} ;
2018-01-12 17:45:39 +00:00
}
} ) ;
QUnit . test ( 'isAvailable() handles properly correct namespace' , function ( assert ) {
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( VALID _UA ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
QUnit . test ( 'isAvailable() handles properly not supported namespace' , function ( assert ) {
2021-11-09 14:40:14 +00:00
assert . false ( isAvailable ( windowChrome , this . page , VALID _UA , [ 9999 ] ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
2024-06-03 12:06:43 +00:00
QUnit . test ( 'isAvailable() handles missing pages' , ( assert ) => {
2024-03-24 20:53:43 +00:00
const page = new Page ( {
2019-07-31 23:17:20 +00:00
id : 0 ,
title : 'Missing' ,
isMissing : true
} ) ;
2021-11-09 14:40:14 +00:00
assert . false ( isAvailable ( windowChrome , page , VALID _UA , VALID _SUPPORTED _NAMESPACES ) ) ;
2019-07-31 23:17:20 +00:00
} ) ;
2024-06-03 12:06:43 +00:00
QUnit . test ( 'isAvailable() handles properly main page' , ( assert ) => {
2024-03-24 20:53:43 +00:00
const page = new Page ( {
2018-01-12 17:45:39 +00:00
id : 0 ,
title : 'Test' ,
2019-07-31 23:17:20 +00:00
isMissing : false ,
2018-01-12 17:45:39 +00:00
isMainPage : true
} ) ;
2021-11-09 14:40:14 +00:00
assert . false ( isAvailable ( windowChrome , page , VALID _UA , VALID _SUPPORTED _NAMESPACES ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
QUnit . test ( 'isAvailable() returns false for iOS' , function ( assert ) {
2023-11-07 16:29:17 +00:00
assert . false ( this . isAvailable ( 'ipad' ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
2018-02-01 18:59:18 +00:00
QUnit . test ( 'isAvailable() uses window.chrome to filter certain chrome-like browsers' , function ( assert ) {
// Dolphin
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( ' Mozilla/5.0 (Linux; Android 7.0; SM-G950U1 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36' ) ) ;
2018-02-01 18:59:18 +00:00
// Opera
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U1 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.116 Mobile Safari/537.36 OPR/44.1.2246.123029' ) ) ;
2018-02-01 18:59:18 +00:00
// Maxthon
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U1 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36 MxBrowser/4.5.10.1300' ) ) ;
2018-02-01 18:59:18 +00:00
} ) ;
2018-09-11 13:13:41 +00:00
QUnit . test ( 'isAvailable() handles properly browsers' , function ( assert ) {
2018-02-01 18:59:18 +00:00
// IPhone 6 Safari
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_0_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A405 Safari/601.1' ) ) ;
2018-02-01 18:59:18 +00:00
// Nokia Lumia 930 Windows Phone 8.1
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537' ) ) ;
2018-02-01 18:59:18 +00:00
// Firefox @ Ubuntu
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0' ) ) ;
2018-02-01 18:59:18 +00:00
} ) ;
QUnit . test ( 'isAvailable() handles properly non-chrome browsers' , function ( assert ) {
2018-01-12 17:45:39 +00:00
// IPhone 6 Safari
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_0_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A405 Safari/601.1' ) ) ;
2018-01-12 17:45:39 +00:00
// Nokia Lumia 930 Windows Phone 8.1
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537' ) ) ;
2018-01-12 17:45:39 +00:00
// Firefox @ Ubuntu
2021-11-09 14:40:14 +00:00
assert . false ( this . notChromeIsAvailable ( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0' ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
QUnit . test ( 'isAvailable() handles properly old devices' , function ( assert ) {
// Samsung Galaxy S5, Android 4.4, Chrome 28
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-G900F Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Samsung Galaxyu S1, Android 4.2.2 Cyanogenmod + built in Samsung Browser
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (Linux; U; Android 4.2.2; en-ca; GT-I9000 Build/JDQ39E) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 CyanogenMod/10.1.0/galaxysmtd' ) ) ;
2018-01-12 17:45:39 +00:00
// Samsung Galaxy S3
2021-11-09 14:40:14 +00:00
assert . false ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 4.3; GT-I9300 Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
QUnit . test ( 'isAvailable() handles properly supported browsers' , function ( assert ) {
// Samsung Galaxy S7, Android 6, Chrome 44
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 6.0.1; SAMSUNG SM-G930F Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/4.0 Chrome/44.0.2403.133 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Samsung Galaxy A5, Android 7, Samsung Browser 5.2
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-A510F Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/5.2 Chrome/51.0.2704.106 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Galaxy J2, Android 5, Chrome 65
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 5.1.1; SM-J200G Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3320.0 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Desktop, Chrome 63
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Desktop, Ubuntu, Chromium 61
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/61.0.3163.100 Chrome/61.0.3163.100 Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
// Galaxy S8, Android 8, Samsung Browser 6.2
2021-11-09 14:40:14 +00:00
assert . true ( this . isAvailable ( 'Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G950U1 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/6.2 Chrome/56.0.2924.87 Mobile Safari/537.36' ) ) ;
2018-01-12 17:45:39 +00:00
} ) ;
2023-11-07 16:29:17 +00:00
} ( ) ) ;