-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathhtml_code.js
More file actions
143 lines (141 loc) · 5.07 KB
/
Copy pathhtml_code.js
File metadata and controls
143 lines (141 loc) · 5.07 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var phantom = require('node-phantom-simple'),
phantomjs = require('phantomjs'),
assert = require('assert'),
testutil = require('./lib/testutil'),
one_step_timeout = 8000,
asyncTest = testutil.asyncTest;
describe('html editor', function() {
var _ph, _page;
before(function(done) {
// Create the headless webkit browser.
phantom.create(function(error, ph) {
assert.ifError(error);
// Open a page for browsing.
_ph = ph;
_ph.createPage(function(err, page) {
_page = page;
page.onConsoleMessage = function(msg) {
console.log(msg);
}
// Set the size to a modern laptop size.
page.set('viewportSize', { width: 1200, height: 900 }, function(err) {
assert.ifError(err);
// Point it to a blank page to start
page.open('about:blank', function(err, status){
assert.ifError(err);
assert.equal(status, 'success');
done();
});
});
});
}, {
// Launch phantomjs from the phantomjs package.
phantomPath: phantomjs.path,
parameters: {
// Use the test server as a proxy server, so that all requests
// go to this server (instead of trying real DNS lookups).
proxy: '127.0.0.1:8193',
// Set the disk storage to zero to avoid persisting localStorage
// between test runs.
'local-storage-quota': 0
}
});
});
after(function() {
// Be sure to kill the browser when the test is done, or else
// we can leave orphan processes.
_ph.exit();
});
it('should serve static editor HTML', function(done) {
// Visit the website of the user "livetest."
_page.open('http://aaa.pencilcode.net.dev/edit/first.html',
function(err, status) {
assert.ifError(err);
assert.equal(status, 'success');
_page.evaluate(function() {
// Inject a script that clears the login cookie for a clean start.
document.cookie='login=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
// And also clear localStorage for this site.
localStorage.clear();
}, function(err) {
assert.ifError(err);
done();
});
});
});
it('should flip into code mode', function(done) {
asyncTest(_page, one_step_timeout, null, function() {
// Click on the "blocks" button
var leftlink = $('.panetitle').filter(
function() { return $(this).parent().position().left == 0; })
.find('a');
leftlink.click();
}, function() {
var lefttitle = $('.panetitle').filter(
function() { return $(this).parent().position().left == 0; })
.find('.panetitle-text');
if (/blocks/.test(lefttitle.text())) return;
return {
filename: $('#filename').text(),
title: lefttitle.text().trim(),
saved: $('#save').prop('disabled')
};
}, function(err, result) {
assert.ifError(err);
// Filename is still shown and unchanged.
assert.ok(/^first.html/.test(result.filename));
// Intentional: we should always add an extra empty line at the bottom.
assert.equal(result.title, 'html');
// The save button is enabled, because it's a new file.
assert.equal(result.saved, false);
done();
});
});
it('should flip into block mode', function(done) {
asyncTest(_page, one_step_timeout, null, function() {
// Click on the "blocks" button
var leftlink = $('.panetitle').filter(
function() { return $(this).parent().position().left == 0; })
.find('a');
leftlink.click();
}, function() {
var lefttitle = $('.panetitle').filter(
function() { return $(this).parent().position().left == 0; })
.find('.panetitle-text');
if (/html/.test(lefttitle.text())) return;
return {
filename: $('#filename').text(),
title: lefttitle.text().trim(),
saved: $('#save').prop('disabled')
};
}, function(err, result) {
assert.ifError(err);
// Filename is still shown and unchanged.
assert.ok(/^first.html/.test(result.filename));
// Intentional: we should always add an extra empty line at the bottom.
assert.ok(/blocks/.test(result.title));
// The save button is enabled, because it's a new file.
assert.equal(result.saved, false);
done();
});
});
//Rename to a .coffee file
var name = 'test' + ('' + Math.random()).substring(2) + '.coffee';
it('should switch palette on filetype change', function(done) {
asyncTest(_page, one_step_timeout, [name], function(name) {
// Alter the editable filename and give up focus.
$('#filename').text(name).focus().blur();
}, function() {
if (!$('.droplet-hover-div.tooltipstered')) return;
return {
//Content of first block in new mode
text: $('.droplet-hover-div.tooltipstered').eq(0).tooltipster('content')
}
}, function(err, result) {
assert.ifError(err);
//First block should be that of coffeescript
assert.equal(result.text, 'Move forward');
done();
});
});
});