1
1
import { jest } from "@jest/globals"
2
2
import { mockPlugin , mockApp } from "./test-helpers.js"
3
3
4
+ import plugin from "./plugin.js"
5
+
4
6
// --------------------------------------------------------------------------------------
5
7
// Note that some of these tests actually make calls to OpenAI. Normally tests would be mocked for
6
8
// a remote call, but for Bill's current purposes, it's pretty useful to be able to see what the real
@@ -12,28 +14,39 @@ describe("plugin", () => {
12
14
describe ( "with a mocked app" , ( ) => {
13
15
const app = mockApp ( ) ;
14
16
15
- it ( "should look up thesaurus entries from trivial input" , async ( ) => {
16
- const noteContent = `
17
- Author: Leo Tolstoy
18
- Title: War and Peace
19
- Date: 1869
20
- Book ID: 23
17
+ it ( "should evaluate the lookup expression" , async ( ) => {
18
+ const noteUUID = 123 ;
19
+ const readwiseID = 456 ;
20
+ const content = `
21
+ # Library Details
22
+ Last synced at: June 15, 2023 3:39 PM
23
+ Oldest update synced in: August 5, 2022
24
+ Next sync for content updated after: August 5, 2022
25
+ Readwise books imported into table: 18
26
+ Book count reported by Readwise: 25
21
27
22
- ### Yo mama so fat, she a multi-part download
23
- Highlighted at: January 3, 2021 12:00 AM
24
- Readwise URL: https://readwise.io/abc123
25
- ` ;
26
- const noteHandles = [ { name : "War and Peace by Tolstoy (R-ID #23)" , uuid : "abc123" } ] ;
27
- app . notes . filter = jest . fn ( ) . mockResolvedValue ( noteHandles )
28
- app . getNoteContent = jest . fn ( ) . mockResolvedValue ( noteContent ) ;
29
- await plugin . noteOption [ "Sync Readwise" ] ( app , "abc123" ) ;
30
- } ) ;
28
+ # ${ plugin . constants . dashboardBookListTitle }
29
+ ${ plugin . _tablePreambleContent ( ) }
30
+ |  | William Harding | books | [kindle](https://kindle.com/blah) | [5 highlights](https://amplenote.com/notes/abc333) | August 5, 2022 | [Readwise link](${ readwiseID } ) |
31
+ |  | William Harding | books | [kindle](https://kindle.com/blah) | [5 highlights](https://amplenote.com/notes/abc333) | August 5, 2022 | [Readwise link](999) |
32
+ `
33
+ const noteHandle = {
34
+ content : ( ) => content ,
35
+ name : plugin . constants . defaultDashboardNoteTitle ,
36
+ uuid : noteUUID ,
37
+ } ;
38
+ app . findNote = jest . fn ( ) . mockResolvedValue ( noteHandle ) ;
39
+ app . notes . find = jest . fn ( ) . mockResolvedValue ( noteHandle ) ;
40
+ app . getNoteContent = jest . fn ( ) . mockResolvedValue ( content ) ;
41
+ plugin . _readwiseMakeRequest = jest . fn ( ) . mockResolvedValue ( { count : 0 } ) ;
42
+ async function * getBook ( ) {
43
+ yield * ( { something : "for sure" } )
44
+ }
45
+ plugin . _readwiseFetchBooks = getBook . bind ( plugin ) ;
46
+ plugin . _testEnvironment = true ;
31
47
32
- it ( "should evaluate the lookup expression" , async ( ) => {
33
- app . notes . find . mockReturnValue ( {
34
- content : ( ) => `To be, or not to be, that is the {${ plugin . constants . pluginName } : lookup}.`
35
- } ) ;
36
- const result = await plugin . insertText . lookup ( app ) ;
48
+ app . notes . find . mockReturnValue ( { content : ( ) => content } ) ;
49
+ const result = await plugin . noteOption [ "Sync all" ] ( app , noteUUID ) ;
37
50
expect ( result ) . toBe ( "question." ) ;
38
51
} ) ;
39
52
} ) ;
0 commit comments