From 224daecc24cab001a93740c71bdcab5bfc2b0b21 Mon Sep 17 00:00:00 2001
From: Le Vivilet <72156503+levivilet@users.noreply.github.com>
Date: Fri, 27 Dec 2024 13:27:41 +0100
Subject: [PATCH] feature: add setInfo tests (#254)
* feature: add setInfo tests
* test
* lint
---
packages/preview-process/test/SetInfo.test.ts | 62 +++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100644 packages/preview-process/test/SetInfo.test.ts
diff --git a/packages/preview-process/test/SetInfo.test.ts b/packages/preview-process/test/SetInfo.test.ts
new file mode 100644
index 00000000..cdbbac9a
--- /dev/null
+++ b/packages/preview-process/test/SetInfo.test.ts
@@ -0,0 +1,62 @@
+import { expect, test } from '@jest/globals'
+import * as GetInfo from '../src/parts/GetInfo/GetInfo.ts'
+import * as SetInfo from '../src/parts/SetInfo/SetInfo.ts'
+
+test('setInfo - stores info correctly', () => {
+ const id = 1
+ const webViewId = 'test-view'
+ const webViewRoot = '/test/root'
+ const contentSecurityPolicy = "default-src 'self'"
+ const iframeContent = '
Test Content
'
+
+ SetInfo.setInfo(id, webViewId, webViewRoot, contentSecurityPolicy, iframeContent)
+
+ const info = GetInfo.getInfo('lvce-webview://test-view')
+ expect(info).toEqual({
+ webViewId,
+ webViewRoot,
+ contentSecurityPolicy,
+ iframeContent,
+ })
+})
+
+test.skip('setInfo - overwrites existing info with same id', () => {
+ const id = 1
+ const initialWebViewId = 'initial-view'
+ const updatedWebViewId = 'updated-view'
+ const webViewRoot = '/test/root'
+ const contentSecurityPolicy = "default-src 'self'"
+ const iframeContent = 'Test Content
'
+
+ SetInfo.setInfo(id, initialWebViewId, webViewRoot, contentSecurityPolicy, iframeContent)
+ SetInfo.setInfo(id, updatedWebViewId, webViewRoot, contentSecurityPolicy, iframeContent)
+
+ expect(() => GetInfo.getInfo('lvce-webview://initial-view')).toThrow('webview info not found')
+
+ const updatedInfo = GetInfo.getInfo('lvce-webview://updated-view')
+ expect(updatedInfo).toEqual({
+ webViewId: updatedWebViewId,
+ webViewRoot,
+ contentSecurityPolicy,
+ iframeContent,
+ })
+})
+
+test.skip('setInfo - handles multiple different ids', () => {
+ const id1 = 1
+ const id2 = 2
+ const webViewId1 = 'view-1'
+ const webViewId2 = 'view-2'
+ const webViewRoot = '/test/root'
+ const contentSecurityPolicy = "default-src 'self'"
+ const iframeContent = 'Test Content
'
+
+ SetInfo.setInfo(id1, webViewId1, webViewRoot, contentSecurityPolicy, iframeContent)
+ SetInfo.setInfo(id2, webViewId2, webViewRoot, contentSecurityPolicy, iframeContent)
+
+ const info1 = GetInfo.getInfo('lvce-webview://view-1')
+ const info2 = GetInfo.getInfo('lvce-webview://view-2')
+
+ expect(info1.webViewId).toBe(webViewId1)
+ expect(info2.webViewId).toBe(webViewId2)
+})