clarity-decode
Version:
An analytics library that uses web page interactions to generate aggregated insights
62 lines (54 loc) • 4.08 kB
text/typescript
import { test, expect } from '@playwright/test';
import { decode } from 'clarity-decode';
test.describe('decode function', () => {
test('should decode a simple payload', () => {
// This is a very simple test that focuses on basic decoding functionality
const testPayload = {
e: ["0.8.20", 1, 0, 506, "devtools", "1mtqiaz", "1c27tix", 2, 0, 0, 0, "https://test.com/"],
a: [
[],
[],
[],
[],
[],
[],
[],
[], 1, ["https://test.com/"], 3, ["A little bit of this and that!"], 4, ["test.com"], 5, ["BlogPosting"], 9, ["en-US"], 15, ["1xtxvl0"], 17, ["ltr"], 18, ["Story 8", "Story 7", "Story 6"], 20, ["A title!"], 21, ["blogger"], 22, ["macOS"], 23, ["15.5.0"], 24, ["undefined~8", "undefined~138"], 26, ["1.7999999523162842"], 27, ["4g"], 28, ["1979"], 29, ["2"], 31, ["44nejbc7s.6933hhug7"], 32, ["519i394pb.53uwavtzg"], 34, ["America/Los_Angeles"], 35, ["420"], 36, ["1"], 37, ["-1"]],
[],
[],
[]
],
};
const input = JSON.stringify(testPayload);
const result = decode(input);
expect(typeof result).toBe('object');
expect(typeof result.timestamp).toBe('number');
expect(typeof result.envelope).toBe('object');
expect(result.envelope.version).toBe("0.8.20");
expect(result.visibility[0].data.visible).toBe(1);
expect(result.contextMenu[0].data.target).toBe(488);
expect(result.contextMenu[0].data.button).toBe(2);
});
test('visibility event should be backward compatible to support string values', () => {
// This is a very simple test that focuses on basic decoding functionality
const testPayload = {
e: ["0.8.20", 1, 0, 506, "devtools", "1mtqiaz", "1c27tix", 2, 0, 0, 0, "https://test.com/"],
a: [
[],
[],
[],
[], 1, ["https://test.com/"], 3, ["A little bit of this and that!"], 4, ["test.com"], 5, ["BlogPosting"], 9, ["en-US"], 15, ["1xtxvl0"], 17, ["ltr"], 18, ["Story 8", "Story 7", "Story 6"], 20, ["A title!"], 21, ["blogger"], 22, ["macOS"], 23, ["15.5.0"], 24, ["undefined~8", "undefined~138"], 26, ["1.7999999523162842"], 27, ["4g"], 28, ["1979"], 29, ["2"], 31, ["44nejbc7s.6933hhug7"], 32, ["519i394pb.53uwavtzg"], 34, ["America/Los_Angeles"], 35, ["420"], 36, ["1"], 37, ["-1"]],
[],
[],
[]
],
};
const input = JSON.stringify(testPayload);
const result = decode(input);
expect(typeof result).toBe('object');
expect(typeof result.timestamp).toBe('number');
expect(typeof result.envelope).toBe('object');
expect(result.envelope.version).toBe("0.8.20");
expect(result.visibility[0].data.visible).toBe(1);
});
});