Browse Source

fix: tests

charlie 1 year ago
parent
commit
dddd937b53
3 changed files with 12 additions and 14 deletions
  1. 0 1
      e2e-tests/logseq-api.spec.ts
  2. 7 3
      e2e-tests/plugin/index.js
  3. 5 10
      src/main/logseq/api.cljs

+ 0 - 1
e2e-tests/logseq-api.spec.ts

@@ -41,7 +41,6 @@ test('block related apis',
     // update
     const content1 = content + '+ update!'
     await callAPI('update_block', b1.uuid, content1)
-    await page.waitForTimeout(1000)
     b1 = await callAPI('get_block', b1.uuid)
 
     expect(b1.content).toBe(content1)

+ 7 - 3
e2e-tests/plugin/index.js

@@ -39,10 +39,14 @@ async function main () {
    }
   `)
 
-  // test log
-  setTimeout(() => {
+  let dbHookDid = false
+
+  // hook db change
+  logseq.DB.onChanged((e) => {
+    if (dbHookDid) return
     logPane(`DB: hook changed`)
-  }, 2000)
+    dbHookDid = true
+  })
 }
 
 // bootstrap

+ 5 - 10
src/main/logseq/api.cljs

@@ -667,18 +667,13 @@
   (fn [block-uuid ^js _opts]
     (let [repo            (state/get-current-repo)]
       (editor-handler/delete-block-aux!
-       {:block/uuid (sdk-utils/uuid-or-throw-error block-uuid) :repo repo} true)
-      nil)))
+       {:block/uuid (sdk-utils/uuid-or-throw-error block-uuid) :repo repo} true))))
 
 (def ^:export update_block
   (fn [block-uuid content ^js opts]
-    (let [repo       (state/get-current-repo)
-          edit-input (state/get-edit-input-id)
-          editing?   (and edit-input (string/ends-with? edit-input (str block-uuid)))]
-      (if editing?
-        (state/set-edit-content! edit-input content)
-        (editor-handler/save-block! repo (sdk-utils/uuid-or-throw-error block-uuid) content (bean/->clj opts)))
-      nil)))
+    (let [repo (state/get-current-repo)]
+      (editor-handler/save-block! repo
+        (sdk-utils/uuid-or-throw-error block-uuid) content (bean/->clj opts)))))
 
 (def ^:export move_block
   (fn [src-block-uuid target-block-uuid ^js opts]
@@ -694,7 +689,7 @@
                          nil)
           src-block    (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error src-block-uuid))
           target-block (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error target-block-uuid))]
-      (editor-dnd-handler/move-blocks nil [src-block] target-block nil move-to) nil)))
+      (editor-dnd-handler/move-blocks nil [src-block] target-block nil move-to))))
 
 (def ^:export get_block api-block/get_block)