mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
feat(tests): update json-templates tests to include date filters and handle undefined keys
This commit is contained in:
parent
8a127b02ef
commit
0d0872a1a5
@ -27,7 +27,7 @@ describe('json-templates', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('json-templates filters', () => {
|
describe('json-templates filters', () => {
|
||||||
it('format filters', async () => {
|
it('date filters', async () => {
|
||||||
const template = {
|
const template = {
|
||||||
today: '{{now | date_format: "YYYY-MM-DD"}}',
|
today: '{{now | date_format: "YYYY-MM-DD"}}',
|
||||||
yesterday: '{{now | date_subtract: 1, "day" | date_format: "YYYY-MM-DD"}}',
|
yesterday: '{{now | date_subtract: 1, "day" | date_format: "YYYY-MM-DD"}}',
|
||||||
@ -43,4 +43,35 @@ describe('json-templates filters', () => {
|
|||||||
yesterday: '2024-12-31',
|
yesterday: '2024-12-31',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('multiple level accessiong', async () => {
|
||||||
|
const template = {
|
||||||
|
user: '{{user.name}}',
|
||||||
|
firstOfArray1: '{{array.0}}',
|
||||||
|
firstOfArray2: '{{array[0]}}',
|
||||||
|
};
|
||||||
|
const result = parse(template)({
|
||||||
|
user: { name: 'john' },
|
||||||
|
array: ['first', 'second'],
|
||||||
|
});
|
||||||
|
expect(result).toEqual({
|
||||||
|
user: 'john',
|
||||||
|
firstOfArray1: 'first',
|
||||||
|
firstOfArray2: 'first',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when key is undefined, ignore it', async () => {
|
||||||
|
const template = {
|
||||||
|
key1: '{{current.key1}}',
|
||||||
|
key2: '{{current.key2}}',
|
||||||
|
};
|
||||||
|
const result = parse(template)({
|
||||||
|
current: { key1: 'value1', key2: undefined },
|
||||||
|
});
|
||||||
|
expect(result).toEqual({
|
||||||
|
key1: 'value1',
|
||||||
|
key2: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user