Skip to content

Commit

Permalink
feature: add setInfo tests (#254)
Browse files Browse the repository at this point in the history
* feature: add setInfo tests

* test

* lint
  • Loading branch information
levivilet authored Dec 27, 2024
1 parent 0e16c40 commit 224daec
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/preview-process/test/SetInfo.test.ts
Original file line number Diff line number Diff line change
@@ -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 = '<h1>Test Content</h1>'

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 = '<h1>Test Content</h1>'

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 = '<h1>Test Content</h1>'

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)
})

0 comments on commit 224daec

Please sign in to comment.