Skip to content

Commit

Permalink
Merge branch 'main' into enes/apkt-1689-connecting-to-multiple-adapte…
Browse files Browse the repository at this point in the history
…r-instance-with-mm-and
  • Loading branch information
enesozturk authored Dec 10, 2024
2 parents 194b3d7 + ff1834c commit b99c0e3
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ConnectionController, CoreHelperUtil, RouterController } from '@reown/appkit-core'
import { beforeAll, describe, expect, it, vi } from 'vitest'
import { W3mConnectingWcMobile } from '../../src/partials/w3m-connecting-wc-mobile'
import { fixture, html } from '@open-wc/testing'

const WC_URI = 'uri'

describe('W3mConnectingWcMobile', () => {
beforeAll(() => {
vi.spyOn(RouterController, 'state', 'get').mockReturnValue({
...RouterController.state,
data: {
wallet: {
id: 'test',
name: 'test',
mobile_link: 'link'
}
}
})
vi.spyOn(ConnectionController, 'state', 'get').mockReturnValue({
...ConnectionController.state,
wcUri: WC_URI
})
vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(true)
})

it('should call openHref with _self if not in an iframe', async () => {
const openHrefSpy = vi.spyOn(CoreHelperUtil, 'openHref')
const el: W3mConnectingWcMobile = await fixture(
html`<w3m-connecting-wc-mobile></w3m-connecting-wc-mobile>`
)
el['onConnectProxy']()

expect(openHrefSpy).toHaveBeenCalledWith(`link://wc?uri=${WC_URI}`, '_self')
})
it('should call openHref with _top if inside iframe', async () => {
const originalTop = global.window.top
const originalSelf = global.window.self
try {
;(global.window as any).top = { name: 'top' }
;(global.window as any).self = { name: 'self' }

const openHrefSpy = vi.spyOn(CoreHelperUtil, 'openHref')
const el: W3mConnectingWcMobile = await fixture(
html`<w3m-connecting-wc-mobile></w3m-connecting-wc-mobile>`
)
el['onConnectProxy']()

expect(openHrefSpy).toHaveBeenCalledWith(`link://wc?uri=${WC_URI}`, '_top')
} finally {
global.window.top = originalTop
global.window.self = originalSelf
}
})
})

0 comments on commit b99c0e3

Please sign in to comment.