Skip to content

Commit 00dac71

Browse files
committed
improve tests
1 parent caaf8f9 commit 00dac71

1 file changed

Lines changed: 46 additions & 28 deletions

File tree

tests/ui/PureReportActionItemTest.tsx

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1818
import type {ReportAction} from '@src/types/onyx';
1919
import type {OriginalMessage} from '@src/types/onyx/ReportAction';
2020
import type ReportActionName from '@src/types/onyx/ReportActionName';
21+
import type {TranslationPaths} from '@src/languages/types';
2122
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
2223
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
2324

@@ -101,40 +102,57 @@ describe('PureReportActionItem', () => {
101102
}
102103

103104
describe('Automatic actions', () => {
104-
it('APPROVED action via workspace rules', async () => {
105-
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.APPROVED, {automaticAction: true});
105+
const testCases = [
106+
{
107+
testTitle: 'APPROVED action via workspace rules',
108+
actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED,
109+
originalMessageExtras: {automaticAction: true},
110+
translationKey: 'iou.automaticallyApproved',
111+
},
112+
{
113+
testTitle: 'FORWARDED action via workspace rules',
114+
actionName: CONST.REPORT.ACTIONS.TYPE.FORWARDED,
115+
originalMessageExtras: {automaticAction: true},
116+
translationKey: 'iou.automaticallyForwarded',
117+
},
118+
{
119+
testTitle: 'SUBMITTED action via harvesting',
120+
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
121+
originalMessageExtras: {harvesting: true},
122+
translationKey: 'iou.automaticallySubmitted',
123+
},
124+
{
125+
testTitle: 'SUBMITTED_AND_CLOSED action via harvesting',
126+
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED,
127+
originalMessageExtras: {harvesting: true},
128+
translationKey: 'iou.automaticallySubmitted',
129+
},
130+
];
131+
132+
const parseTextWithTrailingLink = (translatedText: string) => {
133+
const match = translatedText.match(/^(.*?)(<a[^>]*>)(.*?)(<\/a>)$/);
134+
if (!match) {
135+
return null;
136+
}
137+
const [, textBeforeLink, , linkText] = match;
138+
return {textBeforeLink, linkText};
139+
}
140+
141+
it.each(testCases)('$testTitle', async ({actionName, originalMessageExtras, translationKey}) => {
142+
const action = createReportAction(actionName, originalMessageExtras);
106143
renderItemWithAction(action);
107144
await waitForBatchedUpdatesWithAct();
108145

109146
expect(screen.getByText(actorEmail)).toBeOnTheScreen();
110-
expect(screen.getByText('approved via')).toBeOnTheScreen();
111-
});
112-
113-
it('FORWARDED action via workspace rules', async () => {
114-
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.FORWARDED, {automaticAction: true});
115-
renderItemWithAction(action);
116-
await waitForBatchedUpdatesWithAct();
117-
118-
expect(screen.getByText(actorEmail)).toBeOnTheScreen();
119-
expect(screen.getByText('approved via')).toBeOnTheScreen();
120-
});
121-
122-
it('SUBMITTED action via harvesting', async () => {
123-
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.SUBMITTED, {harvesting: true});
124-
renderItemWithAction(action);
125-
await waitForBatchedUpdatesWithAct();
126-
127-
expect(screen.getByText(actorEmail)).toBeOnTheScreen();
128-
expect(screen.getByText('submitted via')).toBeOnTheScreen();
129-
});
130147

131-
it('SUBMITTED_AND_CLOSED action via harvesting', async () => {
132-
const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED, {harvesting: true});
133-
renderItemWithAction(action);
134-
await waitForBatchedUpdatesWithAct();
148+
const parsedText = parseTextWithTrailingLink(translateLocal(translationKey as TranslationPaths));
149+
if (!parsedText) {
150+
throw new Error("Text cannot be parsed, translation failed");
151+
}
135152

136-
expect(screen.getByText(actorEmail)).toBeOnTheScreen();
137-
expect(screen.getByText('submitted via')).toBeOnTheScreen();
153+
const {textBeforeLink, linkText} = parsedText;
154+
expect(screen.getByText(textBeforeLink)).toBeOnTheScreen();
155+
expect(screen.getByText(linkText)).toBeOnTheScreen();
138156
});
139157
});
140158

0 commit comments

Comments
 (0)