|
|
|
@ -195,6 +195,72 @@ describe('StyleManager', () => { |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule1]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('With multiple classes, should both be in parents list', () => { |
|
|
|
const cmp = domc.addComponent('<div class="cls cls2"></div>'); |
|
|
|
const [rule1, rule2] = cssc.addRules(` |
|
|
|
.cls { color: red; } |
|
|
|
.cls2 { color: blue; } |
|
|
|
`);
|
|
|
|
em.setSelected(cmp); |
|
|
|
obj.__upSel(); |
|
|
|
expect(obj.getSelected()).not.toBe(rule1); |
|
|
|
expect(obj.getSelected()).not.toBe(rule2); |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule2, rule1]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('With tagName + class, class first', () => { |
|
|
|
const cmp = domc.addComponent('<div class="cls" id="id-test"></div>'); |
|
|
|
const [rule1, rule2] = cssc.addRules(` |
|
|
|
.cls { color: red; } |
|
|
|
div { color: yellow; } |
|
|
|
`);
|
|
|
|
em.setSelected(cmp); |
|
|
|
obj.__upSel(); |
|
|
|
expect(obj.getSelected()).toBe(rule1); |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule2]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Should ignore rules with tagName in the selector path but the rule is not apply on the tagName', () => { |
|
|
|
const cmp = domc.addComponent('<div class="cls" id="id-test"></div>'); |
|
|
|
const [rule1, rule2] = cssc.addRules(` |
|
|
|
.cls { color: red; } |
|
|
|
div { color: yellow; } |
|
|
|
div .child { padding: 10px; } |
|
|
|
`);
|
|
|
|
em.setSelected(cmp); |
|
|
|
obj.__upSel(); |
|
|
|
// getSelectedParents should only have 1 rule as the third one is not applied on the div
|
|
|
|
expect(obj.getSelected()).toBe(rule1); |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule2]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Should tagName rules if the selectors does not contain only the tagNale', () => { |
|
|
|
const cmp = domc.addComponent('<div class="cls" id="id-test"></div>'); |
|
|
|
const [rule1, rule2] = cssc.addRules(` |
|
|
|
.cls { color: red; } |
|
|
|
div { color: yellow; } |
|
|
|
.child div { padding: 10px; } |
|
|
|
`);
|
|
|
|
em.setSelected(cmp); |
|
|
|
obj.__upSel(); |
|
|
|
// getSelectedParents should only have 1 rule as the third one is not applied on the div
|
|
|
|
expect(obj.getSelected()).toBe(rule1); |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule2]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('With tagName + ID + class, class first, ID second', () => { |
|
|
|
const cmp = domc.addComponent('<div class="cls" id="id-test"></div>'); |
|
|
|
const [rule1, rule2, rule3] = cssc.addRules(` |
|
|
|
.cls { color: red; } |
|
|
|
div { color: yellow; } |
|
|
|
#id-test { color: blue; } |
|
|
|
`);
|
|
|
|
em.setSelected(cmp); |
|
|
|
obj.__upSel(); |
|
|
|
expect(obj.getSelected()).toBe(rule1); |
|
|
|
expect(obj.getSelectedParents()).toEqual([rule3, rule2]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('With ID + class, multiple devices', () => { |
|
|
|
sm.setComponentFirst(true); |
|
|
|
const cmp = domc.addComponent('<div class="cls" id="id-test"></div>'); |
|
|
|
|