33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6+ import type { IToken } from '../store/authtoken.ts'
7+
68import { createTestingPinia } from '@pinia/testing'
9+ import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
710import { mount } from '@vue/test-utils'
811import { beforeEach , describe , expect , it , vi } from 'vitest'
12+ import AuthToken from './AuthToken.vue'
13+ import AuthTokenDeleteDialog from './AuthTokenDeleteDialog.vue'
14+ import { TokenType , useAuthTokenStore } from '../store/authtoken.ts'
915
1016// AuthToken.vue reads window.oc_defaults at module evaluation time. vi.hoisted
11- // runs before imports, so this guarantees the property is set on the existing
12- // jsdom window before the SFC is first parsed.
17+ // is hoisted by Vitest above the imports at transform time, so this is set
18+ // on the existing jsdom window before the SFC is first parsed.
1319vi . hoisted ( ( ) => {
1420 ( window as unknown as { oc_defaults : { productName : string } } ) . oc_defaults = { productName : 'Nextcloud' }
1521} )
1622
17- import type { IToken } from '../store/authtoken.ts'
18-
1923// Mock @nextcloud /dialogs so the wipe action's showConfirmation call resolves
20- // synchronously in tests. Hoisted so it's installed before AuthToken.vue imports .
24+ // synchronously in tests. Hoisted alongside the rest .
2125const showConfirmationMock = vi . hoisted ( ( ) => vi . fn ( ) )
2226vi . mock ( '@nextcloud/dialogs' , ( ) => ( {
2327 showConfirmation : showConfirmationMock ,
2428} ) )
2529
26- import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
27- import AuthToken from './AuthToken.vue'
28- import AuthTokenDeleteDialog from './AuthTokenDeleteDialog.vue'
29- import { TokenType , useAuthTokenStore } from '../store/authtoken.ts'
30- import { detect } from '../utils/userAgentDetect.ts'
31-
3230function makeToken ( overrides : Partial < IToken > = { } ) : IToken {
3331 return {
3432 id : 1 ,
@@ -44,7 +42,6 @@ function makeToken(overrides: Partial<IToken> = {}): IToken {
4442
4543function mountAuthToken ( token : IToken ) {
4644 return mount ( AuthToken , {
47- // Vue Test Utils v1 (legacy pipeline) uses propsData; v2 also accepts it
4845 propsData : { token } ,
4946 mocks : {
5047 t : ( _ : string , text : string ) => text ,
@@ -192,51 +189,3 @@ describe('AuthTokenDeleteDialog wipe-pending warning', () => {
192189 expect ( noteCard . text ( ) ) . toMatch ( / w i p e / i)
193190 } )
194191} )
195-
196- describe ( 'Android Chrome detection' , ( ) => {
197- it ( 'modern Android Chrome (no Build/ string, post-2021) should match androidChrome' , ( ) => {
198- const ua = 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36'
199- expect ( detect ( ua ) ) . toEqual ( {
200- id : 'androidChrome' ,
201- version : '132' ,
202- } )
203- } )
204-
205- it ( 'legacy Android Chrome (with Build/ string, pre-2021) should match androidChrome' , ( ) => {
206- const ua = 'Mozilla/5.0 (Linux; Android 10; SM-G973F Build/QP1A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36'
207- expect ( detect ( ua ) ) . toEqual ( {
208- id : 'androidChrome' ,
209- version : '130' ,
210- } )
211- } )
212-
213- it ( 'Android Chrome on tablet (no "Mobile" in UA) should match androidChrome' , ( ) => {
214- const ua = 'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
215- expect ( detect ( ua ) ) . toEqual ( {
216- id : 'androidChrome' ,
217- version : '131' ,
218- } )
219- } )
220- } )
221-
222- describe ( 'Desktop Chrome regression tests' , ( ) => {
223- it ( 'Desktop Chrome on Linux should still match chrome' , ( ) => {
224- const ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36'
225- expect ( detect ( ua ) ) . toEqual ( {
226- id : 'chrome' ,
227- version : '132' ,
228- os : 'Linux' ,
229- } )
230- } )
231- } )
232-
233- describe ( 'Desktop Firefox regression tests' , ( ) => {
234- it ( 'Desktop Firefox on Linux should still match firefox' , ( ) => {
235- const ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0'
236- expect ( detect ( ua ) ) . toEqual ( {
237- id : 'firefox' ,
238- version : '124' ,
239- os : 'Linux' ,
240- } )
241- } )
242- } )
0 commit comments