vcard4
Version:
An RFC 6350 compliant JavaScript library for generating and parsing version 4.0 vCards. Can also generate RFC 6351 compliant XML vCards and RFC 7095 compliant jCards. TypeScript type declarations are provided.
112 lines (108 loc) • 3.3 kB
JavaScript
import {
TextType,
TextListType,
SpecialValueType,
IntegerType,
} from "../../src/values/index.js";
import { PrefParameter } from "../../src/parameters/index.js";
import { NProperty } from "../../src/properties/index.js";
import { assert } from "chai";
describe("NProperty tests", () => {
it("Accepts valid input", () => {
assert.doesNotThrow(
() =>
new NProperty(
[],
new SpecialValueType("nproperty", [
new TextType("Stevenson"),
new TextType("John"),
new TextListType([new TextType("Phillip"), new TextType("Paul")]),
new TextType("Dr."),
new TextListType([
new TextType("Jr."),
new TextType("M.D."),
new TextType("A.C.P."),
]),
])
)
);
});
it("Rejects invalid input", () => {
assert.throws(() => new NProperty([], new TextType("Bond;James")));
assert.throws(
() =>
new NProperty(
[new PrefParameter(new IntegerType(1))],
new TextType("James Bond")
)
);
assert.throws(() => new NProperty());
assert.throws(() => new NProperty(1));
assert.throws(() => new NProperty({}));
assert.throws(() => new NProperty("James Bond"));
});
it("Formats value properly", () => {
assert.strictEqual(
new NProperty(
[],
new SpecialValueType("nproperty", [
new TextType("Stevenson"),
new TextType("John"),
new TextListType([new TextType("Phillip"), new TextType("Paul")]),
new TextType("Dr."),
new TextListType([
new TextType("Jr."),
new TextType("M.D."),
new TextType("A.C.P."),
]),
])
).repr(),
"N:Stevenson;John;Phillip,Paul;Dr.;Jr.,M.D.,A.C.P."
);
assert.strictEqual(
new NProperty(
[],
new SpecialValueType("nproperty", [
new TextType("Stevenson"),
new TextType("John"),
new TextListType([new TextType("Phillip"), new TextType("Paul")]),
new TextType("Dr."),
new TextListType([
new TextType("Jr."),
new TextType("M.D."),
new TextType("A.C.P."),
]),
])
).reprXML(),
"<n><surname>Stevenson</surname><given>John</given><additional>Phillip</additional><additional>Paul</additional><prefix>Dr.</prefix><suffix>Jr.</suffix><suffix>M.D.</suffix><suffix>A.C.P.</suffix></n>"
);
assert.deepEqual(
new NProperty(
[],
new SpecialValueType("nproperty", [
new TextType("Stevenson"),
new TextType("John"),
new TextListType([new TextType("Phillip"), new TextType("Paul")]),
new TextType("Dr."),
new TextListType([
new TextType("Jr."),
new TextType("M.D."),
new TextType("A.C.P."),
]),
])
).reprJSON(),
[
"n",
{},
"text",
[
"Stevenson",
"John",
["Phillip", "Paul"],
"Dr.",
["Jr.", "M.D.", "A.C.P."],
],
]
);
});
});