Skip to content

Commit 8e6f81b

Browse files
committed
fix issues with element state
1 parent e419bb4 commit 8e6f81b

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

dist/addStyles.js

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const addStyles = () => {
2-
const { $ } = Cypress;
32
const hasStyles = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrStyle');
43
const hasToggleButton = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle');
54
const defaultStyles = `
@@ -45,6 +44,9 @@ export const addStyles = () => {
4544
border-style: solid;
4645
border-color: transparent transparent #f3f4fa transparent;
4746
}
47+
.reporter:has(#xhrToggle:checked) .command.command-name-request:has(.command-is-event) {
48+
display:none
49+
}
4850
`;
4951
const turnOffXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 6.5c2.76 0 5 2.24 5 5c0 .51-.1 1-.24 1.46l3.06 3.06c1.39-1.23 2.49-2.77 3.18-4.53C21.27 7.11 17 4 12 4c-1.27 0-2.49.2-3.64.57l2.17 2.17c.47-.14.96-.24 1.47-.24zM2.71 3.16a.996.996 0 0 0 0 1.41l1.97 1.97A11.892 11.892 0 0 0 1 11.5C2.73 15.89 7 19 12 19c1.52 0 2.97-.3 4.31-.82l2.72 2.72a.996.996 0 1 0 1.41-1.41L4.13 3.16c-.39-.39-1.03-.39-1.42 0zM12 16.5c-2.76 0-5-2.24-5-5c0-.77.18-1.5.49-2.14l1.57 1.57c-.03.18-.06.37-.06.57c0 1.66 1.34 3 3 3c.2 0 .38-.03.57-.07L14.14 16c-.65.32-1.37.5-2.14.5zm2.97-5.33a2.97 2.97 0 0 0-2.64-2.64l2.64 2.64z"/></svg>`;
5052
const turnOnXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 4C7 4 2.73 7.11 1 11.5C2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 12.5c-2.76 0-5-2.24-5-5s2.24-5 5-5s5 2.24 5 5s-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3s3-1.34 3-3s-1.34-3-3-3z"/></svg>`;
@@ -82,37 +84,32 @@ export const addStyles = () => {
8284
headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleInput);
8385
headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleLabel);
8486
}
85-
const xhrToggleElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle');
86-
const xhrToggleLabelElement = top === null || top === void 0 ? void 0 : top.document.querySelector('[for=xhrToggle]');
87-
const xhrTooltipElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrTooltip');
88-
const hideXhr = () => {
89-
$("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "none");
90-
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
91-
xhrTooltipElement.innerHTML = turnOnXhrDescription;
92-
};
93-
const showXhr = () => {
94-
$("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "block");
95-
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
96-
xhrTooltipElement.innerHTML = turnOffXhrDescription;
97-
};
98-
if (Cypress.env('hideXhr')) {
99-
xhrToggleElement.setAttribute('checked', 'true');
100-
Cypress.on('log:added', () => {
101-
hideXhr();
102-
});
103-
}
104-
else {
105-
// just to be on the safe side when changing hideXhr variable
106-
xhrToggleElement.setAttribute('checked', 'false');
107-
showXhr();
87+
const xhrToggleElement = top.document.querySelector('#xhrToggle');
88+
const xhrToggleLabelElement = top.document.querySelector('[for=xhrToggle]');
89+
const xhrTooltipElement = top.document.querySelector('#xhrTooltip');
90+
if (xhrToggleElement && xhrToggleLabelElement && xhrTooltipElement) {
91+
if (Cypress.env('hideXhr') === true || Cypress.env('hideXhr') === undefined) {
92+
xhrToggleElement.checked = true;
93+
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
94+
xhrTooltipElement.innerHTML = turnOnXhrDescription;
95+
}
96+
else {
97+
xhrToggleElement.checked = false;
98+
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
99+
xhrTooltipElement.innerHTML = turnOffXhrDescription;
100+
}
108101
}
109-
xhrToggleElement.addEventListener('change', (e) => {
102+
xhrToggleElement === null || xhrToggleElement === void 0 ? void 0 : xhrToggleElement.addEventListener('change', (e) => {
110103
// @ts-ignore errors about HTMLElement
111104
if (e.target.checked) {
112-
hideXhr();
105+
// when checked, xhr elements are hidden
106+
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
107+
xhrTooltipElement.innerHTML = turnOnXhrDescription;
113108
}
114109
else {
115-
showXhr();
110+
// when unchecked, xhr elements are visible
111+
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
112+
xhrTooltipElement.innerHTML = turnOffXhrDescription;
116113
}
117114
});
118115
};

src/addStyles.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ export const addStyles = () => {
9999
const xhrToggleLabelElement = top.document.querySelector('[for=xhrToggle]')
100100
const xhrTooltipElement = top.document.querySelector('#xhrTooltip')
101101

102-
if (Cypress.env('hideXhr') === true || Cypress.env('hideXhr') === undefined) {
103-
xhrToggleElement.checked = true
104-
xhrToggleLabelElement.innerHTML = turnOnXhrIcon
105-
xhrTooltipElement.innerHTML = turnOnXhrDescription
106-
} else {
107-
xhrToggleElement.checked = false
108-
xhrToggleLabelElement.innerHTML = turnOffXhrIcon
109-
xhrTooltipElement.innerHTML = turnOffXhrDescription
102+
if (xhrToggleElement && xhrToggleLabelElement && xhrTooltipElement) {
103+
104+
if (Cypress.env('hideXhr') === true || Cypress.env('hideXhr') === undefined) {
105+
xhrToggleElement.checked = true
106+
xhrToggleLabelElement.innerHTML = turnOnXhrIcon
107+
xhrTooltipElement.innerHTML = turnOnXhrDescription
108+
} else {
109+
xhrToggleElement.checked = false
110+
xhrToggleLabelElement.innerHTML = turnOffXhrIcon
111+
xhrTooltipElement.innerHTML = turnOffXhrDescription
112+
}
110113
}
111114

112115
xhrToggleElement?.addEventListener('change', (e) => {

0 commit comments

Comments
 (0)