Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
special characters tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meirotstein committed Oct 31, 2017
1 parent 538a431 commit 4fd7ca0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 59 deletions.
10 changes: 5 additions & 5 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
"type": "map",
"lo": 64.128597,
"la": -21.896110,
"tooltip": "map tooltip"
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq ="
},
{
"type": "image",
"url": "http://cdn.bgr.com/2016/08/iphone-8-concept.jpg",
"tooltip": "image tooltip",
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq =",
"click": {
"metadata": [{
"bla1": 1,
Expand All @@ -103,7 +103,7 @@
{
"type": "text",
"text": "product name (Title)",
"tooltip": "text tooltip",
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq =",
"style": {
"bold": true,
"size": "large"
Expand All @@ -112,7 +112,7 @@
, {
"type": "text",
"text": "long long long long long long long long long long long long long long long long long product category (type)",
"tooltip": "text tooltip"
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq ="
}
, {
"type": "text",
Expand Down Expand Up @@ -143,7 +143,7 @@
,{
"type": "button",
"title": "Navigate to store",
"tooltip": "store is the thing",
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq =",
"click" : {
"actions": [{
"type": "navigate",
Expand Down
134 changes: 80 additions & 54 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,77 +361,103 @@ describe('json-pollock tests', function () {
var rooEl = null;
var childEl = null;

it('Text element', function () {
var conf = {
"type": "text",
"text": "product name (Title)",
"tooltip": "text tooltip"
function singleElementTest(title, conf, assertionClass) {
it(title + ' element' , function () {

rooEl = addToBody(JsonPollock.render(conf));

var wrapdiv = rooEl.childNodes[0];
chai.expect(wrapdiv.localName).to.equal('div');
chai.expect(wrapdiv.className).to.equal('lp-json-pollock lp-json-pollock-single-element');
chai.expect(wrapdiv.childNodes.length).to.equal(1);

childEl = wrapdiv.childNodes[0];
chai.expect(childEl.className).to.contain(assertionClass);
});
}

singleElementTest('Text',
{
"type": "text",
"text": "product name (Title)",
"tooltip": "text tooltip"
},
'lp-json-pollock-element-text');

singleElementTest('Button',
{
"type": "button",
"tooltip": "button tooltip",
"title": "Add to cart",
"click": {
"actions": [{
"type": "link",
"id": "febf3237-f7d9-44bc-a17f-fc8abdfb0f25",
"name": "add to cart",
"uri": "http://example.jpg"
}]
}
},
'lp-json-pollock-element-button');

rooEl = addToBody(JsonPollock.render(conf));

var wrapdiv = rooEl.childNodes[0];
chai.expect(wrapdiv.localName).to.equal('div');
chai.expect(wrapdiv.className).to.equal('lp-json-pollock lp-json-pollock-single-element');
chai.expect(wrapdiv.childNodes.length).to.equal(1);
singleElementTest('Image',
{
"type": "image",
"url": "http://example.jpg",
"tooltip": "image tooltip",
"click": {
"actions": [{
"type": "navigate",
"id": "98446950-2f54-4594-b89b-1d60a9fdda49",
"name": "Navigate to store via image",
"lo": 23.423423,
"la": 2423423423
}]
}
},
'lp-json-pollock-element-image');

childEl = wrapdiv.childNodes[0];
chai.expect(childEl.className).to.equal('lp-json-pollock-element-text');
});
singleElementTest('Map',
{
"type": "map",
"lo": 64.128597,
"la": -21.896110,
"tooltip": "map tooltip"
},
'lp-json-pollock-element-map');

});

it('Button element', function () {
describe('special characters', function () {

var rooEl = null;
var childEl = null;

it('special characters on text tooltip should be escaped', function () {
var conf = {
"type": "button",
"tooltip": "button tooltip",
"title": "Add to cart",
"click": {
"actions": [{
"type": "link",
"id": "febf3237-f7d9-44bc-a17f-fc8abdfb0f25",
"name": "add to cart",
"uri": "http://example.jpg"
}]
}
"type": "text",
"text": "product name (Title)",
"tooltip": "and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq ="
}

rooEl = addToBody(JsonPollock.render(conf));

var wrapdiv = rooEl.childNodes[0];
chai.expect(wrapdiv.localName).to.equal('div');
chai.expect(wrapdiv.className).to.equal('lp-json-pollock lp-json-pollock-single-element');
chai.expect(wrapdiv.childNodes.length).to.equal(1);

childEl = wrapdiv.childNodes[0];
chai.expect(childEl.className).to.equal('lp-json-pollock-element-button');
childEl = rooEl.childNodes[0].childNodes[0].childNodes[0];
chai.expect(childEl.title).to.equal("and & lt < gt > quot \"\n sqout ' slash / ssqout ` eq =");
});

it('Image element', function () {
it('newline character on text content should be replaced with <br>', function () {
var conf = {
"type": "image",
"url": "http://example.jpg",
"tooltip": "image tooltip",
"click": {
"actions": [{
"type": "navigate",
"id": "98446950-2f54-4594-b89b-1d60a9fdda49",
"name": "Navigate to store via image",
"lo": 23.423423,
"la": 2423423423
}]
}
"type": "text",
"text": "line1\nline2"
}

rooEl = addToBody(JsonPollock.render(conf));

var wrapdiv = rooEl.childNodes[0];
chai.expect(wrapdiv.localName).to.equal('div');
chai.expect(wrapdiv.className).to.equal('lp-json-pollock lp-json-pollock-single-element');
chai.expect(wrapdiv.childNodes.length).to.equal(1);

childEl = wrapdiv.childNodes[0];
chai.expect(childEl.className).to.contain('lp-json-pollock-element-image');
childEl = rooEl.childNodes[0].childNodes[0].childNodes[0];
chai.expect(childEl.innerHTML).to.equal("line1<br>line2");
});

});

describe('trigger actions', function () {
Expand Down

0 comments on commit 4fd7ca0

Please sign in to comment.