-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6641b3
commit cfb5d04
Showing
18 changed files
with
114 additions
and
23 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { GlobalRegistrator } from "@happy-dom/global-registrator"; | ||
|
||
GlobalRegistrator.register(); | ||
const bunFetch = fetch; | ||
GlobalRegistrator.register(); | ||
window.fetch = bunFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { test, mock } from "bun:test"; | ||
import { test, mock, expect } from "bun:test"; | ||
import { createCqlInput } from "./CqlInput"; | ||
import { CqlService } from "../CqlService"; | ||
import { TestCqlService } from "../services/TestCqlService"; | ||
import example from "./fixtures/responses/example.json"; | ||
import { findByTestId } from "@testing-library/dom"; | ||
|
||
mock.module("../CqlService", () => ({})); | ||
|
||
const testCqlService = new CqlService("http://localhost"); | ||
const testCqlService = new TestCqlService("http://localhost", { | ||
example, // Fix types | ||
}); | ||
const cqlInput = createCqlInput(testCqlService); | ||
customElements.define("cql-input", cqlInput); | ||
|
||
const mountComponent = () => { | ||
document.body.innerHTML = `<cql-input></cql-input>`; | ||
const container = document.createElement("div"); | ||
container.innerHTML = `<cql-input data-testid="cql-input"></cql-input>`; | ||
return container; | ||
}; | ||
|
||
test("renders a custom element", () => { | ||
mountComponent(); | ||
test("renders a custom element", async () => { | ||
const container = mountComponent(); | ||
await findByTestId(container, "cql-input"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
prosemirror-client/src/cqlInput/fixtures/responses/example.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"tokens": [ | ||
{ | ||
"type": "Token", | ||
"tokenType": "STRING", | ||
"lexeme": "example", | ||
"start": 0, | ||
"end": 6, | ||
"literal": "example" | ||
}, | ||
{ | ||
"type": "Token", | ||
"tokenType": "EOF", | ||
"lexeme": "", | ||
"start": 7, | ||
"end": 7, | ||
"literal": null | ||
} | ||
], | ||
"ast": { | ||
"type": "QueryList", | ||
"content": [ | ||
{ | ||
"type": "QueryBinary", | ||
"left": { | ||
"type": "QueryContent", | ||
"searchExpr": "example" | ||
}, | ||
"right": null | ||
} | ||
] | ||
}, | ||
"queryResult": "q=example", | ||
"suggestions": [], | ||
"error": null | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CqlResult, CqlServiceInterface } from "./CqlService"; | ||
|
||
export class TestCqlService implements CqlServiceInterface { | ||
private abortController: AbortController | undefined; | ||
|
||
/** | ||
* @param url | ||
* @param resultFixtures A map from query strings to results | ||
*/ | ||
constructor( | ||
private url: string, | ||
private resultFixtures: Record<string, CqlResult> | ||
) {} | ||
|
||
public setUrl(url: string) { | ||
this.url = url; | ||
} | ||
|
||
public async fetchResult(query: string) { | ||
const result = this.resultFixtures[query]; | ||
|
||
if (result) { | ||
return Promise.resolve(result); | ||
} | ||
|
||
return Promise.reject( | ||
new Error(`Fixture not found for query string ${query}`) | ||
); | ||
} | ||
|
||
public cancel() { | ||
this.abortController?.abort(); | ||
} | ||
} |