Skip to content

Commit 594dc21

Browse files
authored
Merge pull request #190 from livingdocsIO/test-refactorings
Refactor Tests and update test and example dependencies
2 parents 9fa14a3 + a33770f commit 594dc21

21 files changed

+917
-591
lines changed

package-lock.json

Lines changed: 402 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@
1818
"css-loader": "^0.25.0",
1919
"eslint": "^5.2.0",
2020
"eslint-config-standard": "^11.0.0",
21-
"eslint-plugin-import": "^2.19.1",
21+
"eslint-plugin-import": "^2.22.1",
2222
"eslint-plugin-node": "^7.0.1",
2323
"eslint-plugin-promise": "^3.8.0",
24-
"eslint-plugin-react": "^7.17.0",
24+
"eslint-plugin-react": "^7.21.5",
2525
"eslint-plugin-standard": "^3.1.0",
2626
"font-awesome": "^4.6.1",
2727
"gh-pages": "^0.11.0",
2828
"jasmine-core": "^2.99.1",
29-
"jquery": "^3.4.1",
29+
"jquery": "^3.5.1",
3030
"karma": "^1.7.1",
3131
"karma-chrome-launcher": "^2.0.0",
3232
"karma-coverage": "^1.0.0",
3333
"karma-firefox-launcher": "^1.3.0",
3434
"karma-jasmine": "^1.0.2",
3535
"karma-safari-launcher": "^1.0.0",
36-
"karma-sourcemap-loader": "^0.3.7",
36+
"karma-sourcemap-loader": "^0.3.8",
3737
"karma-webpack": "^1.8.1",
3838
"lodash.clonedeep": "^4.5.0",
3939
"normalize.css": "^8.0.1",
4040
"open-browser-webpack-plugin": "0.0.5",
41-
"prismjs": "^1.4.1",
42-
"react": "^15.3.2",
41+
"prismjs": "^1.22.0",
42+
"react": "^15.7.0",
4343
"react-addons-css-transition-group": "^15.3.2",
44-
"react-dom": "^15.3.2",
45-
"rimraf": "^3.0.0",
44+
"react-dom": "^15.7.0",
45+
"rimraf": "^3.0.2",
4646
"sinon": "^7.4.1",
47-
"style-loader": "^1.0.1",
47+
"style-loader": "^1.3.0",
4848
"url-loader": "^2.1.0",
4949
"webpack": "^1.13.0",
5050
"webpack-dev-server": "^1.14.1"

spec/api.spec.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,47 @@ import $ from 'jquery'
22

33
import Editable from '../src/core'
44

