forked from yabwe/medium-editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplaceholder.spec.js
79 lines (66 loc) · 3.38 KB
/
placeholder.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*global MediumEditor, describe, it, expect, spyOn,
afterEach, beforeEach, selectElementContents,
jasmine, fireEvent, tearDown*/
describe('Placeholder TestCase', function () {
'use strict';
beforeEach(function () {
this.el = document.createElement('div');
this.el.className = 'editor';
this.el.innerHTML = '';
document.body.appendChild(this.el);
});
afterEach(function () {
tearDown(this.el);
});
it('should set placeholder for empty elements', function () {
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).toContain('medium-editor-placeholder');
});
it('should not set a placeholder for elements with text content', function () {
this.el.innerHTML = 'some text';
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder');
});
it('should not set a placeholder for elements with images only', function () {
this.el.innerHTML = '<img src="foo.jpg">';
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder');
});
it('should set placeholder for elements with empty children', function () {
this.el.innerHTML = '<p><br></p><div class="empty"></div>';
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).toContain('medium-editor-placeholder');
});
it('should remove the placeholder on keypress', function () {
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).toContain('medium-editor-placeholder');
fireEvent(editor.elements[0], 'keypress');
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder');
});
it('should add a placeholder to empty elements on blur', function () {
this.el.innerHTML = 'some text';
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder');
editor.elements[0].innerHTML = '';
fireEvent(editor.elements[0], 'blur');
expect(editor.elements[0].className).toContain('medium-editor-placeholder');
});
it('should not add a placeholder to elements with text on blur', function () {
var editor = new MediumEditor('.editor');
expect(editor.elements[0].className).toContain('medium-editor-placeholder');
editor.elements[0].innerHTML = 'some text';
fireEvent(editor.elements[0], 'blur');
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder');
});
it('should add the default placeholder text when data-placeholder is not present', function () {
var editor = new MediumEditor('.editor'),
placeholder = window.getComputedStyle(editor.elements[0], ':after').getPropertyValue('content');
expect(placeholder).toEqual("'" + editor.options.placeholder + "'");
});
it('should use the data-placeholder when it is present', function () {
this.el.setAttribute('data-placeholder', 'Custom placeholder');
var editor = new MediumEditor('.editor'),
placeholder = window.getComputedStyle(editor.elements[0], ':after').getPropertyValue('content');
expect(placeholder).toEqual("'Custom placeholder'");
});
});