Skip to content

Commit

Permalink
Add tests for string sheet semicolon parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
VivaLaVia committed Jun 22, 2022
1 parent 4a89fcf commit 0c22210
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions test/style-string-sheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const expect = require('chai').expect;
const cytoscape = require('../src/test.js');

describe('String-sheet parsing', function(){
let cy;
let consoleWarn;

this.beforeAll(function() {
consoleWarn = console.warn;
console.warn = function() {};
});

this.afterAll(function() {
console.warn = consoleWarn;
});

beforeEach(function() {
cy = cytoscape({
styleEnabled: true,
elements: {
nodes: [
{ data: { id: 'n1' } },
],
},
});
});

afterEach(function(){
cy.destroy();
});

[
'#n1 { color: rgb(1,1,1); background-color: rgb(1,1,1); }',
'#n1 { color: rgb(1,1,1); background-color: rgb(1,1,1) }',
'#n1 {color: rgb(1,1,1);background-color: rgb(1,1,1);}',
`#n1 {color: rgb(1,1,1);
background-color: rgb(1,1,1);}`,
]
.forEach((stringSheet) => {
it('style block applied when parsed with no validity errors', function(){
let style = cy.$('#n1').style();
expect( style ).to.have.property('color');
expect( style['color'] ).to.exist;
expect( style['color'] ).not.to.equal('rgb(1,1,1)');
expect( style ).to.have.property('background-color');
expect( style['background-color'] ).to.exist;
expect( style['background-color'] ).not.to.equal('rgb(1,1,1)');

cy.style().fromString(stringSheet);

style = cy.$('#n1').style();
expect( style['color'] ).to.equal('rgb(1,1,1)');
expect( style['background-color'] ).to.equal('rgb(1,1,1)');
});
});

[
'#n1 { color: rgb(1,1,1) }',
'#n1 { color: rgb(1,1,1); }',
]
.forEach((stringSheet) => {
it('style block with one property applied when parsed with no validity errors', function(){
let style = cy.$('#n1').style();
expect( style ).to.have.property('color');
expect( style['color'] ).to.exist;
expect( style['color'] ).not.to.equal('rgb(1,1,1)');


cy.style().fromString(stringSheet);

style = cy.$('#n1').style();
expect( style['color'] ).to.equal('rgb(1,1,1)');
});
});

[
'#n1 { color: rgb(1,1,1) background-color: rgb(1,1,1) }',
'#n1 { color: rgb(1,1,1) background-color: rgb(1,1,1); }',
`#n1 {color: rgb(1,1,1)
background-color: rgb(1,1,1);}`,
]
.forEach((stringSheet) => {
it('style block ignored when parsed with validity error', function(){
let style = cy.$('#n1').style();
expect( style ).to.have.property('color');
expect( style['color'] ).to.exist;
expect( style['color'] ).not.to.equal('rgb(1,1,1)');
expect( style ).to.have.property('background-color');
expect( style['background-color'] ).to.exist;
expect( style['background-color'] ).not.to.equal('rgb(1,1,1)');

cy.style().fromString(stringSheet);

style = cy.$('#n1').style();
expect( style['color'] ).not.to.equal('rgb(1,1,1)');
expect( style['background-color'] ).not.to.equal('rgb(1,1,1)');
});
});

});

0 comments on commit 0c22210

Please sign in to comment.