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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test cases for snapshot integration #2377

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});