archetecture security fix
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import React, { isValidElement } from 'react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.mock('@/components/layout/PublicHeader', () => ({ default: function MockPublicHeader() { return React.createElement('mock-header') } }))
|
||||
vi.mock('@/components/layout/PublicFooter', () => ({ default: function MockPublicFooter() { return React.createElement('mock-footer') } }))
|
||||
|
||||
import PublicShell from './PublicShell'
|
||||
|
||||
function childTypes(node: React.ReactElement): string[] {
|
||||
return React.Children.toArray(node.props.children).filter(isValidElement).map((child) => {
|
||||
const type = child.type as any
|
||||
if (typeof type === 'string') return type
|
||||
return type.displayName ?? type.name ?? 'anonymous'
|
||||
})
|
||||
}
|
||||
|
||||
describe('dashboard PublicShell', () => {
|
||||
it('wraps public pages with header, content, and footer by default', () => {
|
||||
const shell = PublicShell({ children: React.createElement('main', { id: 'content' }) })
|
||||
|
||||
expect(isValidElement(shell)).toBe(true)
|
||||
expect(childTypes(shell)).toEqual(['MockPublicHeader', 'div', 'MockPublicFooter'])
|
||||
})
|
||||
|
||||
it('omits chrome when embedded so partner surfaces do not get nested headers', () => {
|
||||
const shell = PublicShell({ embedded: true, children: React.createElement('main', { id: 'content' }) })
|
||||
|
||||
expect(childTypes(shell)).toEqual(['div'])
|
||||
const contentWrapper = React.Children.toArray(shell.props.children).find(isValidElement) as React.ReactElement
|
||||
expect(contentWrapper.props.children).toEqual(React.createElement('main', { id: 'content' }))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user