html-pipeline-task_list 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +91 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +45 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +4 -0
- data/Guardfile +27 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/Rakefile +16 -0
- data/app/assets/javascripts/task_list.js +107 -0
- data/app/assets/stylesheets/task_list.scss +20 -0
- data/html-pipeline-task_list.gemspec +37 -0
- data/lib/html/pipeline/task_list.rb +51 -0
- data/lib/html/pipeline/task_list/filter.rb +179 -0
- data/lib/html/pipeline/task_list/railtie.rb +30 -0
- data/lib/html/pipeline/task_list/summary.rb +34 -0
- data/lib/html/pipeline/task_list/version.rb +9 -0
- data/package-lock.json +455 -0
- data/package.json +36 -0
- data/test/behavior.html +109 -0
- data/test/dist/jquery-ujs.js +1 -0
- data/test/dist/jquery.js +1 -0
- data/test/dist/qunit.css +1 -0
- data/test/dist/qunit.js +1 -0
- data/test/dist/task_list.js +1 -0
- data/test/html/pipeline/task_list/filter_test.rb +197 -0
- data/test/html/pipeline/task_list/summary_test.rb +40 -0
- data/test/html/pipeline/task_list_test.rb +32 -0
- data/test/qunit.html +17 -0
- data/test/run-qunit.js +168 -0
- data/test/server.js +51 -0
- data/test/test_helper.rb +5 -0
- data/test/unit/events_test.js +106 -0
- data/test/unit/updates_test.js +476 -0
- metadata +253 -0
data/test/run-qunit.js
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
/* global phantom:false, require:false, console:false, window:false, QUnit:false */
|
2
|
+
|
3
|
+
(function () {
|
4
|
+
'use strict';
|
5
|
+
|
6
|
+
var url, page, timeout,
|
7
|
+
args = require('system').args;
|
8
|
+
|
9
|
+
// arg[0]: scriptName, args[1...]: arguments
|
10
|
+
if (args.length < 2) {
|
11
|
+
console.error('Usage:\n phantomjs [phantom arguments] runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds] [page-properties]');
|
12
|
+
exit(1);
|
13
|
+
}
|
14
|
+
|
15
|
+
url = args[1];
|
16
|
+
|
17
|
+
if (args[2] !== undefined) {
|
18
|
+
timeout = parseInt(args[2], 10);
|
19
|
+
}
|
20
|
+
|
21
|
+
page = require('webpage').create();
|
22
|
+
|
23
|
+
if (args[3] !== undefined) {
|
24
|
+
try {
|
25
|
+
var pageProperties = JSON.parse(args[3]);
|
26
|
+
|
27
|
+
if (pageProperties) {
|
28
|
+
for (var prop in pageProperties) {
|
29
|
+
if (pageProperties.hasOwnProperty(prop)) {
|
30
|
+
page[prop] = pageProperties[prop];
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
} catch (e) {
|
35
|
+
console.error('Error parsing "' + args[3] + '": ' + e);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
// Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`)
|
40
|
+
page.onConsoleMessage = function (msg) {
|
41
|
+
console.log(msg);
|
42
|
+
};
|
43
|
+
|
44
|
+
page.onInitialized = function () {
|
45
|
+
page.evaluate(addLogging);
|
46
|
+
};
|
47
|
+
|
48
|
+
page.onCallback = function (message) {
|
49
|
+
var result,
|
50
|
+
failed;
|
51
|
+
|
52
|
+
if (message) {
|
53
|
+
if (message.name === 'QUnit.done') {
|
54
|
+
result = message.data;
|
55
|
+
failed = !result || !result.total || result.failed;
|
56
|
+
|
57
|
+
if (!result.total) {
|
58
|
+
console.error('No tests were executed. Are you loading tests asynchronously?');
|
59
|
+
}
|
60
|
+
|
61
|
+
exit(failed ? 1 : 0);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
page.open(url, function (status) {
|
67
|
+
if (status !== 'success') {
|
68
|
+
console.error('Unable to access network: ' + status);
|
69
|
+
exit(1);
|
70
|
+
} else {
|
71
|
+
// Cannot do this verification with the 'DOMContentLoaded' handler because it
|
72
|
+
// will be too late to attach it if a page does not have any script tags.
|
73
|
+
var qunitMissing = page.evaluate(function () {
|
74
|
+
return (typeof QUnit === 'undefined' || !QUnit);
|
75
|
+
});
|
76
|
+
|
77
|
+
if (qunitMissing) {
|
78
|
+
console.error('The `QUnit` object is not present on this page.');
|
79
|
+
exit(1);
|
80
|
+
}
|
81
|
+
|
82
|
+
// Set a default timeout value if the user does not provide one
|
83
|
+
if (typeof timeout === 'undefined') {
|
84
|
+
timeout = 5;
|
85
|
+
}
|
86
|
+
|
87
|
+
// Set a timeout on the test running, otherwise tests with async problems will hang forever
|
88
|
+
setTimeout(function () {
|
89
|
+
console.error('The specified timeout of ' + timeout + ' seconds has expired. Aborting...');
|
90
|
+
exit(1);
|
91
|
+
}, timeout * 1000);
|
92
|
+
|
93
|
+
// Do nothing... the callback mechanism will handle everything!
|
94
|
+
}
|
95
|
+
});
|
96
|
+
|
97
|
+
function addLogging() {
|
98
|
+
window.document.addEventListener('DOMContentLoaded', function () {
|
99
|
+
var currentTestAssertions = [];
|
100
|
+
|
101
|
+
QUnit.log(function (details) {
|
102
|
+
var response;
|
103
|
+
|
104
|
+
// Ignore passing assertions
|
105
|
+
if (details.result) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
response = details.message || '';
|
110
|
+
|
111
|
+
if (typeof details.expected !== 'undefined') {
|
112
|
+
if (response) {
|
113
|
+
response += ', ';
|
114
|
+
}
|
115
|
+
|
116
|
+
response += 'expected: ' + details.expected + ', but was: ' + details.actual;
|
117
|
+
}
|
118
|
+
|
119
|
+
if (details.source) {
|
120
|
+
response += '\n' + details.source;
|
121
|
+
}
|
122
|
+
|
123
|
+
currentTestAssertions.push('Failed assertion: ' + response);
|
124
|
+
});
|
125
|
+
|
126
|
+
QUnit.testDone(function (result) {
|
127
|
+
var i,
|
128
|
+
len,
|
129
|
+
name = '';
|
130
|
+
|
131
|
+
if (result.module) {
|
132
|
+
name += result.module + ': ';
|
133
|
+
}
|
134
|
+
name += result.name;
|
135
|
+
|
136
|
+
if (result.failed) {
|
137
|
+
console.log('\n' + 'Test failed: ' + name);
|
138
|
+
|
139
|
+
for (i = 0, len = currentTestAssertions.length; i < len; i++) {
|
140
|
+
console.log(' ' + currentTestAssertions[i]);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
currentTestAssertions.length = 0;
|
145
|
+
});
|
146
|
+
|
147
|
+
QUnit.done(function (result) {
|
148
|
+
console.log('\n' + 'Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.');
|
149
|
+
|
150
|
+
if (typeof window.callPhantom === 'function') {
|
151
|
+
window.callPhantom({
|
152
|
+
'name': 'QUnit.done',
|
153
|
+
'data': result
|
154
|
+
});
|
155
|
+
}
|
156
|
+
});
|
157
|
+
}, false);
|
158
|
+
}
|
159
|
+
|
160
|
+
function exit(code) {
|
161
|
+
if (page) {
|
162
|
+
page.close();
|
163
|
+
}
|
164
|
+
setTimeout(function () {
|
165
|
+
phantom.exit(code);
|
166
|
+
}, 0);
|
167
|
+
}
|
168
|
+
})();
|
data/test/server.js
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
const http = require('http')
|
2
|
+
const fs = require('fs')
|
3
|
+
const path = require('path')
|
4
|
+
|
5
|
+
process.on('uncaughtException', err => console.error('uncaughtException', err))
|
6
|
+
process.on('unhandledRejection', err => console.error('unhandledRejection', err))
|
7
|
+
|
8
|
+
const publicFolder = process.argv.length > 2 ? process.argv[2] : '.'
|
9
|
+
const port = process.argv.length > 3 ? process.argv[3] : 3000
|
10
|
+
|
11
|
+
const mediaTypes = {
|
12
|
+
css: 'text/css',
|
13
|
+
html: 'text/html',
|
14
|
+
js: 'text/javascript'
|
15
|
+
}
|
16
|
+
|
17
|
+
const server = http.createServer(function(request, response) {
|
18
|
+
console.log(request.method + ' ' + request.url)
|
19
|
+
|
20
|
+
if (request.url == '/update') {
|
21
|
+
response.statusCode = 200;
|
22
|
+
response.setHeader('Access-Control-Allow-Origin', '*');
|
23
|
+
response.setHeader('Content-Type', 'application/json');
|
24
|
+
return response.end('{}');
|
25
|
+
}
|
26
|
+
const filepath = path.join(publicFolder, request.url)
|
27
|
+
fs.readFile(filepath, function(err, data) {
|
28
|
+
if (err) {
|
29
|
+
response.statusCode = 404
|
30
|
+
return response.end('File not found or you made an invalid request.')
|
31
|
+
}
|
32
|
+
|
33
|
+
let mediaType = 'text/html'
|
34
|
+
const ext = path.extname(filepath)
|
35
|
+
if (ext.length > 0 && mediaTypes.hasOwnProperty(ext.slice(1))) {
|
36
|
+
mediaType = mediaTypes[ext.slice(1)]
|
37
|
+
}
|
38
|
+
|
39
|
+
response.setHeader('Content-Type', mediaType)
|
40
|
+
response.end(data)
|
41
|
+
})
|
42
|
+
})
|
43
|
+
|
44
|
+
server.on('clientError', function onClientError(err, socket) {
|
45
|
+
console.log('clientError', err)
|
46
|
+
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
|
47
|
+
})
|
48
|
+
|
49
|
+
server.listen(port, '127.0.0.1', function() {
|
50
|
+
console.log('👨🔧 Development server is online.')
|
51
|
+
})
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
// ./test/unit/test_events.js
|
2
|
+
|
3
|
+
QUnit.module("TaskList events", {
|
4
|
+
beforeEach: function() {
|
5
|
+
this.container = $('<div>', {
|
6
|
+
"class": 'js-task-list-container'
|
7
|
+
});
|
8
|
+
this.list = $('<ul>', {
|
9
|
+
"class": 'task-list'
|
10
|
+
});
|
11
|
+
this.item = $('<li>', {
|
12
|
+
"class": 'task-list-item'
|
13
|
+
});
|
14
|
+
this.checkbox = $('<input>', {
|
15
|
+
type: 'checkbox',
|
16
|
+
"class": 'task-list-item-checkbox',
|
17
|
+
disabled: true,
|
18
|
+
checked: false
|
19
|
+
});
|
20
|
+
this.field = $('<textarea>', {
|
21
|
+
"class": 'js-task-list-field'
|
22
|
+
}, "- [ ] text");
|
23
|
+
this.item.append(this.checkbox);
|
24
|
+
this.list.append(this.item);
|
25
|
+
this.container.append(this.list);
|
26
|
+
this.container.append(this.field);
|
27
|
+
$('#qunit-fixture').append(this.container);
|
28
|
+
return this.container.taskList();
|
29
|
+
},
|
30
|
+
afterEach: function() {
|
31
|
+
$(document).off('tasklist:enabled');
|
32
|
+
$(document).off('tasklist:disabled');
|
33
|
+
$(document).off('tasklist:change');
|
34
|
+
return $(document).off('tasklist:changed');
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
QUnit.test("triggers a tasklist:change event before making task list item changes", function( assert ) {
|
39
|
+
var done = assert.async();
|
40
|
+
assert.expect(1);
|
41
|
+
this.field.on('tasklist:change', function(event, index, checked) {
|
42
|
+
return assert.ok(true);
|
43
|
+
});
|
44
|
+
setTimeout(function() {
|
45
|
+
done();
|
46
|
+
}, 20);
|
47
|
+
return this.checkbox.click();
|
48
|
+
});
|
49
|
+
|
50
|
+
QUnit.test("triggers a tasklist:changed event once a task list item changes", function( assert ) {
|
51
|
+
var done = assert.async();
|
52
|
+
assert.expect(1);
|
53
|
+
this.field.on('tasklist:changed', function(event, index, checked) {
|
54
|
+
return assert.ok(true);
|
55
|
+
});
|
56
|
+
setTimeout(function() {
|
57
|
+
done();
|
58
|
+
}, 20);
|
59
|
+
return this.checkbox.click();
|
60
|
+
});
|
61
|
+
|
62
|
+
QUnit.test("can cancel a tasklist:changed event", function( assert ) {
|
63
|
+
var initial;
|
64
|
+
var done = assert.async();
|
65
|
+
assert.expect(2);
|
66
|
+
this.field.on('tasklist:change', function(event, index, checked) {
|
67
|
+
assert.ok(true);
|
68
|
+
return event.preventDefault();
|
69
|
+
});
|
70
|
+
this.field.on('tasklist:changed', function(event, index, checked) {
|
71
|
+
return assert.ok(false);
|
72
|
+
});
|
73
|
+
initial = this.checkbox.val();
|
74
|
+
setTimeout((function(_this) {
|
75
|
+
return function() {
|
76
|
+
assert.equal(initial, _this.checkbox.val());
|
77
|
+
done();
|
78
|
+
};
|
79
|
+
})(this), 20);
|
80
|
+
return this.checkbox.click();
|
81
|
+
});
|
82
|
+
|
83
|
+
QUnit.test("enables task list items when a .js-task-list-field is present", function( assert ) {
|
84
|
+
var done = assert.async();
|
85
|
+
assert.expect(1);
|
86
|
+
$(document).on('tasklist:enabled', function(event) {
|
87
|
+
return assert.ok(true);
|
88
|
+
});
|
89
|
+
this.container.taskList();
|
90
|
+
return setTimeout(function() {
|
91
|
+
done();
|
92
|
+
}, 20);
|
93
|
+
});
|
94
|
+
|
95
|
+
QUnit.test("doesn't enable task list items when a .js-task-list-field is absent", function( assert ) {
|
96
|
+
var done = assert.async();
|
97
|
+
assert.expect(0);
|
98
|
+
$(document).on('tasklist:enabled', function(event) {
|
99
|
+
return assert.ok(true);
|
100
|
+
});
|
101
|
+
this.field.remove();
|
102
|
+
this.container.taskList();
|
103
|
+
return setTimeout(function() {
|
104
|
+
done();
|
105
|
+
}, 20);
|
106
|
+
});
|
@@ -0,0 +1,476 @@
|
|
1
|
+
// ./test/unit/test_updates.js
|
2
|
+
|
3
|
+
QUnit.module("TaskList updates", {
|
4
|
+
beforeEach: function() {
|
5
|
+
this.container = $('<div>', {
|
6
|
+
"class": 'js-task-list-container'
|
7
|
+
});
|
8
|
+
this.list = $('<ul>', {
|
9
|
+
"class": 'task-list'
|
10
|
+
});
|
11
|
+
this.completeItem = $('<li>', {
|
12
|
+
"class": 'task-list-item'
|
13
|
+
});
|
14
|
+
this.completeCheckbox = $('<input>', {
|
15
|
+
type: 'checkbox',
|
16
|
+
"class": 'task-list-item-checkbox',
|
17
|
+
disabled: true,
|
18
|
+
checked: true
|
19
|
+
});
|
20
|
+
this.incompleteItem = $('<li>', {
|
21
|
+
"class": 'task-list-item'
|
22
|
+
});
|
23
|
+
this.incompleteCheckbox = $('<input>', {
|
24
|
+
type: 'checkbox',
|
25
|
+
"class": 'task-list-item-checkbox',
|
26
|
+
disabled: true,
|
27
|
+
checked: false
|
28
|
+
});
|
29
|
+
this.nbsp = String.fromCharCode(160);
|
30
|
+
this.incompleteNBSPItem = $('<li>', {
|
31
|
+
"class": 'task-list-item'
|
32
|
+
});
|
33
|
+
this.incompleteNBSPCheckbox = $('<input>', {
|
34
|
+
type: 'checkbox',
|
35
|
+
"class": 'task-list-item-checkbox',
|
36
|
+
disabled: true,
|
37
|
+
checked: false
|
38
|
+
});
|
39
|
+
this.blockquote = $('<blockquote>');
|
40
|
+
this.quotedList = $('<ul>', {
|
41
|
+
"class": 'task-list'
|
42
|
+
});
|
43
|
+
this.quotedCompleteItem = $('<li>', {
|
44
|
+
"class": 'task-list-item'
|
45
|
+
});
|
46
|
+
this.quotedCompleteCheckbox = $('<input>', {
|
47
|
+
type: 'checkbox',
|
48
|
+
"class": 'task-list-item-checkbox',
|
49
|
+
disabled: true,
|
50
|
+
checked: true
|
51
|
+
});
|
52
|
+
this.quotedIncompleteItem = $('<li>', {
|
53
|
+
"class": 'task-list-item'
|
54
|
+
});
|
55
|
+
this.quotedIncompleteCheckbox = $('<input>', {
|
56
|
+
type: 'checkbox',
|
57
|
+
"class": 'task-list-item-checkbox',
|
58
|
+
disabled: true,
|
59
|
+
checked: false
|
60
|
+
});
|
61
|
+
this.innerBlockquote = $('<blockquote>');
|
62
|
+
this.innerList = $('<ul>', {
|
63
|
+
"class": 'task-list'
|
64
|
+
});
|
65
|
+
this.innerCompleteItem = $('<li>', {
|
66
|
+
"class": 'task-list-item'
|
67
|
+
});
|
68
|
+
this.innerCompleteCheckbox = $('<input>', {
|
69
|
+
type: 'checkbox',
|
70
|
+
"class": 'task-list-item-checkbox',
|
71
|
+
disabled: true,
|
72
|
+
checked: true
|
73
|
+
});
|
74
|
+
this.innerIncompleteItem = $('<li>', {
|
75
|
+
"class": 'task-list-item'
|
76
|
+
});
|
77
|
+
this.innerIncompleteCheckbox = $('<input>', {
|
78
|
+
type: 'checkbox',
|
79
|
+
"class": 'task-list-item-checkbox',
|
80
|
+
disabled: true,
|
81
|
+
checked: false
|
82
|
+
});
|
83
|
+
this.orderedList = $('<ol>', {
|
84
|
+
"class": 'task-list'
|
85
|
+
});
|
86
|
+
this.orderedCompleteItem = $('<li>', {
|
87
|
+
"class": 'task-list-item'
|
88
|
+
});
|
89
|
+
this.orderedCompleteCheckbox = $('<input>', {
|
90
|
+
type: 'checkbox',
|
91
|
+
"class": 'task-list-item-checkbox',
|
92
|
+
disabled: true,
|
93
|
+
checked: true
|
94
|
+
});
|
95
|
+
this.orderedIncompleteItem = $('<li>', {
|
96
|
+
"class": 'task-list-item'
|
97
|
+
});
|
98
|
+
this.orderedIncompleteCheckbox = $('<input>', {
|
99
|
+
type: 'checkbox',
|
100
|
+
"class": 'task-list-item-checkbox',
|
101
|
+
disabled: true,
|
102
|
+
checked: false
|
103
|
+
});
|
104
|
+
this.field = $('<textarea>', {
|
105
|
+
"class": 'js-task-list-field',
|
106
|
+
text: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete"
|
107
|
+
});
|
108
|
+
this.changes = {
|
109
|
+
toComplete: "- [ ] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
110
|
+
toQuotedComplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [ ] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
111
|
+
toInnerComplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [ ] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
112
|
+
toOrderedComplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [ ] ordered complete\n> 0. [ ] ordered incomplete",
|
113
|
+
toIncomplete: "- [x] complete\n- [x] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
114
|
+
toQuotedIncomplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [x] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
115
|
+
toInnerIncomplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [x] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete",
|
116
|
+
toOrderedIncomplete: "- [x] complete\n- [ ] incomplete\n- [" + this.nbsp + "] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [x] ordered incomplete",
|
117
|
+
toIncompleteNBSP: "- [x] complete\n- [ ] incomplete\n- [x] incompleteNBSP\n> - [x] quoted complete\n> - [ ] quoted incomplete\n>> - [x] inner complete\n> > - [ ] inner incomplete\n> 0. [x] ordered complete\n> 0. [ ] ordered incomplete"
|
118
|
+
};
|
119
|
+
this.completeItem.append(this.completeCheckbox);
|
120
|
+
this.list.append(this.completeItem);
|
121
|
+
this.completeItem.expectedIndex = 1;
|
122
|
+
this.incompleteItem.append(this.incompleteCheckbox);
|
123
|
+
this.list.append(this.incompleteItem);
|
124
|
+
this.incompleteItem.expectedIndex = 2;
|
125
|
+
this.incompleteNBSPItem.append(this.incompleteNBSPCheckbox);
|
126
|
+
this.list.append(this.incompleteNBSPItem);
|
127
|
+
this.incompleteNBSPItem.expectedIndex = 3;
|
128
|
+
this.container.append(this.list);
|
129
|
+
this.container.append(this.field);
|
130
|
+
this.quotedCompleteItem.append(this.quotedCompleteCheckbox);
|
131
|
+
this.quotedList.append(this.quotedCompleteItem);
|
132
|
+
this.quotedCompleteItem.expectedIndex = 4;
|
133
|
+
this.quotedIncompleteItem.append(this.quotedIncompleteCheckbox);
|
134
|
+
this.quotedList.append(this.quotedIncompleteItem);
|
135
|
+
this.quotedIncompleteItem.expectedIndex = 5;
|
136
|
+
this.blockquote.append(this.quotedList);
|
137
|
+
this.innerCompleteItem.append(this.innerCompleteCheckbox);
|
138
|
+
this.innerList.append(this.innerCompleteItem);
|
139
|
+
this.innerCompleteItem.expectedIndex = 6;
|
140
|
+
this.innerIncompleteItem.append(this.innerIncompleteCheckbox);
|
141
|
+
this.innerList.append(this.innerIncompleteItem);
|
142
|
+
this.innerIncompleteItem.expectedIndex = 7;
|
143
|
+
this.innerBlockquote.append(this.innerList);
|
144
|
+
this.innerBlockquote.append(this.innerField);
|
145
|
+
this.blockquote.append(this.innerBlockquote);
|
146
|
+
this.container.append(this.blockquote);
|
147
|
+
this.orderedCompleteItem.append(this.orderedCompleteCheckbox);
|
148
|
+
this.orderedList.append(this.orderedCompleteItem);
|
149
|
+
this.orderedCompleteItem.expectedIndex = 8;
|
150
|
+
this.orderedIncompleteItem.append(this.orderedIncompleteCheckbox);
|
151
|
+
this.orderedList.append(this.orderedIncompleteItem);
|
152
|
+
this.orderedIncompleteItem.expectedIndex = 9;
|
153
|
+
this.container.append(this.orderedList);
|
154
|
+
this.blockquote.append(this.field);
|
155
|
+
$('#qunit-fixture').append(this.container);
|
156
|
+
return this.container.taskList();
|
157
|
+
},
|
158
|
+
afterEach: function() {
|
159
|
+
return $(document).off('tasklist:changed');
|
160
|
+
}
|
161
|
+
});
|
162
|
+
|
163
|
+
QUnit.test("updates the source, marking the incomplete item as complete", function( assert ) {
|
164
|
+
var done = assert.async();
|
165
|
+
assert.expect(3);
|
166
|
+
this.field.on('tasklist:changed', (function(_this) {
|
167
|
+
return function(event, index, checked) {
|
168
|
+
assert.ok(checked);
|
169
|
+
assert.equal(index, _this.incompleteItem.expectedIndex);
|
170
|
+
return assert.equal(_this.field.val(), _this.changes.toIncomplete);
|
171
|
+
};
|
172
|
+
})(this));
|
173
|
+
setTimeout(function() {
|
174
|
+
done();
|
175
|
+
}, 20);
|
176
|
+
return this.incompleteCheckbox.click();
|
177
|
+
});
|
178
|
+
|
179
|
+
QUnit.test("updates the source, marking the complete item as incomplete", function( assert ) {
|
180
|
+
var done = assert.async();
|
181
|
+
assert.expect(3);
|
182
|
+
this.field.on('tasklist:changed', (function(_this) {
|
183
|
+
return function(event, index, checked) {
|
184
|
+
assert.ok(!checked);
|
185
|
+
assert.equal(index, _this.completeItem.expectedIndex);
|
186
|
+
return assert.equal(_this.field.val(), _this.changes.toComplete);
|
187
|
+
};
|
188
|
+
})(this));
|
189
|
+
setTimeout(function() {
|
190
|
+
done();
|
191
|
+
}, 20);
|
192
|
+
return this.completeCheckbox.click();
|
193
|
+
});
|
194
|
+
|
195
|
+
QUnit.test("updates the source for items with non-breaking spaces", function( assert ) {
|
196
|
+
var done = assert.async();
|
197
|
+
assert.expect(3);
|
198
|
+
this.field.on('tasklist:changed', (function(_this) {
|
199
|
+
return function(event, index, checked) {
|
200
|
+
assert.ok(checked);
|
201
|
+
assert.equal(index, _this.incompleteNBSPItem.expectedIndex);
|
202
|
+
return assert.equal(_this.field.val(), _this.changes.toIncompleteNBSP);
|
203
|
+
};
|
204
|
+
})(this));
|
205
|
+
setTimeout(function() {
|
206
|
+
done();
|
207
|
+
}, 20);
|
208
|
+
return this.incompleteNBSPCheckbox.click();
|
209
|
+
});
|
210
|
+
|
211
|
+
QUnit.test("updates the source of a quoted item, marking the incomplete item as complete", function( assert ) {
|
212
|
+
var done = assert.async();
|
213
|
+
assert.expect(3);
|
214
|
+
this.field.on('tasklist:changed', (function(_this) {
|
215
|
+
return function(event, index, checked) {
|
216
|
+
assert.ok(checked);
|
217
|
+
assert.equal(index, _this.quotedIncompleteItem.expectedIndex);
|
218
|
+
return assert.equal(_this.field.val(), _this.changes.toQuotedIncomplete);
|
219
|
+
};
|
220
|
+
})(this));
|
221
|
+
setTimeout(function() {
|
222
|
+
done();
|
223
|
+
}, 20);
|
224
|
+
return this.quotedIncompleteCheckbox.click();
|
225
|
+
});
|
226
|
+
|
227
|
+
QUnit.test("updates the source of a quoted item, marking the complete item as incomplete", function( assert ) {
|
228
|
+
var done = assert.async();
|
229
|
+
assert.expect(3);
|
230
|
+
this.field.on('tasklist:changed', (function(_this) {
|
231
|
+
return function(event, index, checked) {
|
232
|
+
assert.ok(!checked);
|
233
|
+
assert.equal(index, _this.quotedCompleteItem.expectedIndex);
|
234
|
+
return assert.equal(_this.field.val(), _this.changes.toQuotedComplete);
|
235
|
+
};
|
236
|
+
})(this));
|
237
|
+
setTimeout(function() {
|
238
|
+
done();
|
239
|
+
}, 20);
|
240
|
+
return this.quotedCompleteCheckbox.click();
|
241
|
+
});
|
242
|
+
|
243
|
+
QUnit.test("updates the source of a quoted quoted item, marking the incomplete item as complete", function( assert ) {
|
244
|
+
var done = assert.async();
|
245
|
+
assert.expect(3);
|
246
|
+
this.field.on('tasklist:changed', (function(_this) {
|
247
|
+
return function(event, index, checked) {
|
248
|
+
assert.ok(checked);
|
249
|
+
assert.equal(index, _this.innerIncompleteItem.expectedIndex);
|
250
|
+
return assert.equal(_this.field.val(), _this.changes.toInnerIncomplete);
|
251
|
+
};
|
252
|
+
})(this));
|
253
|
+
setTimeout(function() {
|
254
|
+
done();
|
255
|
+
}, 20);
|
256
|
+
return this.innerIncompleteCheckbox.click();
|
257
|
+
});
|
258
|
+
|
259
|
+
QUnit.test("updates the source of a quoted quoted item, marking the complete item as incomplete", function( assert ) {
|
260
|
+
var done = assert.async();
|
261
|
+
assert.expect(3);
|
262
|
+
this.field.on('tasklist:changed', (function(_this) {
|
263
|
+
return function(event, index, checked) {
|
264
|
+
assert.ok(!checked);
|
265
|
+
assert.equal(index, _this.innerCompleteItem.expectedIndex);
|
266
|
+
return assert.equal(_this.field.val(), _this.changes.toInnerComplete);
|
267
|
+
};
|
268
|
+
})(this));
|
269
|
+
setTimeout(function() {
|
270
|
+
done();
|
271
|
+
}, 20);
|
272
|
+
return this.innerCompleteCheckbox.click();
|
273
|
+
});
|
274
|
+
|
275
|
+
QUnit.test("updates the source of an ordered list item, marking the incomplete item as complete", function( assert ) {
|
276
|
+
var done = assert.async();
|
277
|
+
assert.expect(3);
|
278
|
+
this.field.on('tasklist:changed', (function(_this) {
|
279
|
+
return function(event, index, checked) {
|
280
|
+
assert.ok(checked);
|
281
|
+
assert.equal(index, _this.orderedIncompleteItem.expectedIndex);
|
282
|
+
return assert.equal(_this.field.val(), _this.changes.toOrderedIncomplete);
|
283
|
+
};
|
284
|
+
})(this));
|
285
|
+
setTimeout(function() {
|
286
|
+
done();
|
287
|
+
}, 20);
|
288
|
+
return this.orderedIncompleteCheckbox.click();
|
289
|
+
});
|
290
|
+
|
291
|
+
QUnit.test("updates the source of an ordered list item, marking the complete item as incomplete", function( assert ) {
|
292
|
+
var done = assert.async();
|
293
|
+
assert.expect(3);
|
294
|
+
this.field.on('tasklist:changed', (function(_this) {
|
295
|
+
return function(event, index, checked) {
|
296
|
+
assert.ok(!checked);
|
297
|
+
assert.equal(index, _this.orderedCompleteItem.expectedIndex);
|
298
|
+
return assert.equal(_this.field.val(), _this.changes.toOrderedComplete);
|
299
|
+
};
|
300
|
+
})(this));
|
301
|
+
setTimeout(function() {
|
302
|
+
done();
|
303
|
+
}, 20);
|
304
|
+
return this.orderedCompleteCheckbox.click();
|
305
|
+
});
|
306
|
+
|
307
|
+
QUnit.test("update ignores items that look like Task List items but lack list prefix", function( assert ) {
|
308
|
+
var done = assert.async();
|
309
|
+
var changes, container, field, item1, item1Checkbox, item2, item2Checkbox, list;
|
310
|
+
assert.expect(3);
|
311
|
+
$('#qunit-fixture').empty();
|
312
|
+
container = $('<div>', {
|
313
|
+
"class": 'js-task-list-container'
|
314
|
+
});
|
315
|
+
list = $('<ul>', {
|
316
|
+
"class": 'task-list'
|
317
|
+
});
|
318
|
+
item1 = $('<li>', {
|
319
|
+
"class": 'task-list-item'
|
320
|
+
});
|
321
|
+
item1Checkbox = $('<input>', {
|
322
|
+
type: 'checkbox',
|
323
|
+
"class": 'task-list-item-checkbox',
|
324
|
+
disabled: true,
|
325
|
+
checked: false
|
326
|
+
});
|
327
|
+
item2 = $('<li>', {
|
328
|
+
"class": 'task-list-item'
|
329
|
+
});
|
330
|
+
item2Checkbox = $('<input>', {
|
331
|
+
type: 'checkbox',
|
332
|
+
"class": 'task-list-item-checkbox',
|
333
|
+
disabled: true,
|
334
|
+
checked: false
|
335
|
+
});
|
336
|
+
field = $('<textarea>', {
|
337
|
+
"class": 'js-task-list-field',
|
338
|
+
text: "[ ] one\n[ ] two\n- [ ] three\n- [ ] four"
|
339
|
+
});
|
340
|
+
changes = "[ ] one\n[ ] two\n- [ ] three\n- [x] four";
|
341
|
+
item1.append(item1Checkbox);
|
342
|
+
list.append(item1);
|
343
|
+
item1.expectedIndex = 1;
|
344
|
+
item2.append(item2Checkbox);
|
345
|
+
list.append(item2);
|
346
|
+
item2.expectedIndex = 2;
|
347
|
+
container.append(list);
|
348
|
+
container.append(field);
|
349
|
+
$('#qunit-fixture').append(container);
|
350
|
+
container.taskList();
|
351
|
+
field.on('tasklist:changed', (function(_this) {
|
352
|
+
return function(event, index, checked) {
|
353
|
+
assert.ok(checked);
|
354
|
+
assert.equal(index, item2.expectedIndex);
|
355
|
+
return assert.equal(field.val(), changes);
|
356
|
+
};
|
357
|
+
})(this));
|
358
|
+
setTimeout(function() {
|
359
|
+
done();
|
360
|
+
}, 20);
|
361
|
+
return item2Checkbox.click();
|
362
|
+
});
|
363
|
+
|
364
|
+
QUnit.test("update ignores items that look like Task List items but are links", function( assert ) {
|
365
|
+
var done = assert.async();
|
366
|
+
var changes, container, field, item1, item1Checkbox, item2, item2Checkbox, list;
|
367
|
+
assert.expect(3);
|
368
|
+
$('#qunit-fixture').empty();
|
369
|
+
container = $('<div>', {
|
370
|
+
"class": 'js-task-list-container'
|
371
|
+
});
|
372
|
+
list = $('<ul>', {
|
373
|
+
"class": 'task-list'
|
374
|
+
});
|
375
|
+
item1 = $('<li>', {
|
376
|
+
"class": 'task-list-item'
|
377
|
+
});
|
378
|
+
item1Checkbox = $('<input>', {
|
379
|
+
type: 'checkbox',
|
380
|
+
"class": 'task-list-item-checkbox',
|
381
|
+
disabled: true,
|
382
|
+
checked: false
|
383
|
+
});
|
384
|
+
item2 = $('<li>', {
|
385
|
+
"class": 'task-list-item'
|
386
|
+
});
|
387
|
+
item2Checkbox = $('<input>', {
|
388
|
+
type: 'checkbox',
|
389
|
+
"class": 'task-list-item-checkbox',
|
390
|
+
disabled: true,
|
391
|
+
checked: false
|
392
|
+
});
|
393
|
+
field = $('<textarea>', {
|
394
|
+
"class": 'js-task-list-field',
|
395
|
+
text: "- [ ] (link)\n- [ ] [reference]\n- [ ] () collapsed\n- [ ] [] collapsed reference\n- [ ] \\(escaped item)\n- [ ] item"
|
396
|
+
});
|
397
|
+
changes = "- [ ] (link)\n- [ ] [reference]\n- [ ] () collapsed\n- [ ] [] collapsed reference\n- [ ] \\(escaped item)\n- [x] item";
|
398
|
+
item1.append(item1Checkbox);
|
399
|
+
list.append(item1);
|
400
|
+
item1.expectedIndex = 1;
|
401
|
+
item2.append(item2Checkbox);
|
402
|
+
list.append(item2);
|
403
|
+
item2.expectedIndex = 2;
|
404
|
+
container.append(list);
|
405
|
+
container.append(field);
|
406
|
+
$('#qunit-fixture').append(container);
|
407
|
+
container.taskList();
|
408
|
+
field.on('tasklist:changed', (function(_this) {
|
409
|
+
return function(event, index, checked) {
|
410
|
+
assert.ok(checked);
|
411
|
+
assert.equal(index, item2.expectedIndex);
|
412
|
+
return assert.equal(field.val(), changes);
|
413
|
+
};
|
414
|
+
})(this));
|
415
|
+
setTimeout(function() {
|
416
|
+
done();
|
417
|
+
}, 20);
|
418
|
+
return item2Checkbox.click();
|
419
|
+
});
|
420
|
+
|
421
|
+
QUnit.test("updates items followed by links", function( assert ) {
|
422
|
+
var done = assert.async();
|
423
|
+
var changes, container, field, item1, item1Checkbox, item2, item2Checkbox, list;
|
424
|
+
assert.expect(3);
|
425
|
+
$('#qunit-fixture').empty();
|
426
|
+
container = $('<div>', {
|
427
|
+
"class": 'js-task-list-container'
|
428
|
+
});
|
429
|
+
list = $('<ul>', {
|
430
|
+
"class": 'task-list'
|
431
|
+
});
|
432
|
+
item1 = $('<li>', {
|
433
|
+
"class": 'task-list-item'
|
434
|
+
});
|
435
|
+
item1Checkbox = $('<input>', {
|
436
|
+
type: 'checkbox',
|
437
|
+
"class": 'task-list-item-checkbox',
|
438
|
+
disabled: true,
|
439
|
+
checked: false
|
440
|
+
});
|
441
|
+
item2 = $('<li>', {
|
442
|
+
"class": 'task-list-item'
|
443
|
+
});
|
444
|
+
item2Checkbox = $('<input>', {
|
445
|
+
type: 'checkbox',
|
446
|
+
"class": 'task-list-item-checkbox',
|
447
|
+
disabled: true,
|
448
|
+
checked: false
|
449
|
+
});
|
450
|
+
field = $('<textarea>', {
|
451
|
+
"class": 'js-task-list-field',
|
452
|
+
text: "- [ ] [link label](link)\n- [ ] [reference label][reference]"
|
453
|
+
});
|
454
|
+
changes = "- [ ] [link label](link)\n- [x] [reference label][reference]";
|
455
|
+
item1.append(item1Checkbox);
|
456
|
+
list.append(item1);
|
457
|
+
item1.expectedIndex = 1;
|
458
|
+
item2.append(item2Checkbox);
|
459
|
+
list.append(item2);
|
460
|
+
item2.expectedIndex = 2;
|
461
|
+
container.append(list);
|
462
|
+
container.append(field);
|
463
|
+
$('#qunit-fixture').append(container);
|
464
|
+
container.taskList();
|
465
|
+
field.on('tasklist:changed', (function(_this) {
|
466
|
+
return function(event, index, checked) {
|
467
|
+
assert.ok(checked);
|
468
|
+
assert.equal(index, item2.expectedIndex);
|
469
|
+
return assert.equal(field.val(), changes);
|
470
|
+
};
|
471
|
+
})(this));
|
472
|
+
setTimeout(function() {
|
473
|
+
done();
|
474
|
+
}, 20);
|
475
|
+
return item2Checkbox.click();
|
476
|
+
});
|