Skip to content

Commit

Permalink
Start adding unit tests in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Feb 25, 2017
1 parent f11d841 commit 88f139a
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -32,6 +32,7 @@ media/*
*.sass-cache
.idea
.coverage
coverage
coverage_html_report/
npm-debug.log*

Expand Down
17 changes: 16 additions & 1 deletion package.json
Expand Up @@ -20,6 +20,14 @@
"react"
]
},
"jest": {
"moduleNameMapper": {
"\\.css$": "<rootDir>/wagtaildraftail/client/tests/styleMock.js"
},
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
},
"dependencies": {
"draft-js": "^0.10.0",
"draftail": "0.5.0",
Expand All @@ -28,17 +36,24 @@
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-jest": "^19.0.0",
"babel-loader": "^6.2.10",
"babel-preset-latest": "^6.22.0",
"babel-preset-react": "^6.22.0",
"css-loader": "^0.26.1",
"enzyme": "^2.7.1",
"enzyme-to-json": "^1.5.0",
"extract-text-webpack-plugin": "^2.0.0",
"jest": "^19.0.2",
"react-addons-test-utils": "^15.4.2",
"webpack": "^2.2.1"
},
"scripts": {
"start": "npm run build -s -- --watch",
"build": "webpack --config webpack.config.dev.js",
"dist": "webpack --config webpack.config.prod.js",
"test": "npm run dist"
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
}
}
19 changes: 19 additions & 0 deletions wagtaildraftail/client/entities/Document.test.js
@@ -0,0 +1,19 @@
import React from 'react';
import { Entity } from 'draft-js';
import Document from './Document';
import { shallow } from 'enzyme';

describe('Document', () => {
it('exists', () => {
expect(Document).toBeDefined();
});

it('renders', () => {
const entityKey = Entity.create('DOCUMENT', 'MUTABLE', { title: 'Test title' });
expect(shallow((
<Document entityKey={entityKey}>
<span>Test children</span>
</Document>
))).toMatchSnapshot();
})
});
28 changes: 28 additions & 0 deletions wagtaildraftail/client/entities/Link.test.js
@@ -0,0 +1,28 @@
import React from 'react';
import { Entity } from 'draft-js';
import Link from './Link';
import { shallow } from 'enzyme';

describe('Link', () => {
it('exists', () => {
expect(Link).toBeDefined();
});

it('renders', () => {
const entityKey = Entity.create('LINK', 'MUTABLE', { url: 'http://example.com/' });
expect(shallow((
<Link entityKey={entityKey}>
<span>Test children</span>
</Link>
))).toMatchSnapshot();
});

it('renders email', () => {
const entityKey = Entity.create('LINK', 'MUTABLE', { url: 'mailto:test@example.com' });
expect(shallow((
<Link entityKey={entityKey}>
<span>Test children</span>
</Link>
))).toMatchSnapshot();
});
});
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Document renders 1`] = `
<span
className="RichEditor-link"
data-tooltip="1"
title="Test title"
>
<Icon
className=""
name="icon-doc-full"
title={null}
/>
<span>
Test children
</span>
</span>
`;
33 changes: 33 additions & 0 deletions wagtaildraftail/client/entities/__snapshots__/Link.test.js.snap
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Link renders 1`] = `
<span
className="RichEditor-link"
data-tooltip="1"
>
<Icon
className=""
name="icon-link"
title={null}
/>
<span>
Test children
</span>
</span>
`;

exports[`Link renders email 1`] = `
<span
className="RichEditor-link"
data-tooltip="2"
>
<Icon
className=""
name="icon-mail"
title={null}
/>
<span>
Test children
</span>
</span>
`;
1 change: 1 addition & 0 deletions wagtaildraftail/client/tests/styleMock.js
@@ -0,0 +1 @@
module.exports = {};
11 changes: 11 additions & 0 deletions wagtaildraftail/client/wagtaildraftail.test.js
@@ -0,0 +1,11 @@
import initDraftailEditor from './wagtaildraftail';

describe('wagtaildraftail', () => {
it('exists', () => {
expect(initDraftailEditor).toBeInstanceOf(Function);
})

it('is exposed as global', () => {
expect(window.initDraftailEditor).toBe(initDraftailEditor);
})
});

0 comments on commit 88f139a

Please sign in to comment.