UNPKG

@reown/appkit-scaffold-ui

Version:

The full stack toolkit to build onchain app UX.

80 lines 3.95 kB
import { fixture } from '@open-wc/testing'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; import { html } from 'lit'; import { ConnectorController, RouterController, StorageUtil } from '@reown/appkit-controllers'; import { W3mAccountAuthButton } from '../../src/partials/w3m-account-auth-button'; import { HelpersUtil } from '../utils/HelpersUtil'; const ACCOUNT_EMAIL = 'w3m-account-email-update'; const MOCK_EMAIL = 'example@gmail.com'; const MOCK_USERNAME = 'john_doe'; describe('W3mAccountAuthButton', () => { beforeEach(() => { vi.spyOn(StorageUtil, 'getConnectedConnectorId').mockReturnValue('AUTH'); }); afterEach(() => { vi.resetAllMocks(); }); test('it should show email when username does not exist', async () => { vi.spyOn(ConnectorController, 'getAuthConnector').mockReturnValue({ id: 'AUTH', provider: { getEmail: () => MOCK_EMAIL } }); vi.spyOn(ConnectorController, 'getConnectorId').mockReturnValue('AUTH'); const authButton = await fixture(html `<w3m-account-auth-button></w3m-account-auth-button>`); const accountEmail = HelpersUtil.getByTestId(authButton, ACCOUNT_EMAIL); expect(accountEmail).not.toBeNull(); expect(HelpersUtil.getTextContent(accountEmail)).toBe(MOCK_EMAIL); }); test('it should show username when email does not exist', async () => { vi.spyOn(StorageUtil, 'getConnectedSocialUsername').mockReturnValue(MOCK_USERNAME); vi.spyOn(ConnectorController, 'getAuthConnector').mockReturnValue({ id: 'AUTH', provider: { getEmail: () => null } }); vi.spyOn(ConnectorController, 'getConnectorId').mockReturnValue('AUTH'); const authButton = await fixture(html `<w3m-account-auth-button></w3m-account-auth-button>`); const accountEmail = HelpersUtil.getByTestId(authButton, ACCOUNT_EMAIL); expect(accountEmail).not.toBeNull(); expect(HelpersUtil.getTextContent(accountEmail)).toBe(MOCK_USERNAME); }); test('it should navigate to update email view screen when email button is clicked without a social provider', async () => { vi.spyOn(RouterController, 'push'); vi.spyOn(ConnectorController, 'getAuthConnector').mockReturnValue({ id: 'AUTH', provider: { getEmail: () => MOCK_EMAIL } }); vi.spyOn(StorageUtil, 'getConnectedSocialUsername').mockReturnValue('username'); vi.spyOn(ConnectorController, 'getConnectorId').mockReturnValue('AUTH'); const authButton = await fixture(html `<w3m-account-auth-button></w3m-account-auth-button>`); const accountEmail = HelpersUtil.getByTestId(authButton, ACCOUNT_EMAIL); expect(accountEmail).not.toBeNull(); accountEmail?.click(); expect(RouterController.push).toHaveBeenCalledWith('UpdateEmailWallet', { email: MOCK_EMAIL, redirectView: 'Account' }); }); test('it should not display when email is null, undefined and no username is set', async () => { const testCases = [null, undefined]; vi.spyOn(ConnectorController, 'getConnectorId').mockReturnValue('AUTH'); for (const emailValue of testCases) { vi.spyOn(ConnectorController, 'getAuthConnector').mockReturnValue({ id: 'AUTH', provider: { getEmail: () => emailValue } }); const authButton = await fixture(html `<w3m-account-auth-button></w3m-account-auth-button>`); const accountEmail = HelpersUtil.getByTestId(authButton, ACCOUNT_EMAIL); expect(accountEmail).toBeNull(); expect(authButton.style.display).toBe('none'); } }); }); //# sourceMappingURL=w3m-account-auth-button.test.js.map