refactor(tender-details): enhance translation page tests and layout

- Updated Cypress tests for the tender translation page to improve visibility checks and streamline assertions.
- Refactored test structure to utilize a dedicated function for fetching the visible title heading.
- Adjusted test cases to ensure accurate language switching and URL handling for tender details.
- Improved layout consistency in the translation page by refining element visibility checks and ensuring proper section rendering.
This commit is contained in:
AmirReza Jamali
2026-05-11 16:11:09 +03:30
parent 283aa9385e
commit f397158a29
36 changed files with 1325 additions and 854 deletions
@@ -8,6 +8,110 @@ import { useIsMutating } from "@tanstack/react-query";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
const COMMA_SEPARATED_FILTER_KEYS = new Set([
"country_codes",
"notice_types",
"form_types",
"classifications",
"cpv_codes",
]);
const normalizeFilterValues = (values: Record<string, any>) => {
const normalized: Record<string, any> = {};
for (const [key, value] of Object.entries(values)) {
if (value === undefined || value === null) {
continue;
}
if (typeof value === "string") {
const trimmedValue = value.trim();
if (!trimmedValue) {
continue;
}
if (COMMA_SEPARATED_FILTER_KEYS.has(key)) {
normalized[key] = trimmedValue
.split(",")
.map((item) => item.trim())
.filter(Boolean)
.join(",");
continue;
}
normalized[key] = trimmedValue;
continue;
}
normalized[key] = value;
}
return normalized;
};
const mapDateRangeFilters = (values: Record<string, any>) => {
const mappedValues = { ...values };
const mapRange = ({
key,
fromKey,
toKey,
aliases = [],
}: {
key: string;
fromKey: string;
toKey: string;
aliases?: Array<{ from: string; to: string }>;
}) => {
const rangeValue = mappedValues[key];
if (!Array.isArray(rangeValue)) {
return;
}
const [from, to] = rangeValue;
if (from !== undefined && from !== null && from !== "") {
mappedValues[fromKey] = from;
aliases.forEach((alias) => {
mappedValues[alias.from] = from;
});
}
if (to !== undefined && to !== null && to !== "") {
mappedValues[toKey] = to;
aliases.forEach((alias) => {
mappedValues[alias.to] = to;
});
}
delete mappedValues[key];
};
mapRange({
key: "created_at_range",
fromKey: "created_at_from",
toKey: "created_at_to",
});
mapRange({
key: "tender_deadline_range",
fromKey: "tender_deadline_from",
toKey: "tender_deadline_to",
aliases: [{ from: "deadline_from", to: "deadline_to" }],
});
mapRange({
key: "publication_date_range",
fromKey: "publication_date_from",
toKey: "publication_date_to",
});
mapRange({
key: "submission_deadline_range",
fromKey: "submission_deadline_from",
toKey: "submission_deadline_to",
aliases: [{ from: "submission_date_from", to: "submission_date_to" }],
});
return mappedValues;
};
const useTenderListPresenter = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [isFilterModalOpen, setIsFilterModalOpen] = useState(false);
@@ -27,6 +131,7 @@ const useTenderListPresenter = () => {
reset: filterFormReset,
watch,
setValue: setFilterValue,
control,
} = useForm();
useEffect(() => {
@@ -48,7 +153,9 @@ const useTenderListPresenter = () => {
!isPending && (data?.meta?.pages ?? 1) * (data?.meta?.limit ?? 10) > 10;
const search = (data: any) => {
const newParams = { ...params, ...data, offset: 0 };
const mappedDateRanges = mapDateRangeFilters(data);
const normalizedData = normalizeFilterValues(mappedDateRanges);
const newParams = { ...params, ...normalizedData, offset: 0 };
const cleanedParams = deleteEmptyKeys(newParams);
const queryString = new URLSearchParams(cleanedParams).toString();
router.push(`${pathName}?${queryString}`);
@@ -88,6 +195,7 @@ const useTenderListPresenter = () => {
search,
watch,
setFilterValue,
control,
isMutating,
shouldShowPagination,
};