-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
125 deletions.
There are no files selected for viewing
125 changes: 0 additions & 125 deletions
125
services/workflows-service/src/collection-flow/collection-flow.service.unit.test.ts
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
services/workflows-service/src/ui-definition/ui-definition.service.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { noop } from 'lodash'; | ||
|
||
import { TranslationService } from '@/providers/translation/translation.service'; | ||
import { UiDefinitionService } from '@/ui-definition/ui-definition.service'; | ||
|
||
import { WorkflowRuntimeDataRepository } from '@/workflow/workflow-runtime-data.repository'; | ||
import { UiDefinitionRepository } from './ui-definition.repository'; | ||
|
||
describe('UiDefinitionService', () => { | ||
let uiSchema: Record<string, unknown>; | ||
let context: Record<string, unknown>; | ||
|
||
let uiDefinitionService: UiDefinitionService; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
{ | ||
provide: UiDefinitionRepository, | ||
useValue: noop, | ||
}, | ||
{ | ||
provide: WorkflowRuntimeDataRepository, | ||
useValue: noop, | ||
}, | ||
UiDefinitionService, | ||
], | ||
}).compile(); | ||
|
||
uiDefinitionService = module.get<UiDefinitionService>(UiDefinitionService); | ||
}); | ||
|
||
beforeEach(() => { | ||
uiSchema = { | ||
title: 'Title', | ||
description: 'Description', | ||
nested: { | ||
label: 'Label', | ||
inner: { | ||
text: 'Inner Text', | ||
}, | ||
}, | ||
array: ['Item 1', 'Item 2'], | ||
}; | ||
|
||
context = {}; | ||
}); | ||
|
||
it('should translate leaf nodes of the uiSchema', () => { | ||
const language = 'fr'; | ||
const expectedUiSchema = { | ||
title: 'Translated Title', | ||
description: 'Translated Description', | ||
nested: { | ||
label: 'Translated Label', | ||
inner: { | ||
text: 'Translated Inner Text', | ||
}, | ||
}, | ||
array: ['Translated Item 1', 'Translated Item 2'], | ||
}; | ||
|
||
const translationService = new TranslationService(); | ||
|
||
translationService.translate = jest.fn((text, lang) => | ||
lang === 'fr' ? `Translated ${text}` : text, | ||
); | ||
|
||
const result = uiDefinitionService.traverseUiSchema( | ||
uiSchema, | ||
context, | ||
language, | ||
translationService, | ||
); | ||
expect(result).toEqual(expectedUiSchema); | ||
}); | ||
}); |