Skip to content

Commit

Permalink
not workng yet
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Feb 19, 2025
1 parent 4d75471 commit b147c59
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.1",
"eslint-plugin-svelte": "^2.36.0",
"fast-check": "^3.23.2",
"globals": "^15.0.0",
"jsdom": "^24.0.0",
"lodash": "^4.17.21",
Expand Down
40 changes: 40 additions & 0 deletions packages/ui-components/src/__tests__/handleShareChoices.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { handleShareChoices } from '../lib/services/handleShareChoices';
import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
import fc from 'fast-check';

describe('handleShareChoices', () => {
beforeEach(() => {
Expand Down Expand Up @@ -50,3 +51,42 @@ describe('handleShareChoices', () => {
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('http://example.com/?state=');
});
});

describe('property-based tests', () => {
beforeEach(() => {
Object.assign(navigator, {
clipboard: {
writeText: vi.fn()
}
});

vi.mock('$app/stores', () => ({
page: {
subscribe: vi.fn((fn) => {
fn({ url: new URL('http://example.com') });
return () => {};
})
}
}));
});

it('should always create valid URLs with any state string', async () => {
await fc.assert(
fc.asyncProperty(fc.string(), async (state) => {
const mockGui = {
serializeState: vi.fn().mockReturnValue(state)
};

await handleShareChoices(mockGui as unknown as DotrainOrderGui);

const clipboardText = (navigator.clipboard.writeText as any).mock.calls[0][0];
const url = new URL(clipboardText);

// Property: URL should always be valid and contain the state parameter
expect(url.searchParams.has('state')).toBe(true);
// Compare with the encoded state value
expect(url.searchParams.get('state')).toBe(encodeURIComponent(state));
})
);
});
});

0 comments on commit b147c59

Please sign in to comment.