Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia committed Feb 7, 2024
1 parent 5b971e0 commit fd6eebb
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
56 changes: 56 additions & 0 deletions src/components/FrameMetadata.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,60 @@ describe('FrameMetadata', () => {
expect(meta.container.querySelector('meta[name="fc:frame:image"]')).not.toBeNull();
expect(meta.container.querySelectorAll('meta').length).toBe(2);
});

it('renders with action mint', () => {
const meta = render(
<FrameMetadata
image="https://example.com/image.png"
buttons={[
{
label: 'Mint',
action: 'mint',
target: 'https://zizzamia.xyz/api/frame/mint',
},
]}
/>,
);
expect(meta.container.querySelector('meta[name="fc:frame:button:1:action"]')).not.toBeNull();
expect(
meta.container
.querySelector('meta[name="fc:frame:button:1:action"]')
?.getAttribute('content'),
).toBe('mint');
expect(meta.container.querySelector('meta[name="fc:frame:button:1:target"]')).not.toBeNull();
expect(
meta.container
.querySelector('meta[name="fc:frame:button:1:target"]')
?.getAttribute('content'),
).toBe('https://zizzamia.xyz/api/frame/mint');
expect(meta.container.querySelectorAll('meta').length).toBe(5);
});

it('renders with action link', () => {
const meta = render(
<FrameMetadata
image="https://example.com/image.png"
buttons={[
{
label: 'Link',
action: 'link',
target: 'https://zizzamia.xyz/api/frame/link',
},
]}
/>,
);
expect(meta.container.querySelector('meta[name="fc:frame:button:1:action"]')).not.toBeNull();
expect(
meta.container
.querySelector('meta[name="fc:frame:button:1:action"]')
?.getAttribute('content'),
).toBe('link');
expect(meta.container.querySelector('meta[name="fc:frame:button:1:target"]')).not.toBeNull();
expect(
meta.container
.querySelector('meta[name="fc:frame:button:1:target"]')
?.getAttribute('content'),
).toBe('https://zizzamia.xyz/api/frame/link');
expect(meta.container.querySelectorAll('meta').length).toBe(5);
});
});
3 changes: 1 addition & 2 deletions src/components/FrameMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export function FrameMetadata({
)}
{!!button.target && (
<meta name={`fc:frame:button:${index + 1}:target`} content={button.target} />
)
}
)}
</>
);
})}
Expand Down
34 changes: 33 additions & 1 deletion src/core/getFrameHtmlResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('getFrameHtmlResponse', () => {
const html = getFrameHtmlResponse({
buttons: [
{ label: 'button1', action: 'post' },
{ label: 'button2' },
{ label: 'button2', action: 'mint', target: 'https://example.com' },
{ label: 'button3', action: 'post_redirect' },
{ label: 'button4' },
],
Expand All @@ -24,6 +24,8 @@ describe('getFrameHtmlResponse', () => {
'<meta property="fc:frame:button:1" content="button1" />' +
'<meta property="fc:frame:button:1:action" content="post" />' +
'<meta property="fc:frame:button:2" content="button2" />' +
'<meta property="fc:frame:button:2:action" content="mint" />' +
'<meta property="fc:frame:button:2:target" content="https://example.com" />' +
'<meta property="fc:frame:button:3" content="button3" />' +
'<meta property="fc:frame:button:3:action" content="post_redirect" />' +
'<meta property="fc:frame:button:4" content="button4" />' +
Expand All @@ -32,6 +34,36 @@ describe('getFrameHtmlResponse', () => {
);
});

it('should return correct HTML with action mint', () => {
const html = getFrameHtmlResponse({
buttons: [{ label: 'Mint', action: 'mint', target: 'https://zizzamia.xyz/api/frame/mint' }],
image: 'https://zizzamia.xyz/park-1.png',
});

expect(html).toBe(
'<!DOCTYPE html><html><head><meta property="fc:frame" content="vNext" />' +
'<meta property="fc:frame:image" content="https://zizzamia.xyz/park-1.png" />' +
'<meta property="fc:frame:button:1" content="Mint" />' +
'<meta property="fc:frame:button:1:action" content="mint" />' +
'<meta property="fc:frame:button:1:target" content="https://zizzamia.xyz/api/frame/mint" /></head></html>',
);
});

it('should return correct HTML with action linkt', () => {
const html = getFrameHtmlResponse({
buttons: [{ label: 'Link', action: 'link', target: 'https://zizzamia.xyz/api/frame/link' }],
image: 'https://zizzamia.xyz/park-1.png',
});

expect(html).toBe(
'<!DOCTYPE html><html><head><meta property="fc:frame" content="vNext" />' +
'<meta property="fc:frame:image" content="https://zizzamia.xyz/park-1.png" />' +
'<meta property="fc:frame:button:1" content="Link" />' +
'<meta property="fc:frame:button:1:action" content="link" />' +
'<meta property="fc:frame:button:1:target" content="https://zizzamia.xyz/api/frame/link" /></head></html>',
);
});

it('should handle no input', () => {
const html = getFrameHtmlResponse({
buttons: [{ label: 'button1' }],
Expand Down
42 changes: 42 additions & 0 deletions src/core/getFrameMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,46 @@ describe('getFrameMetadata', () => {
'fc:frame:refresh_period': '10',
});
});

it('should return the correct metadata with action mint', () => {
expect(
getFrameMetadata({
buttons: [{ label: 'Mint', action: 'mint', target: 'https://zizzamia.xyz/api/frame/mint' }],
image: 'https://zizzamia.xyz/park-1.png',
input: {
text: 'Tell me a boat story',
},
post_url: 'https://zizzamia.xyz/api/frame',
}),
).toEqual({
'fc:frame': 'vNext',
'fc:frame:button:1': 'Mint',
'fc:frame:button:1:action': 'mint',
'fc:frame:button:1:target': 'https://zizzamia.xyz/api/frame/mint',
'fc:frame:image': 'https://zizzamia.xyz/park-1.png',
'fc:frame:input:text': 'Tell me a boat story',
'fc:frame:post_url': 'https://zizzamia.xyz/api/frame',
});
});

it('should return the correct metadata with action link', () => {
expect(
getFrameMetadata({
buttons: [{ label: 'Link', action: 'link', target: 'https://zizzamia.xyz/frame/link' }],
image: 'https://zizzamia.xyz/park-1.png',
input: {
text: 'Tell me a boat story',
},
post_url: 'https://zizzamia.xyz/api/frame',
}),
).toEqual({
'fc:frame': 'vNext',
'fc:frame:button:1': 'Link',
'fc:frame:button:1:action': 'link',
'fc:frame:button:1:target': 'https://zizzamia.xyz/api/frame/link',
'fc:frame:image': 'https://zizzamia.xyz/park-1.png',
'fc:frame:input:text': 'Tell me a boat story',
'fc:frame:post_url': 'https://zizzamia.xyz/api/frame',
});
});
});

0 comments on commit fd6eebb

Please sign in to comment.