Debian Codegraph @

skins/MinervaNeue/tests/qunit/skins.minerva.scripts/downloadPageAction.test.js

raw symbols SCIP
1 ( function () {
2 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';
3 const VALID_SUPPORTED_NAMESPACES = [ 0 ];
4 const spinner = () => ( {
5 $el: $( '<span>' )
6 } );
7 const Deferred = $.Deferred;
8 const windowChrome = { chrome: true };
9 const windowNotChrome = {};
10 const downloadAction = require( 'skins.minerva.scripts/downloadPageAction.js' );
11 const onClick = downloadAction.test.onClick;
12 const isAvailable = downloadAction.test.isAvailable;
13
14 class Page {
15 constructor( options ) {
16 this.isMissing = options.isMissing;
17 // eslint-disable-next-line no-underscore-dangle
18 this._isMainPage = !!options.isMainPage;
19 }
20
21 isMainPage() {
22 // eslint-disable-next-line no-underscore-dangle
23 return this._isMainPage;
24 }
25
26 getNamespaceId() {
27 return 0;
28 }
29 }
30 QUnit.module( 'Minerva DownloadIcon', {
31 beforeEach: function () {
32 this.getOnClickHandler = function ( onLoadAllImages ) {
33 const portletLink = document.createElement( 'li' );
34
35 return function () {
36 onClick( portletLink, spinner(), onLoadAllImages );
37 };
38 };
39 }
40 } );
41
42 QUnit.test( '#getOnClickHandler (print after image download)', function ( assert ) {
43 const
44 d = Deferred(),
45 handler = this.getOnClickHandler( () => d.resolve() ),
46 spy = this.sandbox.stub( window, 'print' );
47
48 handler();
49 d.then( () => {
50 assert.strictEqual( spy.callCount, 1, 'Print occurred.' );
51 } );
52
53 return d;
54 } );
55
56 QUnit.test( '#getOnClickHandler (print via timeout)', function ( assert ) {
57 const
58 d = Deferred(),
59 handler = this.getOnClickHandler( () => d.resolve() ),
60 spy = this.sandbox.stub( window, 'print' );
61
62 window.setTimeout( () => {
63 d.resolve();
64 }, 3400 );
65
66 handler();
67 d.then( () => {
68 assert.strictEqual( spy.callCount, 1,
69 'Print was called once despite loadImages resolving after MAX_PRINT_TIMEOUT' );
70 } );
71
72 return d;
73 } );
74
75 QUnit.test( '#getOnClickHandler (multiple clicks)', function ( assert ) {
76 const d = Deferred(),
77 handler = this.getOnClickHandler( () => d.resolve() ),
78 spy = this.sandbox.stub( window, 'print' );
79
80 window.setTimeout( () => {
81 d.resolve();
82 }, 3400 );
83
84 handler();
85 handler();
86 d.then( () => {
87 assert.strictEqual( spy.callCount, 1,
88 'Print was called once despite multiple clicks' );
89 } );
90
91 return d;
92 } );
93
94 QUnit.module( 'isAvailable()', {
95 beforeEach: function () {
96 const page = new Page( {
97 id: 0,
98 title: 'Test',
99 isMissing: false,
100 isMainPage: false
101 } );
102 this.page = page;
103 this.isAvailable = function ( ua ) {
104 return isAvailable( windowChrome, page, ua,
105 VALID_SUPPORTED_NAMESPACES );
106 };
107 this.notChromeIsAvailable = function ( ua ) {
108 return isAvailable( windowNotChrome, page, ua,
109 VALID_SUPPORTED_NAMESPACES );
110 };
111 }
112 } );
113
114 QUnit.test( 'isAvailable() handles properly correct namespace', function ( assert ) {
115 assert.true( this.isAvailable( VALID_UA ) );
116 } );
117
118 QUnit.test( 'isAvailable() handles properly not supported namespace', function ( assert ) {
119 assert.false( isAvailable( windowChrome, this.page, VALID_UA, [ 9999 ] ) );
120 } );
121
122 QUnit.test( 'isAvailable() handles missing pages', ( assert ) => {
123 const page = new Page( {
124 id: 0,
125 title: 'Missing',
126 isMissing: true
127 } );
128 assert.false( isAvailable( windowChrome, page, VALID_UA, VALID_SUPPORTED_NAMESPACES ) );
129 } );
130
131 QUnit.test( 'isAvailable() handles properly main page', ( assert ) => {
132 const page = new Page( {
133 id: 0,
134 title: 'Test',
135 isMissing: false,
136 isMainPage: true
137 } );
138 assert.false( isAvailable( windowChrome, page, VALID_UA, VALID_SUPPORTED_NAMESPACES ) );
139 } );
140
141 QUnit.test( 'isAvailable() returns false for iOS', function ( assert ) {
142 assert.false( this.isAvailable( 'ipad' ) );
143 } );
144
145 QUnit.test( 'isAvailable() uses window.chrome to filter certain chrome-like browsers', function ( assert ) {
146 // Dolphin
147 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' ) );
148 // Opera
149 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' ) );
150 // Maxthon
151 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' ) );
152 } );
153
154 QUnit.test( 'isAvailable() handles properly browsers', function ( assert ) {
155 // IPhone 6 Safari
156 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' ) );
157 // Nokia Lumia 930 Windows Phone 8.1
158 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' ) );
159 // Firefox @ Ubuntu
160 assert.false( this.isAvailable( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0' ) );
161 } );
162
163 QUnit.test( 'isAvailable() handles properly non-chrome browsers', function ( assert ) {
164 // IPhone 6 Safari
165 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' ) );
166 // Nokia Lumia 930 Windows Phone 8.1
167 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' ) );
168 // Firefox @ Ubuntu
169 assert.false( this.notChromeIsAvailable( 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0' ) );
170 } );
171
172 QUnit.test( 'isAvailable() handles properly old devices', function ( assert ) {
173 // Samsung Galaxy S5, Android 4.4, Chrome 28
174 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' ) );
175 // Samsung Galaxyu S1, Android 4.2.2 Cyanogenmod + built in Samsung Browser
176 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' ) );
177 // Samsung Galaxy S3
178 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' ) );
179 } );
180
181 QUnit.test( 'isAvailable() handles properly supported browsers', function ( assert ) {
182 // Samsung Galaxy S7, Android 6, Chrome 44
183 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' ) );
184 // Samsung Galaxy A5, Android 7, Samsung Browser 5.2
185 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' ) );
186 // Galaxy J2, Android 5, Chrome 65
187 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' ) );
188 // Desktop, Chrome 63
189 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' ) );
190 // Desktop, Ubuntu, Chromium 61
191 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' ) );
192 // Galaxy S8, Android 8, Samsung Browser 6.2
193 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' ) );
194 } );
195
196 }() );