Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

previewCitationCluster => previewCluster #141

Merged
merged 5 commits into from
Dec 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wasm: test previewCitationCluster with cluster modes
  • Loading branch information
cormacrelf committed Dec 1, 2021
commit dac86e182b8f3396a773014997d518ace889cbac
57 changes: 40 additions & 17 deletions crates/wasm/js-tests/node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ let boldStyle = mkNoteStyle(
<text variable="URL" prefix=" " />
`,
);
let authorTitleStyle = mkInTextStyle(
`
<group delimiter=", ">
<names variable="author" />
<text variable="title" />
</group>
`,
``
);


describe("Driver", () => {

Expand Down Expand Up @@ -198,7 +208,7 @@ describe("previewCitationCluster", () => {
``,
);

function pccSetup(callback) {
function pccSetup(callback: (driver: Driver, ids: [string, string]) => void) {
withDriver({ style: ibidStyle }, driver => {
let one = "cluster-one";
let two = "cluster-two";
Expand Down Expand Up @@ -242,28 +252,41 @@ describe("previewCitationCluster", () => {
})

test("should error when supplying unsupported output format", () => {
pccSetup((driver, [one, two]) => {
let res = driver.previewCitationCluster(
{ cites: [{ id: "r1" }] }, [{}], "plaintext");
pccSetup((driver) => {
let res = driver.previewCitationCluster({ cites: [{ id: "r1" }] }, [{}], "plaintext");
expect(() => res.unwrap()).toThrow("Unknown output format \"plaintext\"");
})
})
});

test("should allow omitting the format argument", () => {
pccSetup((driver, [_, two]) => {
let res = driver.previewCitationCluster(
{ cites: [{ id: "r1" }] },
[{ note: 1 }, { id: two, note: 5 }]
).unwrap();
expect(res).toEqual("ONE");
})
});

test("should handle cluster modes", () => {
pccSetup((driver, [_, two]) => {
driver.setStyle(authorTitleStyle).unwrap();
driver.insertReference(
{ title: "ONE", id: "r1", type: "book", author: [{ family: "Smith" }] }
).unwrap();
let res = driver.previewCitationCluster(
{ cites: [{ id: "r1" }], mode: "Composite", infix: ", whose book" },
[{ note: 1 }, { id: two, note: 5 }]
).unwrap();
expect(res).toEqual("Smith, whose book ONE");
})
});

});

describe("AuthorOnly and friends", () => {
let style = mkInTextStyle(
`
<group delimiter=", ">
<names variable="author" />
<text variable="title" />
</group>
`,
``
);

function withSupp(callback) {
withDriver({ style }, driver => {
function withSupp(callback: (driver: Driver, ids: [string, string]) => void) {
withDriver({ style: authorTitleStyle }, driver => {
let one = "cluster-one";
let two = "cluster-two";
oneOneOne(driver, { title: "ONE", id: "r1", author: [{ family: "Smith" }] }, "cluster-one");
Expand Down