forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorShare.spec.ts
More file actions
36 lines (30 loc) · 1.12 KB
/
Copy pathcalculatorShare.spec.ts
File metadata and controls
36 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { buildCalculatorShareUrl, decodeCalculatorShare, encodeCalculatorShare } from './calculatorShare';
import type { CalculatorState } from '../components/SplitCalculator/SplitCalculator';
describe('calculatorShare', () => {
const sampleState: CalculatorState = {
type: 'equal',
participants: [
{ id: '1', name: 'Alice', amount: 10, percentage: 50, items: [] },
{ id: '2', name: 'Bob', amount: 10, percentage: 50, items: [] },
],
items: [],
totalAmount: 20,
taxAmount: 2,
tipAmount: 3,
currency: 'USD',
rounding: 'none',
};
it('encodes and decodes calculator state correctly', () => {
const raw = encodeCalculatorShare(sampleState);
const decoded = decodeCalculatorShare(raw);
expect(decoded).toEqual(sampleState);
});
it('builds a calculator share link containing the calculator route', () => {
const link = buildCalculatorShareUrl(sampleState);
expect(link).toContain('/calculator?data=');
expect(link).not.toContain(' ');
});
it('returns null for invalid share payloads', () => {
expect(decodeCalculatorShare('not-base64')).toBeNull();
});
});