-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into enes/apkt-1689-connecting-to-multiple-adapte…
…r-instance-with-mm-and
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/scaffold-ui/test/partials/w3m-connecting-wc-mobile.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
}) |