Skip to content

Commit

Permalink
Merge branch 'master' into package-updates-0624
Browse files Browse the repository at this point in the history
  • Loading branch information
akanshaaa19 authored Jun 20, 2024
2 parents b40e9b4 + ea343e1 commit c99f349
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/containers/Flow/FlowTranslation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
.Radio {
padding: 0px 8px;
}

.DialogContent {
text-align: center;
}
45 changes: 44 additions & 1 deletion src/containers/Flow/FlowTranslation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, waitFor, fireEvent } from '@testing-library/react';
import { render, waitFor, fireEvent, screen } from '@testing-library/react';
import { vi } from 'vitest';
import { MockedProvider } from '@apollo/client/testing';
import * as Notification from 'common/notification';
Expand Down Expand Up @@ -37,6 +37,13 @@ describe('Testing Translation flows', () => {

const button = getByText('Submit');
fireEvent.click(button);

await waitFor(() => {
expect(screen.getByText('Note')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('Continue'));

await waitFor(() => {
expect(notificationSpy).toHaveBeenCalledWith('Flow has been translated successfully');
});
Expand All @@ -48,6 +55,11 @@ describe('Testing Translation flows', () => {

const button = getByText('Submit');
fireEvent.click(button);
await waitFor(() => {
expect(screen.getByText('Note')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('Continue'));
await waitFor(() => {
expect(notificationSpy).toHaveBeenCalledWith('Sorry! Unable to translate flow', 'warning');
});
Expand All @@ -70,6 +82,13 @@ describe('Testing Translation flows', () => {
fireEvent.click(getByText('Export with auto translate'));
const submitButton = getByText('Submit');
fireEvent.click(submitButton);

await waitFor(() => {
expect(screen.getByText('Note')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('Continue'));

await waitFor(() => {
expect(mockSetDialog).toHaveBeenCalledWith(false);
});
Expand Down Expand Up @@ -106,4 +125,28 @@ describe('Testing Translation flows', () => {
expect(mockSetDialog).toHaveBeenCalledWith(false);
});
});
it('it closes the warning dialog box', async () => {
const { getByText, container } = render(flowTranslation());
await waitFor(() => {
expect(container).toBeInTheDocument();
});

const button = getByText('Submit');
fireEvent.click(button);

await waitFor(() => {
expect(screen.getByText('Note')).toBeInTheDocument();
});

fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape', code: 'esc' });
});

it('closes the translation dialog box', async () => {
const wrapper = render(flowTranslation());
await waitFor(() => {
expect(wrapper.container).toBeInTheDocument();
});

fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape', code: 'esc' });
});
});
48 changes: 42 additions & 6 deletions src/containers/Flow/FlowTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const BackdropLoader = ({ text }: any) => (
export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTranslationProps) => {
const [action, setAction] = useState('auto');
const [importing, setImporting] = useState(false);
const [autoTranslate, setAutoTranslate] = useState<any>(null);

const { t } = useTranslation();

Expand Down Expand Up @@ -91,19 +92,25 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
};

const handleOk = () => {
if (action === 'auto') {
handleAuto();
} else if (action === 'export') {
if (action === 'auto' || action === 'export-auto') {
setAutoTranslate(action);
} else {
handleExport();
} else if (action === 'export-auto') {
handleAutoExport();
}
};

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setAction((event.target as HTMLInputElement).value);
};

const handleAutoTranslate = () => {
if (autoTranslate === 'auto') {
handleAuto();
} else if (autoTranslate === 'export-auto') {
handleAutoExport();
}
};

const importButton = (
<ImportButton
title={t('Import translations')}
Expand Down Expand Up @@ -175,7 +182,29 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
</div>
);

return (
let autoTranslateWarningDialog;
if (autoTranslate) {
autoTranslateWarningDialog = (
<DialogBox
title="Note"
alignButtons="center"
buttonOk="Continue"
buttonCancel="Cancel"
handleOk={handleAutoTranslate}
handleCancel={() => {
setAutoTranslate(null);
}}
>
<p className={styles.DialogContent}>
Auto translate only adds translation in languages nodes which are empty. To get the latest
translations of updated content in your default language flow, please clear the nodes in
the language nodes.
</p>
</DialogBox>
);
}

let flowTranslationDialog = (
<DialogBox
title="Translate Options"
alignButtons="center"
Expand All @@ -190,6 +219,13 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans
{dialogContent}
</DialogBox>
);

return (
<>
{flowTranslationDialog}
{autoTranslateWarningDialog}
</>
);
};

export default FlowTranslation;

0 comments on commit c99f349

Please sign in to comment.