@mmisty/cypress-grep
Version:
Filters tests by tags/title using substring or regular expressions (can find dynamic tags)
90 lines (89 loc) • 4.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addSearchInput = exports.updateCount = void 0;
const cypress_controls_ext_1 = require("cypress-controls-ext");
const select_element_css_1 = require("./select-element/select-element-css");
const select_element_html_1 = require("./select-element/select-element-html");
const index_1 = require("./index");
const testsCountSelector = '.number-input';
const inputGrep = '.grep';
const iconSearch = '.icon-container';
const withParent = (parentId) => (sel) => {
return `#${parentId} ${sel}`;
};
const updateCount = (parentId) => (count) => {
const testCountElement = (0, cypress_controls_ext_1.cypressAppSelect)(withParent(parentId)(testsCountSelector));
if (testCountElement.length > 0) {
testCountElement.text(count);
}
};
exports.updateCount = updateCount;
const setZIndex = (val) => {
// for some reason cypress header has sticky position and hovers tooltip
// soo need to change for a while
const cyHeader = (0, cypress_controls_ext_1.cypressAppSelect)('.reporter .runnable-header');
cyHeader.css('z-index', `${val}`);
};
const tooltipCorrect = (selector, listener) => {
listener(`${selector}`, 'mouseover', () => {
setZIndex(0);
});
listener(`${selector}`, 'mouseout', () => {
setZIndex(1);
});
};
const addSearchInput = (showTags, showPending) => {
const id = 'searchInput';
(0, cypress_controls_ext_1.setupControlsExtension)({
id,
mode: { open: true, run: (0, index_1.isInteractive)() },
inject: 'insertAfter',
selectorToInject: '.reporter header .toggle-specs-wrapper',
style: (0, select_element_css_1.style)(testsCountSelector, iconSearch),
control: () => (0, select_element_html_1.html)(testsCountSelector, inputGrep, iconSearch, showTags, showPending),
addEventListener: (parentId, listener, cyStop, cyRestart) => {
const selector = withParent(parentId);
listener(selector(inputGrep), 'change', () => {
cyStop();
cyRestart();
});
listener(selector(inputGrep), 'keypress', event => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (event.key === 'Enter') {
cyStop();
cyRestart();
}
});
listener(selector('.clear-input'), 'click', () => {
const searchField = (0, cypress_controls_ext_1.cypressAppSelect)(selector(inputGrep));
searchField.val('');
});
listener(selector('.show-tags'), 'click', () => {
const tagsDataSel = 'data-show-tags';
const tags = (0, cypress_controls_ext_1.cypressAppSelect)(selector('.show-tags'));
const val = tags.attr(tagsDataSel);
tags.attr(tagsDataSel, val === 'true' ? 'false' : 'true');
});
listener(selector('.show-pending'), 'click', () => {
const pendingDataSel = 'data-show-pending';
const tags = (0, cypress_controls_ext_1.cypressAppSelect)(selector('.show-pending'));
const val = tags.attr(pendingDataSel);
tags.attr(pendingDataSel, val === 'true' ? 'false' : 'true');
});
tooltipCorrect(selector('.btn-wrapper'), listener);
tooltipCorrect(selector(iconSearch), listener);
tooltipCorrect(selector(testsCountSelector), listener);
tooltipCorrect(selector('.btn-wrapper-icon'), listener);
listener(selector('.btn-wrapper-icon'), 'mouseover', () => {
const tool = (0, cypress_controls_ext_1.cypressAppSelect)(selector('.tooltip'));
tool.css('display', 'block');
});
listener(selector('.btn-wrapper-icon'), 'mouseout', () => {
const tool = (0, cypress_controls_ext_1.cypressAppSelect)(selector('.tooltip'));
tool.css('display', 'none');
});
},
});
return id;
};
exports.addSearchInput = addSearchInput;