Fix timetable timezone tests

This commit is contained in:
2026-08-28 02:56:48 +01:00
parent 3de0e89e94
commit aa07a78912
+19 -17
View File
@@ -6,6 +6,7 @@ const vm = require('node:vm');
function loadScheduleModule(overrides) {
const timeDatePlaceholdersScript = fs.readFileSync(require.resolve('../src/web/public/js/shared/time-date-placeholders.js'), 'utf8');
const placeholderScript = fs.readFileSync(require.resolve('../src/web/public/js/shared/placeholder-utils.js'), 'utf8');
const placeholderInfoScript = fs.readFileSync(require.resolve('../src/web/public/js/shared/placeholder-info.js'), 'utf8');
const scriptPath = require.resolve('../src/web/public/js/regions/type/timetable.js');
const script = fs.readFileSync(scriptPath, 'utf8');
const registry = new Map();
@@ -74,6 +75,7 @@ function loadScheduleModule(overrides) {
vm.runInNewContext(timeDatePlaceholdersScript, sandbox, { filename: 'time-date-placeholders.js' });
vm.runInNewContext(placeholderScript, sandbox, { filename: 'placeholder-utils.js' });
vm.runInNewContext(placeholderInfoScript, sandbox, { filename: 'placeholder-info.js' });
if (customWindow.placeholderUtils) {
sandbox.window.placeholderUtils = customWindow.placeholderUtils;
}
@@ -101,9 +103,9 @@ test('timetable region editor lists timezone transforms in helper text', () => {
]
});
assert.match(html, /Placeholder values support transforms/);
assert.match(html, /<code>\{\{start\.tz\(\)\}\}<\/code>/);
assert.match(html, /<code>\{\{start\.tz_long\(\)\}\}<\/code>/);
assert.match(html, /Timetable placeholder transforms/);
assert.match(html, /<dt class="fw-normal"><code>tz\(\)<\/code>/);
assert.match(html, /<dt class="fw-normal"><code>tz_long\(\)<\/code>/);
assert.doesNotMatch(html, /class="chip">\{\{start\.tz\(\)\}\}<\/span>/);
});
@@ -127,17 +129,17 @@ test('timetable region editor shows supported date format tokens', () => {
]
});
assert.match(html, /Supported date format tokens/);
assert.match(html, /<th scope="col">Format<\/th>/);
assert.ok(html.indexOf('<td><code>D</code></td><td>1-31</td><td>The day of the month</td>') < html.indexOf('<td><code>ddd</code></td><td>Mon</td><td>The abbreviated weekday name</td>'));
assert.ok(html.indexOf('<td><code>ddd</code></td><td>Mon</td><td>The abbreviated weekday name</td>') < html.indexOf('<td><code>M</code></td><td>1-12</td><td>The month, beginning at 1</td>'));
assert.ok(html.indexOf('<td><code>YY</code></td><td>18</td><td>The two-digit year</td>') < html.indexOf('<td><code>YYYY</code></td><td>2018</td><td>The four-digit year</td>'));
assert.doesNotMatch(html, /<td><code>y<\/code><\/td>/);
assert.doesNotMatch(html, /<td><code>yyyy<\/code><\/td>/);
assert.doesNotMatch(html, /<td><code>yy<\/code><\/td>/);
assert.match(html, /Date format tokens/);
assert.match(html, /<th>Token<\/th><th>Meaning<\/th><th>Example<\/th>/);
assert.match(html, /<tr><td><code>D<\/code><\/td><td>Day number<\/td><td><code>16<\/code><\/td><\/tr>/);
assert.match(html, /<tr><td><code>YYYY<\/code><\/td><td>Four-digit year<\/td><td><code>2026<\/code><\/td><\/tr>/);
assert.match(html, /Date format tokens/);
assert.match(html, /<th>Token<\/th><th>Meaning<\/th><th>Example<\/th>/);
assert.match(html, /<tr><td><code>D<\/code><\/td><td>Day number<\/td><td><code>16<\/code><\/td><\/tr>/);
assert.match(html, /<tr><td><code>YYYY<\/code><\/td><td>Four-digit year<\/td><td><code>2026<\/code><\/td><\/tr>/);
assert.doesNotMatch(html, /<td><code>tz<\/code><\/td>/);
assert.match(html, /start\.tz_long\(\)/);
assert.match(html, /Use these tokens inside <code>\.format\(\.\.\.\)<\/code>/);
assert.match(html, /Use <code>tz\(\)<\/code> for a short timezone name and <code>tz_long\(\)<\/code> for the full timezone name/);
assert.match(html, /Use <code>tz\(\)<\/code> for a short timezone name and <code>tz_long\(\)<\/code> for the full timezone name/);
});
test('timetable region preview resolves timezone placeholders from explicit timezone transforms', () => {
@@ -161,8 +163,8 @@ test('timetable region preview resolves timezone placeholders from explicit time
id: 101,
title: 'Launch',
short_description: 'Doors open',
start_datetime: '2026-08-20T10:00:00.000Z',
end_datetime: '2026-08-20T11:00:00.000Z'
start_datetime: '2099-08-20T10:00:00.000Z',
end_datetime: '2099-08-20T11:00:00.000Z'
}
]
}
@@ -281,8 +283,8 @@ test('timetable preview does not force the group timezone into placeholder trans
id: 101,
title: 'Launch',
short_description: 'Doors open',
start_datetime: '2026-08-20T10:00:00.000Z',
end_datetime: '2026-08-20T11:00:00.000Z'
start_datetime: '2099-08-20T10:00:00.000Z',
end_datetime: '2099-08-20T11:00:00.000Z'
}
]
}