@mariusandra/simmerjs
Version:
A pure Javascript reverse CSS selector engine which calculates a DOM element's unique CSS selector on the current page.
135 lines (133 loc) • 3.6 kB
JavaScript
;
var _inspectNthChild = require("./inspectNthChild");
describe('analyzeElementSiblings', () => {
test(`takes an only child with no classes and identifies it as having a unique tag / class`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => []
}, [])).toBe(true);
});
test(`takes an only child with classes and identifies it as having a unique tag / class`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someClass']
}, [])).toBe(true);
});
test(`takes an child with a sibling and identifies it as having a unique tag`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someClass']
}, [{
el: {
nodeName: 'P'
},
getClasses: () => []
}])).toBe(true);
});
test(`takes an child with a sibling and identifies it as having a unique class`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someClass']
}, [{
el: {
nodeName: 'DIV'
},
getClasses: () => []
}])).toBe(true);
});
test(`takes an child with a sibling and identifies it as having a unique class among matching classes`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someUniqueClass', 'someBClass']
}, [{
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someBClass']
}])).toBe(true);
});
test(`takes an child with multiple sibling and identifies it as having a unique class among matching classes`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someUniqueClass', 'someBClass']
}, [{
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someDClass']
}])).toBe(true);
});
test(`takes an child with multiple sibling and identifies it as having no unique class`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someBClass']
}, [{
el: {
nodeName: 'DIV'
},
getClasses: () => ['someAClass', 'someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someBClass']
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => ['someDClass']
}])).toBe(false);
});
test(`takes an child with multiple sibling and identifies it as having no unique tag`, function () {
expect((0, _inspectNthChild.analyzeElementSiblings)({
el: {
nodeName: 'DIV'
},
getClasses: () => []
}, [{
el: {
nodeName: 'DIV'
},
getClasses: () => []
}, {
el: {
nodeName: 'DIV'
},
getClasses: () => []
}])).toBe(false);
});
});