feat(editor): Add examples for object and array expression methods (#9360)

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Elias Meire
2024-05-14 16:32:31 +02:00
committed by GitHub
parent 78e7c7a9da
commit 52936633af
11 changed files with 890 additions and 193 deletions

View File

@@ -92,6 +92,17 @@ describe('Data Transformation Functions', () => {
).toEqual([1, 2, 3, 'as', {}, [1, 2], '[sad]', null]);
});
test('.unique() should work on an arrays of objects', () => {
expect(
evaluate(
"={{ [{'name':'Nathan', age:42}, {'name':'Jan', age:16}, {'name':'Nathan', age:21}].unique('name') }}",
),
).toEqual([
{ name: 'Nathan', age: 42 },
{ name: 'Jan', age: 16 },
]);
});
test('.isEmpty() should work correctly on an array', () => {
expect(evaluate('={{ [].isEmpty() }}')).toEqual(true);
});
@@ -242,6 +253,10 @@ describe('Data Transformation Functions', () => {
);
});
test('.append() should work on an array', () => {
expect(evaluate('={{ [1,2,3].append(4,5,"done") }}')).toEqual([1, 2, 3, 4, 5, 'done']);
});
describe('Conversion methods', () => {
test('should exist but return undefined (to not break expressions with mixed data)', () => {
expect(evaluate('={{ numberList(1, 20).toInt() }}')).toBeUndefined();

View File

@@ -253,6 +253,9 @@ describe('Data Transformation Functions', () => {
);
expect(evaluate('={{ "2008-11-11".toDateTime() }}')).toBeInstanceOf(DateTime);
expect(evaluate('={{ "1-Feb-2024".toDateTime() }}')).toBeInstanceOf(DateTime);
expect(evaluate('={{ "1713976144063".toDateTime("ms") }}')).toBeInstanceOf(DateTime);
expect(evaluate('={{ "31-01-2024".toDateTime("dd-MM-yyyy") }}')).toBeInstanceOf(DateTime);
expect(() => evaluate('={{ "hi".toDateTime() }}')).toThrowError(
new ExpressionExtensionError('cannot convert to Luxon DateTime'),
);