Declarative styles
This commit is contained in:
@ -1,15 +1,16 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { UnderlineType } from "file/paragraph/run/underline";
|
||||
import { ShadingType } from "file/table";
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
import { CharacterStyle } from "./character-style";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("CharacterStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to character and use the given style id", () => {
|
||||
const style = new CharacterStyle("myStyleId");
|
||||
const style = new CharacterStyle({ id: "myStyleId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -17,7 +18,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -29,7 +30,10 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the name of the style, if given", () => {
|
||||
const style = new CharacterStyle("myStyleId", "Style Name");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
name: "Style Name",
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -38,7 +42,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -52,7 +56,7 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("formatting methods: style attributes", () => {
|
||||
it("#basedOn", () => {
|
||||
const style = new CharacterStyle("myStyleId").basedOn("otherId");
|
||||
const style = new CharacterStyle({ id: "myStyleId", basedOn: "otherId" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -60,7 +64,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -75,7 +79,12 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("formatting methods: run properties", () => {
|
||||
it("#size", () => {
|
||||
const style = new CharacterStyle("myStyleId").size(24);
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
size: 24,
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -86,7 +95,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -99,7 +108,12 @@ describe("CharacterStyle", () => {
|
||||
|
||||
describe("#underline", () => {
|
||||
it("should set underline to 'single' if no arguments are given", () => {
|
||||
const style = new CharacterStyle("myStyleId").underline();
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -110,7 +124,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -122,7 +136,14 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style if given", () => {
|
||||
const style = new CharacterStyle("myStyleId").underline("double");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
type: UnderlineType.DOUBLE,
|
||||
},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -133,7 +154,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -145,7 +166,15 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("should set the style and color if given", () => {
|
||||
const style = new CharacterStyle("myStyleId").underline("double", "005599");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
underline: {
|
||||
type: UnderlineType.DOUBLE,
|
||||
color: "005599",
|
||||
},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -156,7 +185,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -169,7 +198,12 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#superScript", () => {
|
||||
const style = new CharacterStyle("myStyleId").superScript();
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
superScript: true,
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -188,7 +222,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -200,7 +234,12 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#color", () => {
|
||||
const style = new CharacterStyle("myStyleId").color("123456");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
color: "123456",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -211,7 +250,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -223,7 +262,12 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#bold", () => {
|
||||
const style = new CharacterStyle("myStyleId").bold();
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
bold: true,
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -234,7 +278,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -246,7 +290,12 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#italics", () => {
|
||||
const style = new CharacterStyle("myStyleId").italics();
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
italics: true,
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -257,7 +306,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -269,7 +318,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#link", () => {
|
||||
const style = new CharacterStyle("myStyleId").link("MyLink");
|
||||
const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -277,7 +326,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -290,7 +339,7 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#semiHidden", () => {
|
||||
const style = new CharacterStyle("myStyleId").semiHidden();
|
||||
const style = new CharacterStyle({ id: "myStyleId", semiHidden: true });
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -298,7 +347,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -309,7 +358,12 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#highlight", () => {
|
||||
const style = new CharacterStyle("myStyleId").highlight("005599");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
highlight: "005599",
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -320,7 +374,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -332,7 +386,16 @@ describe("CharacterStyle", () => {
|
||||
});
|
||||
|
||||
it("#shadow", () => {
|
||||
const style = new CharacterStyle("myStyleId").shadow("pct10", "00FFFF", "FF0000");
|
||||
const style = new CharacterStyle({
|
||||
id: "myStyleId",
|
||||
run: {
|
||||
shadow: {
|
||||
type: ShadingType.PERCENT_10,
|
||||
fill: "00FFFF",
|
||||
color: "FF0000",
|
||||
},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
@ -343,7 +406,7 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": "99",
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user