11import { h , render , rerender } from "preact" ;
22import { testBrowser } from "../tools/tester" ;
3+ import { NotebookPage , ProfilePage } from "./app" ;
34import { cellExecuteQueue } from "./components/cell" ;
45import { Notebook } from "./components/notebook" ;
56import * as db from "./db" ;
6- import * as nb from "./notebook_root" ;
77import { assert , assertEqual , createResolvable , delay } from "./util" ;
88
99const DOC_TITLE = "Anonymous Notebook" ;
1010
11- testBrowser ( async function notebook_NotebookRoot ( ) {
12- const mdb = db . enableMock ( ) ;
13- resetPage ( ) ;
14- const el = h ( nb . NotebookRoot , { } ) ;
15- render ( el , document . body ) ;
16- await flush ( ) ;
17- assertEqual ( mdb . counts , { queryLatest : 1 } ) ;
18- const c = document . body . getElementsByTagName ( "div" ) [ 0 ] ;
19- assertEqual ( c . className , "notebook" ) ;
20- } ) ;
21-
2211testBrowser ( async function notebook_Notebook ( ) {
2312 const mdb = db . enableMock ( ) ;
2413 await renderAnonNotebook ( ) ;
@@ -126,21 +115,21 @@ testBrowser(async function notebook_profile() {
126115 await renderProfile ( "non-existant" ) ;
127116 let avatars = document . querySelectorAll ( ".avatar" ) ;
128117 assert ( avatars . length === 0 ) ;
129- let notebooks = document . querySelectorAll ( ".most-recent ol li" ) ;
118+ let notebooks = document . querySelectorAll ( ".nb-listing ol li" ) ;
130119 assert ( notebooks . length === 0 ) ;
131120 assertEqual ( mdb . counts , { queryProfile : 1 } ) ;
132121
133122 // Try again with a real uid.
134123 await renderProfile ( db . defaultOwner . uid ) ;
135124 avatars = document . querySelectorAll ( ".avatar" ) ;
136125 assert ( avatars . length === 1 ) ;
137- notebooks = document . querySelectorAll ( ".most-recent ol li" ) ;
126+ notebooks = document . querySelectorAll ( ".nb-listing ol li" ) ;
138127 assert ( notebooks . length === 1 ) ;
139128 assertEqual ( mdb . counts , { queryProfile : 2 } ) ;
140129} ) ;
141130
142131testBrowser ( async function notebook_executeQueue ( ) {
143- const { notebookRef } = await renderAnonNotebook ( ) ;
132+ const notebookRef = await renderAnonNotebook ( ) ;
144133 // All the cells must be executed now.
145134 assertEqual ( cellExecuteQueue . length , 0 ) ;
146135 const cell1 = await notebookRef . insertCell ( 2 , "a = 0" ) ;
@@ -163,7 +152,7 @@ testBrowser(async function notebook_executeQueue() {
163152
164153testBrowser ( async function notebook_urlImport ( ) {
165154 db . enableMock ( ) ;
166- const { notebookRef } = await renderAnonNotebook ( ) ;
155+ const notebookRef = await renderAnonNotebook ( ) ;
167156 const testdataUrl = `${ location . origin } /repo/src/testdata` ;
168157
169158 const cell1 = await notebookRef . insertCell (
@@ -202,27 +191,32 @@ function resetPage() {
202191function renderProfile ( profileUid : string ) {
203192 const promise = createResolvable ( ) ;
204193 resetPage ( ) ;
205- const el = h ( nb . NotebookRoot , {
206- onReady : promise . resolve ,
207- profileUid
194+ const el = h ( ProfilePage , {
195+ matches : {
196+ userId : profileUid
197+ } ,
198+ onReady : promise . resolve
208199 } ) ;
209200 render ( el , document . body ) ;
210201 return promise ;
211202}
212203
213- async function renderAnonNotebook ( ) : Promise < nb . NotebookRoot > {
204+ async function renderAnonNotebook ( ) : Promise < Notebook > {
214205 const promise = createResolvable ( ) ;
215206 resetPage ( ) ;
216- let notebookRoot : nb . NotebookRoot ;
217- const el = h ( nb . NotebookRoot , {
218- nbId : "default" ,
207+ let notebookRoot ;
208+ const el = h ( NotebookPage , {
209+ matches : {
210+ nbId : "default"
211+ } ,
219212 onReady : promise . resolve ,
220- ref : n => ( notebookRoot = n )
213+ ref : ref => ( notebookRoot = ref )
221214 } ) ;
222215 render ( el , document . body ) ;
223216 await promise ;
224- await notebookRoot . notebookRef . isReady ;
225- return notebookRoot ;
217+ const notebookRef = notebookRoot . componentRef ;
218+ await notebookRef . isReady ;
219+ return notebookRef ;
226220}
227221
228222async function renderNotebook ( ) : Promise < Notebook > {
0 commit comments