Something went wrong. Try again.
[PRE-ALPHA] an open source web-based 2D/3D graphing calculator cartesium.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104import { describe, expect, it } from 'vitest';
import { GRAPH_EMBED_API_VERSION, GRAPH_EMBED_PROTOCOL_VERSION, GRAPH_EMBED_V1_INTERACTION, GRAPH_EMBED_V1_PROTOCOL_VERSION, isGraphEmbedHostMessage, isGraphEmbedV1LifecycleMessage, isGraphEmbedViewerMessage} from './protocol';
describe('graph embed protocol', () => { it('accepts bounded viewport commands', () => { expect( isGraphEmbedHostMessage({ type: 'cartesium:embed:set-viewport', version: GRAPH_EMBED_PROTOCOL_VERSION, viewport: { x_min: -2, x_max: 2, y_min: -1, y_max: 1 } }) ).toBe(true); expect( isGraphEmbedHostMessage({ type: 'cartesium:embed:set-viewport', version: GRAPH_EMBED_PROTOCOL_VERSION, viewport: { x_min: 2, x_max: -2, y_min: -1, y_max: 1 } }) ).toBe(false); });
it('rejects unknown versions and malformed viewer messages', () => { expect( isGraphEmbedHostMessage({ type: 'cartesium:embed:reset-viewport', version: 2 }) ).toBe(false); expect( isGraphEmbedViewerMessage({ type: 'cartesium:embed:ready', version: GRAPH_EMBED_PROTOCOL_VERSION }) ).toBe(false); });
it('accepts only boolean expanded-state commands', () => { expect( isGraphEmbedHostMessage({ type: 'cartesium:embed:set-expanded', version: GRAPH_EMBED_PROTOCOL_VERSION, expanded: true }) ).toBe(true); expect( isGraphEmbedHostMessage({ type: 'cartesium:embed:set-expanded', version: GRAPH_EMBED_PROTOCOL_VERSION, expanded: 'yes' }) ).toBe(false); });
it('validates the independently versioned v1 lifecycle envelope', () => { expect( isGraphEmbedV1LifecycleMessage({ type: 'cartesium.embed.ready', protocolVersion: GRAPH_EMBED_V1_PROTOCOL_VERSION, embedApiVersion: GRAPH_EMBED_API_VERSION, interaction: GRAPH_EMBED_V1_INTERACTION, title: 'Graph' }) ).toBe(true); expect( isGraphEmbedV1LifecycleMessage({ type: 'cartesium.embed.error', protocolVersion: GRAPH_EMBED_V1_PROTOCOL_VERSION, embedApiVersion: GRAPH_EMBED_API_VERSION, interaction: GRAPH_EMBED_V1_INTERACTION, code: 'missing-source', message: 'Missing source.' }) ).toBe(true); expect( isGraphEmbedV1LifecycleMessage({ type: 'cartesium.embed.ready', protocolVersion: 2, embedApiVersion: GRAPH_EMBED_API_VERSION, interaction: GRAPH_EMBED_V1_INTERACTION, title: 'Graph' }) ).toBe(false); expect( isGraphEmbedV1LifecycleMessage({ type: 'cartesium.embed.error', protocolVersion: GRAPH_EMBED_V1_PROTOCOL_VERSION, embedApiVersion: GRAPH_EMBED_API_VERSION, interaction: GRAPH_EMBED_V1_INTERACTION, code: 'secret-internal-code', message: 'Error' }) ).toBe(false); });});