Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDA-4443_4444: Adding A11Y to Close and Prevent enter while pod is disabled #2063

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/__snapshots__/aboutApp.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports[`about app should render correctly 1`] = `
className="AboutApp-close-button"
data-testid="CLOSE_BUTTON"
disabled={false}
onKeyDown={[Function]}
onMouseDown={[Function]}
title="Close"
>
Expand Down
89 changes: 89 additions & 0 deletions spec/aboutApp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,93 @@ describe('about app', () => {
.hasClass('AboutApp-button-save-restart-text'),
).toBe(true);
});

it('should restore to global config url on cancelling after enter pressed', () => {
const cloneAboutDataMock = {
...aboutDataMockState,
finalConfig: { url: 'bcd.symphony.com' },
};

cloneAboutDataMock.globalConfig = { isPodUrlEditable: true };
cloneAboutDataMock.userConfig = { isPodUrlEditable: false };

const wrapper = shallow(React.createElement(AboutApp));
ipcRenderer.send('about-app-data', cloneAboutDataMock);
const pod = wrapper.find(`[data-testid="POD_INFO"]`);
pod.simulate('click', { detail: 1 });
pod.simulate('click', { detail: 2 });
pod.simulate('click', { detail: 3 });

const inputPod = wrapper.find(`[data-testid="POD_INFO_INPUT"]`);
inputPod.simulate('change', {
target: { value: 'pod.symphony.com123' },
});
inputPod.simulate('keydown', {
target: { value: 'pod.symphony.com123' },
keyCode: 13,
});
wrapper.find(`[data-testid="CANCEL_BUTTON"]`).simulate('click');

expect(pod.text()).toBe('abcxyz.symphony.com');
});

it('should work with A11Y Cancel button', () => {
const cloneAboutDataMock = {
...aboutDataMockState,
finalConfig: { url: 'bcd.symphony.com' },
};

cloneAboutDataMock.globalConfig = { isPodUrlEditable: true };
cloneAboutDataMock.userConfig = { isPodUrlEditable: false };

const wrapper = shallow(React.createElement(AboutApp));
ipcRenderer.send('about-app-data', cloneAboutDataMock);
const pod = wrapper.find(`[data-testid="POD_INFO"]`);
pod.simulate('click', { detail: 1 });
pod.simulate('click', { detail: 2 });
pod.simulate('click', { detail: 3 });

wrapper.find(`[data-testid="CANCEL_BUTTON"]`).simulate('keydown', {
target: { value: 'pod.symphony.com123' },
keyCode: 13,
});

expect(wrapper.find(`[data-testid="CANCEL_BUTTON"]`).exists()).toBe(false);
});

it('should work with A11Y Close button', () => {
const cloneAboutDataMock = {
...aboutDataMockState,
finalConfig: { url: 'bcd.symphony.com' },
};

cloneAboutDataMock.globalConfig = { isPodUrlEditable: true };
cloneAboutDataMock.userConfig = { isPodUrlEditable: false };

const wrapper = shallow(React.createElement(AboutApp));
ipcRenderer.send('about-app-data', cloneAboutDataMock);
const pod = wrapper.find(`[data-testid="POD_INFO"]`);
pod.simulate('click', { detail: 1 });
pod.simulate('click', { detail: 2 });
pod.simulate('click', { detail: 3 });

const inputPod = wrapper.find(`[data-testid="POD_INFO_INPUT"]`);
inputPod.simulate('change', {
target: { value: 'pod.symphony.com' },
});
inputPod.simulate('keydown', {
target: { value: 'pod.symphony.com' },
keyCode: 13,
});

wrapper.find(`[data-testid="CLOSE_BUTTON"]`).simulate('keydown', {
keyCode: 13,
});

expect(ipcRenderer.send).toHaveBeenNthCalledWith(
12,
'user-pod-updated',
'pod.symphony.com',
);
});
});
25 changes: 25 additions & 0 deletions src/renderer/components/about-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const SFE_CLIENT_TYPE_NAME = 'SFE-Lite';
const KEY_CODE = {
ENTER: 13,
ESCAPE: 27,
SPACE: 32,
};

/**
Expand Down Expand Up @@ -202,6 +203,7 @@ export default class AboutApp extends React.Component<{}, IState> {
onMouseDown={this.eventHandlers.onCancel}
title={cancelText}
data-testid={'CANCEL_BUTTON'}
onKeyDown={this.onCancelKeyDown}
>
{cancelText}
</button>
Expand All @@ -219,6 +221,7 @@ export default class AboutApp extends React.Component<{}, IState> {
data-testid={'CLOSE_BUTTON'}
ref={this.closeButtonRef}
disabled={!isValidHostname}
onKeyDown={this.onCloseKeyDown}
>
<span
className={classNames({
Expand Down Expand Up @@ -334,6 +337,9 @@ export default class AboutApp extends React.Component<{}, IState> {
*/
public onKeyDown = (e) => {
if (e.keyCode === KEY_CODE.ENTER) {
if (!this.state.isValidHostname) {
return;
}
const { value } = e.target;
this.setState({ updatedHostname: value });
this.handlePodInputBlur(e);
Expand All @@ -348,6 +354,25 @@ export default class AboutApp extends React.Component<{}, IState> {
});
}
};
/**
* Handles handle keydown on Close
* @param e
*/
public onCloseKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
if (e.keyCode === KEY_CODE.ENTER || e.keyCode === KEY_CODE.SPACE) {
this.close();
}
};

/**
* Handles key down on Cancel
* @param e
*/
public onCancelKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
if (e.keyCode === KEY_CODE.ENTER || e.keyCode === KEY_CODE.SPACE) {
this.cancel();
}
};

/**
* Validates and sets new hostname
Expand Down
Loading