Skip to content

Commit

Permalink
feat: add test cases for snapshot integration (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Apr 4, 2023
1 parent 8d24a2d commit 1ce0c29
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apps/web/src/components/Shared/Snapshot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import Header from './Header';

interface WrapperProps {
children: ReactNode;
dataTestId?: string;
}

const Wrapper: FC<WrapperProps> = ({ children }) => (
<Card className="mt-3 cursor-auto p-5" onClick={stopEventPropagation}>
const Wrapper: FC<WrapperProps> = ({ children, dataTestId = '' }) => (
<Card className="mt-3 cursor-auto p-5" dataTestId={dataTestId} onClick={stopEventPropagation}>
{children}
</Card>
);
Expand Down Expand Up @@ -52,7 +53,7 @@ const Snapshot: FC<SnapshotProps> = ({ propsalId }) => {
const { proposal, votes } = data;

return (
<Wrapper>
<Wrapper dataTestId={`snapshot-${proposal.id}`}>
<Header proposal={proposal as Proposal} />
<Choices proposal={proposal as Proposal} votes={votes as Vote[]} />
</Wrapper>
Expand Down
12 changes: 12 additions & 0 deletions tests/scripts/apps/web/publication.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ test.describe('Publication attachments', () => {
await expect(publicationOembed).toBeVisible();
});
});

test.describe('Publication snapshot widget', () => {
test('should have normal oembed', async ({ page }) => {
await page.goto(`${WEB_BASE_URL}/posts/0x24b6-0x11`);

const snapshotWidget = page.getByTestId(
'snapshot-0x0f24d1b2ba7bf01e325b8800d170358b56b7181818f8e58efcc58879b99616b7'
);
await expect(snapshotWidget).toContainText('Should we build Lenster polls via Snapshot?');
await expect(snapshotWidget).toContainText('Yes ser');
});
});
});

test.describe('Publication sidebar', () => {
Expand Down
23 changes: 23 additions & 0 deletions tests/scripts/packages/lib/getSnapshotProposalId.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from '@playwright/test';
import getSnapshotProposalId from 'lib/getSnapshotProposalId';

test.describe('getSnapshotProposalId', () => {
test('should return null for invalid urls', () => {
expect(getSnapshotProposalId('https://snapshot.org')).toBeNull();
expect(getSnapshotProposalId('https://snapshot.org/#/invalid-url')).toBeNull();
expect(getSnapshotProposalId('https://snapshot.org/#/123.eth/proposal/invalid-id')).toBeNull();
});

test('should return the proposal id for valid urls', () => {
expect(
getSnapshotProposalId(
'https://snapshot.org/#/123.eth/proposal/0x1234567890123456789012345678901234567890123456789012345678901234'
)
).toEqual('0x1234567890123456789012345678901234567890123456789012345678901234');
expect(
getSnapshotProposalId(
'https://snapshot.org/#/abc123.eth/proposal/0xabcdefABCDEFabcdefABCDEFabcdefABCDEFABCDEFabcdefABCDEFABCDEFabcd'
)
).toEqual('0xabcdefABCDEFabcdefABCDEFabcdefABCDEFABCDEFabcdefABCDEFABCDEFabcd');
});
});

2 comments on commit 1ce0c29

@vercel
Copy link

@vercel vercel bot commented on 1ce0c29 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

prerender – ./apps/prerender

prerender-git-main-lenster.vercel.app
prerender.lenster.xyz
prerender-lenster.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 1ce0c29 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

web-git-main-lenster.vercel.app
lenster.vercel.app
web-lenster.vercel.app
lenster.xyz

Please sign in to comment.