Skip to content

Commit

Permalink
refactor: use metadata from options if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Oct 23, 2024
1 parent 7177364 commit 9f29e9d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
70 changes: 70 additions & 0 deletions packages/appkit/src/tests/appkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ describe('Base', () => {

beforeEach(() => {
vi.resetAllMocks()

Object.defineProperty(global, 'document', {
value: {
title: 'Document Title',
querySelector: vi.fn().mockImplementation(selector => {
if (selector === 'meta[property="og:description"]') {
return { content: 'Document Description' }
} else if (selector === 'link[rel~="icon"]') {
return { href: 'https://example.com/favicon.ico' }
}
return null
}),
getElementsByTagName: vi.fn().mockImplementation(tagName => {
if (tagName === 'title') {
return [{ textContent: 'Document Title' }]
}
return []
})
},
writable: true
})

Object.defineProperty(global, 'window', {
value: {
location: {
origin: 'https://example.com'
}
},
writable: true
})

appKit = new AppKit(mockOptions)
})

Expand Down Expand Up @@ -441,4 +472,43 @@ describe('Base', () => {
expect(result).toBe('connector-image-url')
})
})

describe('Metadata Handling', () => {
it('should read metadata from document object when not provided', () => {
appKit = new AppKit(mockOptions)
expect(OptionsController.setMetadata).toHaveBeenCalledWith({
name: 'Document Title',
description: 'Document Description',
url: 'https://example.com',
icons: ['https://example.com/favicon.ico']
})
})

it('should use provided metadata when available', () => {
const customMetadata = {
name: 'Custom Name',
description: 'Custom Description',
url: 'https://custom.com',
icons: ['https://custom.com/icon.png']
}
appKit = new AppKit({ ...mockOptions, metadata: customMetadata })
expect(OptionsController.setMetadata).toHaveBeenCalledWith(customMetadata)
})

it('should use a mix of provided and document metadata', () => {
const partialMetadata = {
name: 'Custom Name',
description: '',
url: '',
icons: ['https://custom.com/icon.png']
}
appKit = new AppKit({ ...mockOptions, metadata: partialMetadata })
expect(OptionsController.setMetadata).toHaveBeenCalledWith({
name: 'Custom Name',
description: 'Document Description',
url: 'https://example.com',
icons: ['https://custom.com/icon.png']
})
})
})
})
6 changes: 0 additions & 6 deletions packages/appkit/src/tests/mocks/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ export const mockOptions = {
projectId: 'test-project-id',
adapters: [{ chainNamespace: 'eip155' } as unknown as ChainAdapter],
networks: [mainnet, solana],
metadata: {
name: 'Test App',
description: 'Test App Description',
url: 'https://test-app.com',
icons: ['https://test-app.com/icon.png']
},
sdkVersion: `html-wagmi-5.1.6` as SdkVersion
} as unknown as AppKitOptions & {
sdkVersion: SdkVersion
Expand Down

0 comments on commit 9f29e9d

Please sign in to comment.