-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
4 changed files
with
59 additions
and
54 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,55 @@ | ||
import test from "ava"; | ||
import * as sinon from "sinon"; | ||
|
||
import { injectPairedShortcodes } from "../src"; | ||
import { createDocument } from "./__testutils__/createDocument"; | ||
|
||
test.afterEach.always(() => { | ||
sinon.restore(); | ||
}); | ||
import { linkResolver } from "./__testutils__/linkResolver"; | ||
|
||
import { link } from "../src"; | ||
|
||
test.serial("injects paired shorcodes", (t) => { | ||
const injector = sinon.spy(); | ||
const args = ["testSlots", { url: "/bar" }] as const; | ||
|
||
injectPairedShortcodes(injector); | ||
test("returns link field resolved anchor tag", (t) => { | ||
t.is( | ||
`<a href="https://google.com">${args[0]}</a>`, | ||
link()(...args, { | ||
link_type: "Web", | ||
url: "https://google.com", | ||
}), | ||
); | ||
}); | ||
|
||
t.true(injector.called); | ||
test("returns link field resolved blank anchor tag", (t) => { | ||
t.is( | ||
`<a href="https://google.com" target="_blank" rel="noopener noreferrer">${args[0]}</a>`, | ||
link()(...args, { | ||
link_type: "Web", | ||
url: "https://google.com", | ||
target: "_blank", | ||
}), | ||
); | ||
}); | ||
|
||
test.serial("injects paired shorcodes with namespace", (t) => { | ||
const namespace = "prismic"; | ||
test("returns document resolved anchor tag", (t) => { | ||
t.is( | ||
`<a href="/foo">${args[0]}</a>`, | ||
link()(...args, createDocument({ url: "/foo" })), | ||
); | ||
}); | ||
|
||
const injector = sinon.spy(); | ||
test("returns document resolved anchor tag using link resolver", (t) => { | ||
t.is( | ||
`<a href="/foo">${args[0]}</a>`, | ||
link(linkResolver)(...args, createDocument({ url: "/foo" })), | ||
); | ||
}); | ||
|
||
injectPairedShortcodes(injector, { shortcodesNamespace: namespace }); | ||
test("returns an empty anchor tag when link resolver is required but not provided", (t) => { | ||
t.is(`<a>${args[0]}</a>`, link()(...args, createDocument())); | ||
}); | ||
|
||
t.true(injector.args.every((args) => args[0].startsWith(namespace))); | ||
test("returns document resolved anchor tag for current page", (t) => { | ||
t.is( | ||
`<a href="/bar" aria-current="page">${args[0]}</a>`, | ||
link()(...args, createDocument({ url: "/bar" })), | ||
); | ||
}); |
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,51 +1,26 @@ | ||
import test from "ava"; | ||
import * as sinon from "sinon"; | ||
|
||
import { createDocument } from "./__testutils__/createDocument"; | ||
import { injectPairedShortcodes } from "../src"; | ||
|
||
import { linkResolver } from "./__testutils__/linkResolver"; | ||
test.afterEach.always(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
import { link } from "../src"; | ||
test.serial("injects paired shorcodes", (t) => { | ||
const injector = sinon.spy(); | ||
|
||
const args = ["testSlots", { url: "/bar" }] as const; | ||
injectPairedShortcodes(injector); | ||
|
||
test("returns link field resolved anchor tag", (t) => { | ||
t.is( | ||
`<a href="https://google.com">${args[0]}</a>`, | ||
link()(...args, { | ||
link_type: "Web", | ||
url: "https://google.com", | ||
}), | ||
); | ||
t.true(injector.called); | ||
}); | ||
|
||
test("returns link field resolved blank anchor tag", (t) => { | ||
t.is( | ||
`<a href="https://google.com" target="_blank" rel="noopener noreferrer">${args[0]}</a>`, | ||
link()(...args, { | ||
link_type: "Web", | ||
url: "https://google.com", | ||
target: "_blank", | ||
}), | ||
); | ||
}); | ||
test.serial("injects paired shorcodes with namespace", (t) => { | ||
const namespace = "prismic"; | ||
|
||
test("returns document resolved anchor tag", (t) => { | ||
t.is( | ||
`<a href="/foo">${args[0]}</a>`, | ||
link()(...args, createDocument({ url: "/foo" })), | ||
); | ||
}); | ||
const injector = sinon.spy(); | ||
|
||
test("returns document resolved anchor tag using link resolver", (t) => { | ||
t.is( | ||
`<a href="/foo">${args[0]}</a>`, | ||
link(linkResolver)(...args, createDocument({ url: "/foo" })), | ||
); | ||
}); | ||
injectPairedShortcodes(injector, { shortcodesNamespace: namespace }); | ||
|
||
test("returns document resolved anchor tag for current page", (t) => { | ||
t.is( | ||
`<a href="/bar" aria-current="page">${args[0]}</a>`, | ||
link()(...args, createDocument({ url: "/bar" })), | ||
); | ||
t.true(injector.args.every((args) => args[0].startsWith(namespace))); | ||
}); |