Skip to content

Commit

Permalink
🚨 increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewelsby committed Mar 12, 2020
1 parent 79db7bf commit 3b2c7dc
Show file tree
Hide file tree
Showing 10 changed files with 5,725 additions and 80 deletions.
28 changes: 28 additions & 0 deletions __tests__/Manifest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Manifest from '../src/Manifest';
describe('Manifest', () => {
let subject;
beforeEach(() => {
subject = new Manifest();
});
describe('.merge(zip, counter)', () => {
it.todo('merges the given zip file manifest into doc');
});

describe('.toXml(formatted)', () => {
it('returns XML ', () => {
jest.spyOn(subject, 'doc', 'get').mockReturnValue({ hello: 'world' });
expect(subject.toXml()).toMatchInlineSnapshot(`
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<hello>world</hello>
"
`);
expect(subject.toXml(false)).toMatchInlineSnapshot(`
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
<hello>world</hello>"
`);

jest.spyOn(subject, 'doc', 'get').mockReturnValue('');
expect(subject.toXml()).toMatchInlineSnapshot(`""`);
});
});
});
45 changes: 33 additions & 12 deletions __tests__/XMLFileBase.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
import XMLFileBase from '../src/XMLFileBase';
import fixture from './__fixtures__/content.json';
import fs from 'fs';
import path from 'path';

describe('XMLFileBase', () => {
describe('.namespaces', () => {
it.todo('extracts namespace key/pairs for the XML document');
let subject;
beforeEach(() => {
subject = new XMLFileBase();
});

describe('.data', () => {
it.todo('converts the XML to object notation');
describe('.namespaces', () => {
it('extracts namespace key/pairs for the XML document', () => {
subject.rootKey = 'office:document-content';
jest.spyOn(subject, 'data', 'get').mockReturnValue(fixture);
expect(subject.namespaces).toMatchSnapshot();
});
});

describe('.contentOriginal', () => {
it.todo('extracts the selected content keys from the data');
describe('.data', () => {
it('converts the XML to object notation', () => {
subject.xml = fs
.readFileSync(path.join(__dirname, '__fixtures__/content.xml'))
.toString();
let actual = subject.data;
expect(actual).toEqual(fixture);
});
});

describe('.content', () => {
it.todo('returns optimised content with pre-processors');
});

describe('.changeImagePaths', () => {
it.todo('replaces references of asset path with its updated location');
it('returns optimised content with pre-processors', () => {
jest.spyOn(subject, 'data', 'get').mockReturnValue(fixture);
expect(subject.content).toMatchSnapshot();
});
});

describe('.changeKeyReferences', () => {
it.todo('replaces references of styles with the updated reference');
it('replaces references of styles with the updated reference', () => {
let given = { 'hello:world': 'prefixme' };
jest.spyOn(subject, 'prefixKeys', 'get').mockReturnValue(['hello:world']);
subject.id = 0;
let actual = subject.changeKeyReferences(given);
expect(actual).toEqual({ 'hello:world': '0-prefixme' });
});
});
});
Loading

0 comments on commit 3b2c7dc

Please sign in to comment.