Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

81 lines
2.9 KiB
TypeScript

import { parse } from '../src';
const plain = (value: string) => ({ type: 'PLAIN_TEXT' as const, value });
const paragraph = (value: Array<Record<string, unknown>>) => ({ type: 'PARAGRAPH' as const, value });
const bold = (value: Array<Record<string, unknown>>) => ({ type: 'BOLD' as const, value });
const strike = (value: Array<Record<string, unknown>>) => ({ type: 'STRIKE' as const, value });
// `fallback` is the [start, end] offset span of the raw `<t:...>` in the source.
const timestampNode = (value: string, format: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' = 't', fallback?: [number, number]) => ({
type: 'TIMESTAMP' as const,
value: {
timestamp: value,
format,
},
...(fallback !== undefined ? { fallback } : {}),
});
const spanOf = (input: string, raw: string): [number, number] => {
const start = input.indexOf(raw);
return [start, start + raw.length];
};
test.each([
['<t:1708551317>', '<t:1708551317>', '1708551317', 't' as const],
['<t:1708551317:R>', '<t:1708551317:R>', '1708551317', 'R' as const],
['hello <t:1708551317>', '<t:1708551317>', '1708551317', 't' as const],
])('parses %p', (input, raw, value, format) => {
const node = timestampNode(value, format, spanOf(input, raw));
const prefix = input.slice(0, input.indexOf(raw));
expect(parse(input)).toEqual([paragraph(prefix ? [plain(prefix), node] : [node])]);
});
test.each([
['<t:1708551317:I>', [paragraph([plain('<t:1708551317:I>')])]],
['<t:17>', [paragraph([plain('<t:17>')])]],
])('parses %p', (input, output) => {
expect(parse(input)).toEqual(output);
});
test.each([
['~<t:1708551317>~', '<t:1708551317>', '1708551317', 't' as const, strike],
['~<t:1708551317:R>~', '<t:1708551317:R>', '1708551317', 'R' as const, strike],
['*<t:1708551317>*', '<t:1708551317>', '1708551317', 't' as const, bold],
])('parses %p', (input, raw, value, format, wrapper) => {
const node = timestampNode(value, format, spanOf(input, raw));
expect(parse(input)).toEqual([paragraph([wrapper([node])])]);
});
test.each([
['<t:2025-07-22T10:00:00.000+00:00:R>', '1753178400', 'R' as const],
['<t:2025-07-22T10:00:00+00:00:R>', '1753178400', 'R' as const],
['<t:2025-07-24T20:19:58.154+00:00:R>', '1753388398', 'R' as const],
])('parses %p', (input, value, format) => {
const node = timestampNode(value, format, [0, input.length]);
expect(parse(input)).toEqual([paragraph([node])]);
});
describe('relative hour timestamp parsing', () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2025-07-22T00:00:00.000Z'));
});
afterAll(() => {
jest.useRealTimers();
});
test.each([
['<t:10:00:00+00:00:R>', '1753178400', 'R' as const],
['<t:10:00+00:00:R>', '1753178400', 'R' as const],
['<t:10:00:05+00:00>', '1753178405', 't' as const],
['<t:10:00+00:00>', '1753178400', 't' as const],
])('parses %p', (input, value, format) => {
const node = timestampNode(value, format, [0, input.length]);
expect(parse(input)).toEqual([paragraph([node])]);
});
});