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

cmd-plus-enter-commit-dialog #1296

Merged
merged 2 commits into from
Sep 20, 2022
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
89 changes: 89 additions & 0 deletions src/app/components/PushDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react';
import { Provider } from 'react-redux';
import { StorageProviderType } from '@/constants/StorageProviderType';
import {
act, render, resetStore, createMockStore, fireEvent,
} from '../../../tests/config/setupTest';
import PushDialog from './PushDialog';
import { store } from '../store';

describe('PushDialog', () => {
beforeEach(() => {
resetStore();
});

it('should show push dialog', () => {
const mockStore = createMockStore({
uiState: {
showPushDialog: 'initial',
localApiState: {
branch: 'main',
provider: StorageProviderType.GITHUB,
},
},
});

const result = render(
<Provider store={mockStore}>
<PushDialog />
</Provider>,
);
expect(result.getByText('Push changes')).toBeInTheDocument();
expect(result.getByText('Commit message')).toBeInTheDocument();
expect(result.getByText('Push')).toBeInTheDocument();

result.unmount();
});

it('should show success dialog', () => {
const mockStore = createMockStore({
uiState: {
showPushDialog: 'success',
localApiState: {
branch: 'main',
provider: StorageProviderType.GITHUB,
},
},
});

const result = render(
<Provider store={mockStore}>
<PushDialog />
</Provider>,
);
expect(result.getByText('Changes pushed to GitHub')).toBeInTheDocument();
expect(result.getByText('Create Pull Request')).toBeInTheDocument();

result.unmount();
});

it('should be able to push by pressing ctrl/cmd + Enter', () => {
const mockStore = createMockStore({
uiState: {
showPushDialog: 'initial',
localApiState: {
branch: 'main',
provider: StorageProviderType.GITHUB,
},
},
});

const result = render(
<Provider store={mockStore}>
<PushDialog />
</Provider>,
);

act(() => {
fireEvent.keyDown(document, {
key: 'Enter',
code: 'Enter',
ctrlKey: true,
});
});

expect(store.getState().uiState.showPushDialog).toBe(false);

result.unmount();
});
});
9 changes: 9 additions & 0 deletions src/app/components/PushDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Spinner from './Spinner';
import { StorageProviderType } from '@/constants/StorageProviderType';
import { isGitProvider } from '@/utils/is';
import Textarea from './Textarea';
import { useShortcut } from '@/hooks/useShortcut';

function ConfirmDialog() {
const { onConfirm, onCancel, showPushDialog } = usePushDialog();
Expand Down Expand Up @@ -84,6 +85,14 @@ function ConfirmDialog() {
}
}, [showPushDialog, localApiState]);

const handleSaveShortcut = React.useCallback((event: KeyboardEvent) => {
if (event.metaKey || event.ctrlKey) {
handleSubmit();
}
}, [handleSubmit]);

useShortcut(['Enter'], handleSaveShortcut);

switch (showPushDialog) {
case 'initial': {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/TokenGroup/TokenGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('TokenGroup', () => {
resetStore();
});

it('should be able to collpase a token group', async () => {
it('should be able to collapse a token group', async () => {
const { getByTestId } = render(<TokenGroup
tokenValues={tokenValues as DeepKeyTokenMap}
showNewForm={showNewForm}
Expand Down