-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
121 lines (100 loc) · 4.65 KB
/
test.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*global jQuery, test, ok, equal*/
(function ($) {
"use strict";
test("signle line", function () {
var $fixture = $('#qunit-fixture');
$('<p style="width: 200px; font-size: 15px;">single line</p>')
.appendTo($fixture)
.splitLines();
ok(!$fixture.find('p').hasClass('has-lines'), 'Should not have line');
if ($.browser.msie && parseInt($.browser.version, 10) <= 8) {
equal($fixture.html(), '<P style="WIDTH: 200px; FONT-SIZE: 15px">single line</P>', "Should have not changed html");
} else {
equal($fixture.html(), '<p style="width: 200px; font-size: 15px;">single line</p>', "Should have not changed html");
}
});
test("double line", function () {
var $fixture = $('#qunit-fixture'),
innerHtml;
$([
'<p style="width: 200px; font-size: 15px;">',
'Slightly longer paragraph spanning_across 2 lines!',
'</p>'].join(''))
.appendTo($fixture)
.splitLines();
ok($fixture.find('p').hasClass('has-lines'), 'Should have lines');
equal($fixture.find('span.line').length, 2, 'Should have exacly 2 lines');
equal($fixture.find('p').text(),
'Slightly longer paragraph spanning_across 2 lines!',
'Should have the same text');
innerHtml = $fixture.find('p').html();
if ($.browser.msie && parseInt($.browser.version, 10) <= 8) {
equal($fixture.find('p').html().slice(0, 27), '<SPAN class=line>Slightly l', 'should have span without text before');
equal(innerHtml.slice(0, 27), '<SPAN class=line>Slightly l', 'there should be no text before first span');
equal(innerHtml.slice(-15), '2 lines!</SPAN>', 'there should be no text before last span');
} else {
equal($fixture.find('p').html().slice(0, 27), '<span class="line">Slightly', 'should have span without text before');
equal(innerHtml.slice(0, 27), '<span class="line">Slightly', 'there should be no text before first span');
equal(innerHtml.slice(-15), '2 lines!</span>', 'there should be no text before last span');
}
});
test("triple line", function () {
var $fixture = $('#qunit-fixture');
$([
'<p style="width: 200px; font-size: 15px;">',
'Even longer text spanning_across 3 lines! This is paragraph with no nested els',
'</p>'].join(''))
.appendTo($fixture)
.splitLines();
ok($fixture.find('p').hasClass('has-lines'), 'Should have lines');
equal($fixture.find('span.line').length, 3, 'Should have exacly 3 lines in: ' + $fixture.find('p').html());
equal($fixture.find('p').text(),
'Even longer text spanning_across 3 lines! This is paragraph with no nested els',
'Should have the same text');
});
test("double line with span in first line", function () {
var $fixture = $('#qunit-fixture');
$([
'<p style="width: 200px; font-size: 15px;">',
'Slightly <strong>longer</strong> paragraph spanning_across 2 lines!',
'</p>'].join(''))
.appendTo($fixture)
.splitLines();
ok($fixture.find('p').hasClass('has-lines'), 'Should have lines');
equal($fixture.find('p span.line').length, 2, 'Should have exacly 2 lines');
equal($fixture.find('p strong').text(), 'longer', 'Should keep markup');
equal($fixture.find('p').text(),
'Slightly longer paragraph spanning_across 2 lines!',
'Should have the same text');
});
test("double line with hidden span arround last word", function () {
var $fixture = $('#qunit-fixture');
$([
'<p style="width: 200px; font-size: 15px;">',
'Slightly longer paragraph spanning_across 2 lines! <span class="accessibility" style="display: inline-block; width: 1px; height: 1px; text-indent: -999px">[invisible multi-line text]</span>',
'</p>'].join(''))
.appendTo($fixture)
.splitLines();
ok($fixture.find('p').hasClass('has-lines'), 'Should have lines');
equal($fixture.find('p span.line').length, 2, 'Should have exacly 2 lines');
equal($fixture.find('p span.accessibility').text(), '[invisible multi-line text]', 'Should keep markup');
equal($fixture.find('p').text(),
'Slightly longer paragraph spanning_across 2 lines! [invisible multi-line text]',
'Should have the same text');
});
test("double line with span across lines", function () {
var $fixture = $('#qunit-fixture');
$([
'<p style="width: 200px; font-size: 15px;">',
'Slightly <strong>longer paragraph spanning_across</strong> 2 lines!',
'</p>'].join(''))
.appendTo($fixture)
.splitLines();
ok($fixture.find('p').hasClass('has-lines'), 'Should have lines');
equal($fixture.find('p span.line').length, 2, 'Should have exacly 2 lines');
equal($fixture.find('p strong').text(), 'longer paragraph spanning_across', 'Should keep markup');
equal($fixture.find('p').text(),
'Slightly longer paragraph spanning_across 2 lines!',
'Should have the same text');
});
}(jQuery));