From 04ea2b2dc983e18005fadf9fa8f054c3619a83fa Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 3 Jan 2019 02:11:04 +0000 Subject: [PATCH] Add footer tests and improve table documentation --- docs/usage/tables.md | 24 +++++++++++++----------- src/file/footer-wrapper.spec.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/file/footer-wrapper.spec.ts diff --git a/docs/usage/tables.md b/docs/usage/tables.md index 895f3b8851..a129023217 100644 --- a/docs/usage/tables.md +++ b/docs/usage/tables.md @@ -2,15 +2,15 @@ You can create tables with `docx`. More information can be found [here](http://officeopenxml.com/WPtable.php). -## How to +## Create Table -To create a table, simply use the `createTable` method on a `document`. +To create a table, simply use the `createTable()` method on a `document`. ```ts const table = doc.createTable([NUMBER OF ROWS], [NUMBER OF COLUMNS]); ``` -Alternatively, you can create a table object directly, and then add it in the document +Alternatively, you can create a table object directly, and then add it in the `document` ```ts const table = new Table(4, 4); @@ -36,10 +36,20 @@ The above section created a table with cells. To access the cell, use the `getCe const cell = table.getCell([ROW INDEX], [COLUMN INDEX]); ``` +For example: + ```ts const cell = table.getCell(0, 2); ``` +### Add paragraph to a cell + +Once you have got the cell, you can add data to it with the `addParagraph` method. + +```ts +cell.addParagraph(new Paragraph("Hello")); +``` + ## Borders BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`. @@ -107,14 +117,6 @@ To get a row, use the `getRow` method on a `table`. There are a handful of metho table.getRow([ROW INDEX]); ``` -### Add paragraph to a cell - -Once you have got the cell, you can add data to it with the `addParagraph` method. - -```ts -cell.addParagraph(new Paragraph("Hello")); -``` - ## Merge cells together ### Merging on a row diff --git a/src/file/footer-wrapper.spec.ts b/src/file/footer-wrapper.spec.ts new file mode 100644 index 0000000000..0379d40d60 --- /dev/null +++ b/src/file/footer-wrapper.spec.ts @@ -0,0 +1,29 @@ +import { expect } from "chai"; +import * as sinon from "sinon"; + +import { FooterWrapper } from "./footer-wrapper"; +import { Media } from "./media"; +import { Paragraph } from "./paragraph"; +import { Table } from "./table"; + +describe("FooterWrapper", () => { + describe("#addParagraph", () => { + it("should call the underlying footer's addParagraph", () => { + const file = new FooterWrapper(new Media(), 1); + const spy = sinon.spy(file.Footer, "addParagraph"); + file.addParagraph(new Paragraph()); + + expect(spy.called).to.equal(true); + }); + }); + + describe("#addTable", () => { + it("should call the underlying footer's addParagraph", () => { + const file = new FooterWrapper(new Media(), 1); + const spy = sinon.spy(file.Footer, "addTable"); + file.addTable(new Table(1, 1)); + + expect(spy.called).to.equal(true); + }); + }); +});