Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: Allow to ignore every element, matching selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Korotin committed Dec 19, 2016
1 parent a1b4f34 commit c36ed78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion doc/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ All methods are chainable:

All tests in a suite will fail if none of the elements will be found.

* `ignoreElements('selector1', 'selector2', ...)` - elements, matching
* `ignoreElements('.selector1', {every: '.selector2'}, ...)` - elements, matching
specified selectors will be ignored when comparing images.
- `.selector1` - Ignore only the first matched element.
- `{every: '.selector2'}` - Ignore all matched elements.

* `setTolerance(value)` - overrides global tolerance value for the whole suite
(See `tolerance`option description in [config](./config.md) documentation
Expand Down
17 changes: 10 additions & 7 deletions lib/browser/client-scripts/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,21 @@ function getCaptureRect(selectors) {
function findIgnoreAreas(selectors) {
var result = [];
util.each(selectors, function(selector) {
var element = lib.queryFirst(selector);
if (element) {
var rect = getElementCaptureRect(element);
if (rect) {
result.push(rect.round().serialize());
}
}
var elements = typeof selector === 'string'
? [lib.queryFirst(selector)]
: lib.queryAll(selector.every);

util.each(elements, addIgnoreArea.bind(result));
});

return result;
}

function addIgnoreArea(element) {
var rect = element && getElementCaptureRect(element);
rect && this.push(rect.round().serialize());
}

function isHidden(css, clientRect) {
return css.display === 'none' ||
css.visibility === 'hidden' ||
Expand Down
9 changes: 7 additions & 2 deletions lib/tests-api/suite-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ module.exports = function(suite) {
this.ignoreElements = function ignoreElements() {
var selectors = argumentsToArray(arguments);

if (selectors.some(notString)) {
throw new TypeError('suite.ignoreElements accepts only strings or array of strings');
if (selectors.some(isNotValidSelector)) {
throw new TypeError('suite.ignoreElements accepts strings, object with property "every" as string or array of them');
}
suite.ignoreSelectors = selectors;
return this;
Expand Down Expand Up @@ -133,6 +133,11 @@ function notString(arg) {
return typeof arg !== 'string';
}

// Check if selector is not a string or not an object with "every" option.
function isNotValidSelector(arg) {
return !(_.isString(arg) || (_.isObject(arg) && _.isString(arg.every)));
}

function argumentsToArray(args) {
if (args.length === 1 && Array.isArray(args[0])) {
return args[0];
Expand Down

0 comments on commit c36ed78

Please sign in to comment.