add attribute test to HTML parser node tests

This commit is contained in:
Dave Conway-Jones 2015-12-19 14:30:43 +00:00
parent 08b39f50b3
commit 65daaeb617
2 changed files with 94 additions and 33 deletions

View File

@ -113,10 +113,47 @@ describe('html node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.payload.should.be.instanceof(Array).and.have.lengthOf(1);
msg.payload[0].indexOf("Blue").should.be.above(-1);
msg.payload[0].indexOf("Red").should.be.above(-1);
done();
});
n1.receive({payload:data,topic: "bar"});
});
});
});
it('should fix up a unclosed tag', function(done) {
fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],tag:"span"},
{id:"n2", type:"helper"}];
helper.load(htmlNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
should.equal(msg.payload, '<img src="foo.png"/>');
done();
});
n1.receive({payload:data,topic: "bar"});
});
});
});
it('should retrive an attribute from a tag', function(done) {
fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"attr",tag:"span img"},
{id:"n2", type:"helper"}];
helper.load(htmlNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('payload');
msg.payload[0].should.have.property('src','foo.png');
msg.should.have.property('topic', 'bar');
done();
});
n1.receive({payload:data,topic: "bar"});
});
@ -232,6 +269,26 @@ describe('html node', function() {
});
});
it('should retrieve an attribute from a tag', function(done) {
fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"attr",tag:"span img",as:"multi"},
{id:"n2", type:"helper"}];
helper.load(htmlNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('payload');
msg.payload.should.have.property('src','foo.png');
msg.should.have.property('topic', 'bar');
cnt = 2; // frig the answer as only one img tag
done();
});
n1.receive({payload:data,topic: "bar"});
});
});
});
});
});

View File

@ -21,5 +21,9 @@
<li>Parsnip</li>
</ul>
<span>
<img src="foo.png">
</span>
</body>
</html>