Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add test for w3m-connecting-header #3650

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
70 changes: 70 additions & 0 deletions packages/scaffold-ui/test/partials/w3m-connecting-header.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { W3mConnectingHeader } from '../../src/partials/w3m-connecting-header'
import { describe, it, expect, vi, afterEach } from 'vitest'
import { elementUpdated, fixture } from '@open-wc/testing'
import { html } from 'lit'
import { HelpersUtil } from '../utils/HelpersUtil'
import type { WuiTabs } from '@reown/appkit-ui'
import type { Platform } from '@reown/appkit-core'

// -- 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.only('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)
}
})
})
Loading