Skip to content
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
19 changes: 10 additions & 9 deletions apps/meteor/client/omnichannel/priorities/PrioritiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import type { ILivechatPriority, Serialized } from '@rocket.chat/core-typings';
import type { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';

import { PriorityIcon } from './PriorityIcon';
import PrioritiesTableRow from './PrioritiesTableRow';
import GenericNoResults from '../../components/GenericNoResults';
import {
GenericTable,
GenericTableHeaderCell,
GenericTableCell,
GenericTableRow,
GenericTableHeader,
GenericTableBody,
GenericTableLoadingTable,
Expand Down Expand Up @@ -48,12 +46,15 @@ export const PrioritiesTable = ({ priorities, onRowClick, isLoading }: Prioritie
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{priorities?.map(({ _id, name, i18n, sortItem, dirty }) => (
<GenericTableRow key={_id} tabIndex={0} role='link' onClick={(): void => onRowClick(_id)} action qa-row-id={_id}>
<GenericTableCell withTruncatedText>
<PriorityIcon level={sortItem} />
</GenericTableCell>
<GenericTableCell withTruncatedText>{dirty ? name : t(i18n)}</GenericTableCell>
</GenericTableRow>
<PrioritiesTableRow
key={_id}
id={_id}
name={name}
i18n={i18n}
sortItem={sortItem}
dirty={dirty}
onClick={() => onRowClick(_id)}
/>
))}
</GenericTableBody>
</GenericTable>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { render, screen } from '@testing-library/react';

import PrioritiesTableRow from './PrioritiesTableRow';

const mockedPriority = {
id: '1',
i18n: 'Highest',
sortItem: 1,
dirty: false,
onClick: jest.fn(),
};

const defaultContainer = document.body.appendChild(document.createElement('table')).appendChild(document.createElement('tbody'));

test('should match the translation if its the default language', async () => {
render(<PrioritiesTableRow {...mockedPriority} />, {
container: defaultContainer,
wrapper: mockAppRoot()
.withDefaultLanguage('en')
.withTranslations('en', 'core', {
Highest: mockedPriority.i18n,
})
.build(),
});

expect(screen.queryByRole('table')).toHaveTextContent(mockedPriority.i18n);
});

test('should not match the defaultText if its not the default language', async () => {
render(<PrioritiesTableRow {...mockedPriority} />, {
container: defaultContainer,
wrapper: mockAppRoot()
.withDefaultLanguage('pt-BR')
.withTranslations('pt-BR', 'core', {
Highest: 'Muito Alta',
})
.build(),
});

expect(screen.queryByRole('table')).not.toHaveTextContent(mockedPriority.i18n);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { LivechatPriorityWeight } from '@rocket.chat/core-typings';
import { useTranslation } from 'react-i18next';

import { PriorityIcon } from './PriorityIcon';
import { GenericTableCell, GenericTableRow } from '../../components/GenericTable';

type PrioritiesTableRowProps = {
id: string;
name?: string;
i18n: string;
sortItem: LivechatPriorityWeight;
dirty: boolean;
onClick: () => void;
};

const PrioritiesTableRow = ({ id, name, i18n, sortItem, dirty, onClick }: PrioritiesTableRowProps) => {
const { t } = useTranslation();
return (
<GenericTableRow tabIndex={0} role='link' onClick={onClick} action qa-row-id={id}>
<GenericTableCell withTruncatedText>
<PriorityIcon level={sortItem} />
</GenericTableCell>
<GenericTableCell withTruncatedText>{dirty ? name : t(i18n)}</GenericTableCell>
</GenericTableRow>
);
};

export default PrioritiesTableRow;
15 changes: 15 additions & 0 deletions packages/mock-providers/src/MockedAppRootBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ export class MockedAppRootBuilder {
return this;
}

// Manually changes the language in the i18next instance
// To be used with languages other than the default one
withDefaultLanguage(lng: string): this {
if (this.i18n.isInitialized) {
this.i18n.changeLanguage(lng);
return this;
}

this.i18n.on('initialized', () => {
this.i18n.changeLanguage(lng);
});

return this;
}

withServerContext(partial: Partial<ServerContextValue>): this {
this.server = { ...this.server, ...partial };
return this;
Expand Down
Loading