Copilot commented on code in PR #40817: URL: https://github.com/apache/superset/pull/40817#discussion_r3383182113
########## superset-frontend/playwright/tests/chart/handlebars-format-date.spec.ts: ########## @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Regression for #32960: the `formatDate` Handlebars helper (provided by + * just-handlebars-helpers) stopped working after 4.1.2, rendering + * "i is not a function" (minified) / "moment is not a function" (dev) instead + * of the formatted date. The helper resolves `moment` lazily via + * `global.moment` / `require('moment/min/moment-with-locales')`, which the + * bundled HandlebarsViewer no longer satisfies (it switched to dayjs). + * + * This is a TDD validation test. It creates a Handlebars chart whose template + * uses `{{formatDate 'DD.MM.YYYY' ds}}` and asserts the chart renders a real + * formatted date rather than the helper error. + * + * CI green => formatDate works again; merging closes #32960. + * CI red => the bug is still live; the fix belongs in the Handlebars plugin + * (superset-frontend/plugins/plugin-chart-handlebars), e.g. by + * providing a moment-free formatDate or making moment resolvable. + */ +import type { Page } from '@playwright/test'; +import { testWithAssets, expect } from '../../helpers/fixtures'; +import { apiPost } from '../../helpers/api/requests'; + +const DATASET_NAME = 'birth_names'; + +async function findDatasetIdByName(page: Page, name: string): Promise<number> { + const query = `(filters:!((col:table_name,opr:eq,value:'${name}')))`; + const resp = await page.request.get(`api/v1/dataset/?q=${query}`); + const body = await resp.json(); + if (!body.result?.length) { + throw new Error(`Dataset ${name} not found`); + } + return body.result[0].id; +} + +testWithAssets( + 'Handlebars formatDate helper renders a formatted date (#32960)', + async ({ page, testAssets }) => { + const datasetId = await findDatasetIdByName(page, DATASET_NAME); Review Comment: Playwright’s per-test timeout is 30s (see `superset-frontend/playwright.config.ts`), and this spec chains several potentially slow steps (dataset lookup, chart creation, Explore navigation + query/render). Consider bumping this test’s timeout (e.g. `TIMEOUT.SLOW_TEST`) to avoid CI flakiness. While touching this area, you can also reuse the existing `getDatasetByName` helper (which uses `rison.encode(...)`) instead of duplicating the dataset lookup logic here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
