1- import { render } from 'lit'
21import { beforeAll , beforeEach , describe , expect , it , vi } from 'vitest'
32
4- let renderHeader
3+ let sourcePane
54
65beforeAll ( async ( ) => {
7- class MockSourceEditorCard extends HTMLElement {
8- constructor ( ) {
9- super ( )
10- this . updateEditingState = vi . fn ( )
11- this . setReadOnly = vi . fn ( )
12- this . focusEditor = vi . fn ( )
13- }
14- }
15-
16- if ( ! globalThis . customElements . get ( 'source-pane-source-editor-card' ) ) {
17- globalThis . customElements . define ( 'source-pane-source-editor-card' , MockSourceEditorCard )
18- }
19-
20- const headerModule = await import ( '../src/Header.ts' )
21- renderHeader = headerModule . renderHeader
22-
6+ await import ( '../src/components/source-provider/SourceProvider.ts' )
237 await import ( '../src/components/header/SourceHeader.ts' )
8+ sourcePane = ( await import ( '../src/sourcePane.ts' ) ) . default
9+
2410} )
2511
26- function renderHeaderIntoDocument ( sourcePaneState ) {
12+ function renderPaneIntoDocument ( ) {
2713 const container = document . createElement ( 'div' )
2814 document . body . appendChild ( container )
2915
3016 const store = { findTypeURIs : vi . fn ( ( ) => ( { } ) ) }
3117 const subject = { uri : 'https://janedoe.example/test.ttl' }
32- render ( renderHeader ( store , subject , sourcePaneState ) , container )
33-
34- return { container, subject, store }
18+ const context = {
19+ dom : document ,
20+ session : { store }
21+ }
22+ const rendered = sourcePane . render ( subject , context )
23+ container . appendChild ( rendered )
24+ return { container, subject, store, rendered }
3525}
3626
3727describe ( 'source-pane' , ( ) => {
@@ -40,67 +30,12 @@ describe('source-pane', () => {
4030 vi . clearAllMocks ( )
4131 } )
4232
43- it ( 'renders the header edit control' , async ( ) => {
44- const sourcePaneState = {
45- broken : false ,
46- editing : false ,
47- readonly : false ,
48- allowed : undefined ,
49- contentType : undefined ,
50- eTag : undefined
51- }
52-
53- const { container } = renderHeaderIntoDocument ( sourcePaneState )
54- await Promise . resolve ( )
55-
56- expect ( container . querySelector ( 'header.sourcePaneHeader' ) ) . not . toBeNull ( )
57- expect ( container . querySelector ( '.sourcePaneEditButton' ) ) . not . toBeNull ( )
58- } )
59-
60- it ( 'activates the editor when edit is clicked' , async ( ) => {
61- const sourcePaneState = {
62- broken : false ,
63- editing : false ,
64- readonly : false ,
65- allowed : undefined ,
66- contentType : undefined ,
67- eTag : undefined
68- }
69-
70- const { container } = renderHeaderIntoDocument ( sourcePaneState )
71- const editorCard = document . createElement ( 'source-pane-source-editor-card' )
72- document . body . appendChild ( editorCard )
73-
33+ it ( 'renders the source provider wrapper' , async ( ) => {
34+ const { rendered } = renderPaneIntoDocument ( )
7435 await Promise . resolve ( )
75- container . querySelector ( '.sourcePaneEditButton' ) . click ( )
76-
77- expect ( editorCard . updateEditingState ) . toHaveBeenCalledWith ( true )
78- expect ( editorCard . setReadOnly ) . toHaveBeenCalledWith ( false )
79- expect ( editorCard . focusEditor ) . toHaveBeenCalled ( )
80- } )
81-
82- it ( 'opens the editor card from the migrated header even without setEditing' , async ( ) => {
83- const header = document . createElement ( 'source-pane-source-header' )
84- Object . defineProperty ( header , 'sourceContext' , {
85- value : {
86- sourcePaneState : {
87- broken : false
88- }
89- } ,
90- writable : true
91- } )
92-
93- const editorCard = document . createElement ( 'source-pane-source-editor-card' )
94- document . body . appendChild ( header )
95- document . body . appendChild ( editorCard )
96-
97- await header . updateComplete
98- await Promise . resolve ( )
99-
100- header . shadowRoot . querySelectorAll ( 'solid-ui-button' ) [ 1 ] . click ( )
10136
102- expect ( editorCard . updateEditingState ) . toHaveBeenCalledWith ( true )
103- expect ( editorCard . setReadOnly ) . toHaveBeenCalledWith ( false )
104- expect ( editorCard . focusEditor ) . toHaveBeenCalled ( )
37+ expect ( rendered ) . not . toBeNull ( )
38+ expect ( rendered . className ) . toBe ( 'sourcePane' )
39+ expect ( rendered . getAttribute ( 'class' ) ) . toBe ( 'sourcePane' )
10540 } )
10641} )
0 commit comments