5-
describe('Editable', () => {
5+
describe('Editable', function () {
66
let editable, $div
77

8-
afterEach(() => {
8+
afterEach(function () {
99
if (editable) {
1010
editable.off()
1111
editable = undefined
1212
}
1313
})
1414

15-
describe('global variable', () => {
16-
it('is not defined', () => {
15+
describe('global variable', function () {
16+
17+
it('is not defined', function () {
1718
expect(window.Editable).toBeUndefined()
1819
})
1920

20-
it('creates a new Editable instance', () => {
21+
it('creates a new Editable instance', function () {
2122
editable = new Editable()
2223
expect(editable.on).toBeDefined()
2324
})
2425

2526
// Test no variables are leaking into global namespace
26-
it('does not define dispatcher globally', () => {
27+
it('does not define dispatcher globally', function () {
2728
expect(window.dispatcher).not.toBeDefined()
2829
})
2930
})
3031

31-
describe('with an element added', () => {
32-
beforeEach(() => {
32+
describe('with an element added', function () {
33+
34+
beforeEach(function () {
3335
$div = $('<div>').appendTo(document.body)
3436
editable = new Editable()
3537
editable.add($div)
3638
})
3739

38-
afterEach(() => {
40+
afterEach(function () {
3941
$div.remove()
4042
})
4143

42-
describe('getContent()', () => {
43-
it('getContent() returns its content', () => {
44+
describe('getContent()', function () {
45+
it('getContent() returns its content', function () {
4446
$div.html('a')
4547
const content = editable.getContent($div[0])
4648

@@ -49,65 +51,68 @@ describe('Editable', () => {
4951
})
5052
})
5153

52-
describe('appendTo()', () => {
53-
it('appends a document fragment', () => {
54+
describe('appendTo()', function () {
55+
56+
it('appends a document fragment', function () {
5457
$div.html('a')
5558
const frag = document.createDocumentFragment()
5659
frag.appendChild(document.createTextNode('b'))
5760
editable.appendTo($div[0], frag)
5861
expect($div[0].innerHTML).toEqual('ab')
5962
})
6063

61-
it('appends text from a string', () => {
64+
it('appends text from a string', function () {
6265
$div.html('a')
6366
editable.appendTo($div[0], 'b')
6467
expect($div[0].innerHTML).toEqual('ab')
6568
})
6669

67-
it('appends html from a string', () => {
70+
it('appends html from a string', function () {
6871
$div.html('a')
6972
editable.appendTo($div[0], '<span>b</span>c')
7073
expect($div[0].innerHTML).toEqual('a<span>b</span>c')
7174
})
7275

73-
it('returns a curosr a the right position', () => {
76+
it('returns a curosr a the right position', function () {
7477
$div.html('a')
7578
const cursor = editable.appendTo($div[0], 'b')
7679
expect(cursor.beforeHtml()).toEqual('a')
7780
expect(cursor.afterHtml()).toEqual('b')
7881
})
7982
})
8083

81-
describe('prependTo()', () => {
82-
it('prepends a document fragment', () => {
84+
describe('prependTo()', function () {
85+
86+
it('prepends a document fragment', function () {
8387
const frag = document.createDocumentFragment()
8488
frag.appendChild(document.createTextNode('b'))
8589
$div.html('a')
8690
editable.prependTo($div[0], frag)
8791
expect($div[0].innerHTML).toEqual('ba')
8892
})
8993

90-
it('prepends text from a string', () => {
94+
it('prepends text from a string', function () {
9195
$div.html('a')
9296
editable.prependTo($div[0], 'b')
9397
expect($div[0].innerHTML).toEqual('ba')
9498
})
9599

96-
it('prepends html from a string', () => {
100+
it('prepends html from a string', function () {
97101
$div.html('A sentence.')
98102
editable.prependTo($div[0], '<span>So</span> be it. ')
99103
expect($div[0].innerHTML).toEqual('<span>So</span> be it. A sentence.')
100104
})
101105

102-
it('returns a curosr a the right position', () => {
106+
it('returns a curosr a the right position', function () {
103107
$div.html('a')
104108
const cursor = editable.prependTo($div[0], 'b')
105109
expect(cursor.beforeHtml()).toEqual('b')
106110
expect(cursor.afterHtml()).toEqual('a')
107111
})
108112
})
109113

110-
describe('change event', () => {
114+
describe('change event', function () {
115+
111116
it('gets triggered after format change', (done) => {
112117
editable.change((element) => {
113118
expect(element).toEqual($div[0])

spec/clipboard.spec.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { parseContent, updateConfig } from '../src/clipboard'
22
import cloneDeep from 'lodash.clonedeep'
33
import * as config from '../src/config'
44

5-
describe('Clipboard', () => {
6-
describe('parseContent()', () => {
5+
describe('Clipboard', function () {
76

8-
afterEach(() => {
7+
describe('parseContent()', function () {
8+
9+
afterEach(function () {
910
updateConfig(config)
1011
})
1112

@@ -22,23 +23,23 @@ describe('Clipboard', () => {
2223
// Copy Elements
2324
// -------------
2425

25-
it('gets a plain text', () => {
26+
it('gets a plain text', function () {
2627
expect(extractSingleBlock('a')).toEqual('a')
2728
})
2829

29-
it('trims text', () => {
30+
it('trims text', function () {
3031
expect(extractSingleBlock(' a ')).toEqual('a')
3132
})
3233

33-
it('keeps a <a> element with an href attribute with an absolute link', () => {
34+
it('keeps a <a> element with an href attribute with an absolute link', function () {
3435
expect(extractSingleBlock('<a href="http://link.com">a</a>')).toEqual('<a href="http://link.com">a</a>')
3536
})
3637

37-
it('keeps a <a> element with an href attribute with an relative link', () => {
38+
it('keeps a <a> element with an href attribute with an relative link', function () {
3839
expect(extractSingleBlock('<a href="/link/1337">a</a>')).toEqual('<a href="/link/1337">a</a>')
3940
})
4041

41-
it('keeps a <a> element with an a list of whitelisted-attributes', () => {
42+
it('keeps a <a> element with an a list of whitelisted-attributes', function () {
4243
const updatedConfig = cloneDeep(config)
4344
updatedConfig.pastedHtmlRules.allowedElements = { a: { href: true, rel: true, target: true } }
4445

@@ -50,7 +51,7 @@ describe('Clipboard', () => {
5051
).toEqual('<a target="_blank" rel="nofollow" href="/link/1337">a</a>')
5152
})
5253

53-
it('removes attributes that arent whitelisted for an <a> element ', () => {
54+
it('removes attributes that arent whitelisted for an <a> element ', function () {
5455
const updatedConfig = cloneDeep(config)
5556
updatedConfig.pastedHtmlRules.allowedElements = { a: { href: true } }
5657
updateConfig(updatedConfig)
@@ -61,28 +62,28 @@ describe('Clipboard', () => {
6162
).toEqual('<a href="/link/1337">a</a>')
6263
})
6364

64-
it('keeps a <strong> element', () => {
65+
it('keeps a <strong> element', function () {
6566
expect(extractSingleBlock('<strong>a</strong>')).toEqual('<strong>a</strong>')
6667
})
6768

68-
it('keeps an <em> element', () => {
69+
it('keeps an <em> element', function () {
6970
expect(extractSingleBlock('<em>a</em>')).toEqual('<em>a</em>')
7071
})
7172

72-
it('keeps a <br> element', () => {
73+
it('keeps a <br> element', function () {
7374
expect(extractSingleBlock('a<br>b')).toEqual('a<br>b')
7475
})
7576

7677
// Split Blocks
7778
// ------------
7879

79-
it('creates two blocks from two paragraphs', () => {
80+
it('creates two blocks from two paragraphs', function () {
8081
const blocks = extract('<p>a</p><p>b</p>')
8182
expect(blocks[0]).toEqual('a')
8283
expect(blocks[1]).toEqual('b')
8384
})
8485

85-
it('creates two blocks from an <h1> followed by an <h2>', () => {
86+
it('creates two blocks from an <h1> followed by an <h2>', function () {
8687
const blocks = extract('<h1>a</h1><h2>b</h2>')
8788
expect(blocks[0]).toEqual('a')
8889
expect(blocks[1]).toEqual('b')
@@ -91,74 +92,74 @@ describe('Clipboard', () => {
9192
// Clean Whitespace
9293
// ----------------
9394

94-
var checkWhitespace = function (a, b) {
95+
function checkWhitespace (a, b) {
9596
expect(escape(extractSingleBlock(a))).toEqual(escape(b))
9697
}
9798

98-
it('replaces a single &nbsp; character', () => {
99+
it('replaces a single &nbsp; character', function () {
99100
checkWhitespace('a&nbsp;b', 'a b')
100101
})
101102

102-
it('replaces a series of &nbsp; with alternating whitespace and &nbsp;', () => {
103+
it('replaces a series of &nbsp; with alternating whitespace and &nbsp;', function () {
103104
checkWhitespace('a&nbsp;&nbsp;&nbsp;&nbsp;b', 'a \u00A0 \u00A0b')
104105
})
105106

106-
it('replaces a single &nbsp; character before a <span>', () => {
107+
it('replaces a single &nbsp; character before a <span>', function () {
107108
checkWhitespace('a&nbsp;<span>b</span>', 'a b')
108109
})
109110

110-
it('collapses multiple whitespaces', () => {
111+
it('collapses multiple whitespaces', function () {
111112
checkWhitespace('A B C D', 'A B C D')
112113
})
113114

114-
it('removes newlines', () => {
115+
it('removes newlines', function () {
115116
checkWhitespace('A\nB \n C', 'A B C')
116117
})
117118

118119
// Remove Elements
119120
// ---------------
120121

121-
it('removes a <span> element', () => {
122+
it('removes a <span> element', function () {
122123
expect(extractSingleBlock('<span>a</span>')).toEqual('a')
123124
})
124125

125-
it('removes an <a> element without an href attribute', () => {
126+
it('removes an <a> element without an href attribute', function () {
126127
expect(extractSingleBlock('<a>a</a>')).toEqual('a')
127128
})
128129

129130

130-
it('removes an <a> element with an empty href attribute', () => {
131+
it('removes an <a> element with an empty href attribute', function () {
131132
expect(extractSingleBlock('<a href>a</a>')).toEqual('a')
132133
})
133134

134-
it('removes an <a> element with an empty href attribute', () => {
135+
it('removes an <a> element with an empty href attribute', function () {
135136
expect(extractSingleBlock('<a href="">a</a>')).toEqual('a')
136137
})
137138

138-
it('removes an empty <strong> element', () => {
139+
it('removes an empty <strong> element', function () {
139140
expect(extractSingleBlock('<strong></strong>')).toEqual(undefined)
140141
})
141142

142-
it('removes a <strong> element with only whitespace', () => {
143+
it('removes a <strong> element with only whitespace', function () {
143144
expect(extractSingleBlock('<strong> </strong>')).toEqual(undefined)
144145
})
145146

146-
it('removes an empty <strong> element but keeps its whitespace', () => {
147+
it('removes an empty <strong> element but keeps its whitespace', function () {
147148
expect(extractSingleBlock('a<strong> </strong>b')).toEqual('a b')
148149
})
149150

150-
it('removes an attribute from an <em> element', () => {
151+
it('removes an attribute from an <em> element', function () {
151152
expect(extractSingleBlock('<em data-something="x">a</em>')).toEqual('<em>a</em>')
152153
})
153154

154155
// Transform Elements
155156
// ------------------
156157

157-
it('transforms a <b> into a <strong>', () => {
158+
it('transforms a <b> into a <strong>', function () {
158159
expect(extractSingleBlock('<b>a</b>')).toEqual('<strong>a</strong>')
159160
})
160161

161-
it('changes absolute links to relative ones with the keepInternalRelativeLinks flag set to true', () => {
162+
it('changes absolute links to relative ones with the keepInternalRelativeLinks flag set to true', function () {
162163
const updatedConfig = cloneDeep(config)
163164
updatedConfig.pastedHtmlRules.keepInternalRelativeLinks = true
164165
updateConfig(updatedConfig)
@@ -168,15 +169,15 @@ describe('Clipboard', () => {
168169
// Escape Content
169170
// --------------
170171

171-
it('escapes the string "<b>a</b>"', () => {
172+
it('escapes the string "<b>a</b>"', function () {
172173
// append the string to test as text node so the browser escapes it.
173174
const div = document.createElement('div')
174175
div.appendChild(document.createTextNode('<b>a</b>'))
175176

176177
expect(parseContent(div)[0]).toEqual('&lt;b&gt;a&lt;/b&gt;')
177178
})
178179

179-
it('removes blacklisted HTML elements (e.g. <style>)', () => {
180+
it('removes blacklisted HTML elements (e.g. <style>)', function () {
180181
const div = document.createElement('div')
181182
div.innerHTML = `
182183
<style type="text/css">

0 commit comments

Comments
 (0)