-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for
w3m-connecting-header
(#3650)
Co-authored-by: Enes <[email protected]>
- Loading branch information
1 parent
ef9c289
commit c9a240f
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
packages/scaffold-ui/test/partials/w3m-connecting-header.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,73 @@ | ||
import { elementUpdated, fixture } from '@open-wc/testing' | ||
import { afterEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { html } from 'lit' | ||
|
||
import type { Platform } from '@reown/appkit-core' | ||
import type { WuiTabs } from '@reown/appkit-ui' | ||
|
||
import { W3mConnectingHeader } from '../../src/partials/w3m-connecting-header' | ||
import { HelpersUtil } from '../utils/HelpersUtil' | ||
|
||
// -- Constants ------------------------------------------- // | ||
const TABS = 'wui-tabs' | ||
|
||
const TAB_VALUES = { | ||
mobile: { | ||
icon: 'mobile', | ||
label: 'Mobile', | ||
platform: 'mobile' | ||
}, | ||
browser: { | ||
icon: 'extension', | ||
label: 'Browser', | ||
platform: 'browser' | ||
}, | ||
desktop: { | ||
icon: 'desktop', | ||
label: 'Desktop', | ||
platform: 'desktop' | ||
} | ||
} | ||
|
||
// -- Helpers --------------------------------------------- // | ||
async function createComponent(platformTabs: Platform[]) { | ||
const element: W3mConnectingHeader = await fixture( | ||
html`<w3m-connecting-header .platforms=${platformTabs}></w3m-connecting-header>` | ||
) | ||
const { tabs } = HelpersUtil.querySelect(element, TABS) as WuiTabs | ||
|
||
return { element, tabs } | ||
} | ||
|
||
describe('W3mConnectingHeader', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('it should display different platforms', async () => { | ||
expect((await createComponent(['mobile'])).tabs).toStrictEqual([TAB_VALUES.mobile]) | ||
expect((await createComponent(['browser'])).tabs).toStrictEqual([TAB_VALUES.browser]) | ||
expect((await createComponent(['desktop'])).tabs).toStrictEqual([TAB_VALUES.desktop]) | ||
}) | ||
|
||
it('it should activate the correct platform tab when clicked', async () => { | ||
const TABS: Platform[] = ['mobile', 'browser', 'desktop'] | ||
|
||
const { element } = await createComponent(TABS) | ||
|
||
const tabs = HelpersUtil.querySelect(element, 'wui-tabs') | ||
|
||
for (const platform of TABS) { | ||
HelpersUtil.getByTestId(tabs, `tab-${platform.toLowerCase()}`).click() | ||
|
||
element.requestUpdate() | ||
await elementUpdated(element) | ||
|
||
const tabElement = HelpersUtil.getByTestId(tabs, `tab-${platform.toLowerCase()}`) | ||
const isActive = tabElement.getAttribute('data-active') === 'true' | ||
|
||
expect(isActive).toBe(true) | ||
} | ||
}) | ||
}) |