Skip to content

Commit b931d60

Browse files
authored
fix: Copy button not working on forms and readonly editors (#4202)
* fix: fix Copy button * test: add copy check * test: adjust copy button test * test: remove wait
1 parent a2ecf11 commit b931d60

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/shared/contexts/YamlEditorContext/EditorActions.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export function EditorActions({
105105
className="action-button"
106106
tooltip={t('common.tooltips.download')}
107107
/>
108-
<CopyButton val={val} className="action-button" resourceName={title} />
108+
<CopyButton
109+
contentToCopy={val}
110+
buttonClassName="action-button"
111+
resourceName={title}
112+
/>
109113
<Button
110114
design="Transparent"
111115
icon={visible ? 'hide' : 'show'}

tests/integration/support/helpers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ export function useCategory(category) {
2020
cy.getLeftNav().contains(category).click();
2121
});
2222
}
23+
24+
export const grantClipboardPermissions = () => {
25+
cy.wrap(
26+
Cypress.automation('remote:debugger:protocol', {
27+
command: 'Browser.grantPermissions',
28+
params: {
29+
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
30+
origin: window.location.origin,
31+
},
32+
}),
33+
);
34+
};

tests/integration/tests/namespace/test-stateful-sets.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { grantClipboardPermissions } from '../../support/helpers';
12
import { loadFile } from '../../support/loadFile';
23

34
const FILE_NAME = 'test-stateful-sets.yaml';
@@ -51,6 +52,29 @@ context('Test Stateful Sets', () => {
5152
cy.getMidColumn().contains('web:80/TCP');
5253
});
5354

55+
it('Check if Copy button works correctly', () => {
56+
grantClipboardPermissions();
57+
cy.inspectTab('Edit');
58+
59+
// Stub window.prompt so browser popup never shows
60+
cy.window().then((win) => {
61+
cy.stub(win, 'prompt')
62+
.callsFake((msg, value) => {
63+
expect(value).to.contain('kind: StatefulSet');
64+
return value;
65+
})
66+
.as('copyPrompt');
67+
});
68+
69+
cy.get('ui5-button[icon="copy"]:visible').click({ force: true });
70+
71+
cy.contains(`Copied ${SS_NAME}.yaml to clipboard`).should('be.visible');
72+
cy.wait(2100);
73+
cy.contains(`Copied ${SS_NAME}.yaml to clipboard`).should('not.exist');
74+
75+
cy.get('@copyPrompt').should('have.been.called');
76+
});
77+
5478
it('Inspect list', () => {
5579
cy.wait(3000); // wait for the resource to be refeched and displayed in the list
5680
cy.inspectList(SS_NAME);

0 commit comments

Comments
 (0)