Skip to content

Commit c6f315b

Browse files
committed
fix: Remove focus before taking a screenshot in AddGranteeBase
risk: nonprod JIRA: LX-729
1 parent a19cf4f commit c6f315b

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

Diff for: libs/sdk-ui-tests/backstop/backstop_data/engine_scripts/puppet/clickAndHoverHelper.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// (C) 2025 GoodData Corporation
2+
13
/* eslint-disable no-console,header/header */
24

35
const debug = process.env.BACKSTOP_DEBUG;
@@ -28,12 +30,17 @@ async function withVisibleSelector(page, scenario, selector, fun) {
2830
}
2931

3032
module.exports = async (page, scenario) => {
33+
const shouldResetFocus = scenario.shouldResetFocus;
3134
const hoverSelectors = scenario.hoverSelectors || scenario.hoverSelector;
3235
const clickSelectors = scenario.clickSelectors || scenario.clickSelector;
3336
const keyPressSelectors = scenario.keyPressSelectors || scenario.keyPressSelector;
3437
const scrollToSelector = scenario.scrollToSelector;
3538
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]
3639

40+
if (shouldResetFocus) {
41+
await page.evaluate(() => document.activeElement?.blur());
42+
}
43+
3744
if (keyPressSelectors) {
3845
for (const keyPressSelector of [].concat(keyPressSelectors)) {
3946
await page.waitForTimeout(keyPressSelector.selector);

Diff for: libs/sdk-ui-tests/stories/_infra/backstopScenario.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (C) 2007-2019 GoodData Corporation
1+
// (C) 2007-2025 GoodData Corporation
22

33
/*
44
* These types were taken mostly as-is from the @types/backstopjs package. renamed interfaces to start with 'I'
@@ -14,6 +14,11 @@ export interface IKeypressSelector {
1414
/** The Backstop test definition. See https://github.com/garris/BackstopJS#advanced-scenarios */
1515
export interface IBackstopScenarioConfig {
1616
[key: string]: any; // Allow for custom properties.
17+
/**
18+
* Whether the focus should be reset before taking a screenshot
19+
*/
20+
shouldResetFocus?: boolean;
21+
1722
/**
1823
* Click the specified DOM element prior to screenshot
1924
*/

Diff for: libs/sdk-ui-tests/stories/utils/useResetFocus.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// (C) 2025 GoodData Corporation
2+
import React from "react";
3+
4+
export const useResetFocus = (delay: number = 0): void => {
5+
React.useEffect(() => {
6+
const timeout = setTimeout(() => {
7+
(document.activeElement as HTMLElement | null)?.blur();
8+
}, delay);
9+
10+
return () => {
11+
clearTimeout(timeout);
12+
};
13+
}, [delay]);
14+
};

Diff for: libs/sdk-ui-tests/stories/visual-regression/kit/ShareDialog/AddGranteeBase.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (C) 2021 GoodData Corporation
1+
// (C) 2021-2025 GoodData Corporation
22
import React from "react";
33
import { storiesOf } from "../../../_infra/storyRepository.js";
44
import { action } from "@storybook/addon-actions";
@@ -189,5 +189,9 @@ export const AddGranteeExamples = (): JSX.Element => {
189189
};
190190

191191
storiesOf(`${UiKit}/ShareDialog/AddGranteeBase`)
192-
.add("full-featured", () => <AddGranteeExamples />, { screenshot: true })
193-
.add("themed", () => wrapWithTheme(<AddGranteeExamples />), { screenshot: true });
192+
.add("full-featured", () => <AddGranteeExamples />, {
193+
screenshot: { shouldResetFocus: true },
194+
})
195+
.add("themed", () => wrapWithTheme(<AddGranteeExamples />), {
196+
screenshot: { shouldResetFocus: true },
197+
});

0 commit comments

Comments
 (0)