mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
chore(account): write tests for CreateAccessToken [EE-2561] (#6578)
This commit is contained in:
parent
b7d18ef50f
commit
f1ea2b5c02
8 changed files with 178 additions and 27 deletions
36
app/__mocks__/i18next.ts
Normal file
36
app/__mocks__/i18next.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
function replaceBetween(
|
||||
startIndex: number,
|
||||
endIndex: number,
|
||||
original: string,
|
||||
insertion: string
|
||||
) {
|
||||
const result =
|
||||
original.substring(0, startIndex) +
|
||||
insertion +
|
||||
original.substring(endIndex);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function mockT(i18nKey: string, args?: Record<string, string>) {
|
||||
let key = i18nKey;
|
||||
|
||||
while (key.includes('{{') && args) {
|
||||
const startIndex = key.indexOf('{{');
|
||||
const endIndex = key.indexOf('}}');
|
||||
|
||||
const currentArg = key.substring(startIndex + 2, endIndex);
|
||||
const value = args[currentArg];
|
||||
|
||||
key = replaceBetween(startIndex, endIndex + 2, key, value);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
const i18next: Record<string, unknown> = jest.createMockFromModule('i18next');
|
||||
i18next.t = mockT;
|
||||
i18next.language = 'en';
|
||||
i18next.changeLanguage = () => new Promise(() => {});
|
||||
i18next.use = () => i18next;
|
||||
|
||||
export default i18next;
|
Loading…
Add table
Add a link
Reference in a new issue