#548 #508 Restart numbered lists

This commit is contained in:
Dolan
2021-03-12 03:58:05 +00:00
parent 9864cdea16
commit 0b88cb0ca5
20 changed files with 430 additions and 163 deletions

View File

@ -1,7 +1,8 @@
// tslint:disable:object-literal-key-quotes
import { expect } from "chai";
import { stub } from "sinon";
import { SinonStub, stub } from "sinon";
import * as convenienceFunctions from "convenience-functions";
import { Formatter } from "export/formatter";
import { File } from "../file";
@ -9,6 +10,14 @@ import { Paragraph } from "../paragraph";
import { Media } from "./media";
describe("Media", () => {
before(() => {
stub(convenienceFunctions, "uniqueId").callsFake(() => "test");
});
after(() => {
(convenienceFunctions.uniqueId as SinonStub).restore();
});
describe("#addImage", () => {
it("should add image", () => {
const file = new File();
@ -23,7 +32,6 @@ describe("Media", () => {
it("should ensure the correct relationship id is used when adding image", () => {
// tslint:disable-next-line:no-any
stub(Media as any, "generateId").callsFake(() => "testId");
const file = new File();
const image1 = Media.addImage(file, "test");
@ -33,7 +41,7 @@ describe("Media", () => {
expect(graphicData["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"]).to.deep.equal({
_attr: {
"r:embed": `rId{testId.png}`,
"r:embed": `rId{test.png}`,
cstate: "none",
},
});
@ -45,7 +53,7 @@ describe("Media", () => {
expect(graphicData2["a:graphic"][1]["a:graphicData"][1]["pic:pic"][2]["pic:blipFill"][0]["a:blip"]).to.deep.equal({
_attr: {
"r:embed": `rId{testId.png}`,
"r:embed": `rId{test.png}`,
cstate: "none",
},
});
@ -54,9 +62,6 @@ describe("Media", () => {
describe("#addMedia", () => {
it("should add media", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const image = new Media().addMedia("");
expect(image.fileName).to.equal("test.png");
expect(image.dimensions).to.deep.equal({
@ -74,8 +79,6 @@ describe("Media", () => {
it("should return UInt8Array if atob is present", () => {
// tslint:disable-next-line
((process as any).atob as any) = () => "atob result";
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const image = new Media().addMedia("");
expect(image.stream).to.be.an.instanceof(Uint8Array);
@ -84,8 +87,6 @@ describe("Media", () => {
it("should use data as is if its not a string", () => {
// tslint:disable-next-line
((process as any).atob as any) = () => "atob result";
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const image = new Media().addMedia(new Buffer(""));
expect(image.stream).to.be.an.instanceof(Uint8Array);
@ -94,9 +95,6 @@ describe("Media", () => {
describe("#getMedia", () => {
it("should get media", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const media = new Media();
media.addMedia("");
@ -124,9 +122,6 @@ describe("Media", () => {
describe("#Array", () => {
it("Get images as array", () => {
// tslint:disable-next-line:no-any
(Media as any).generateId = () => "test";
const media = new Media();
media.addMedia("");

View File

@ -1,3 +1,5 @@
import { uniqueId } from "convenience-functions";
import { IDrawingOptions } from "../drawing";
import { File } from "../file";
import { PictureRun } from "../paragraph";
@ -17,11 +19,6 @@ export class Media {
return new PictureRun(mediaData, drawingOptions);
}
private static generateId(): string {
// https://gist.github.com/6174/6062387
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
private readonly map: Map<string, IMediaData>;
constructor() {
@ -39,7 +36,7 @@ export class Media {
}
public addMedia(buffer: Buffer | string | Uint8Array | ArrayBuffer, width: number = 100, height: number = 100): IMediaData {
const key = `${Media.generateId()}.png`;
const key = `${uniqueId()}.png`;
return this.createMedia(
key,