Skip to content

Commit

Permalink
Add strich type check to web-awesome (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw authored Jan 20, 2025
1 parent 507a79d commit 4a12413
Show file tree
Hide file tree
Showing 68 changed files with 496 additions and 1,202 deletions.
607 changes: 113 additions & 494 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion packages/core-api/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,5 @@ export type AttachmentLink = AttachmentLinkFile | AttachmentLinkExpected | Attac

export interface AttachmentTestStepResult {
link: AttachmentLinkExpected | AttachmentLinkLinked | AttachmentLinkInvalid;

type: "attachment";
}
4 changes: 3 additions & 1 deletion packages/core-api/src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ const times: DurationField[] = [
},
];

export const formatDuration = (duration: number | undefined): string => {
export const formatDuration = (duration?: number): string => {
if (duration === undefined) {
return "unknown";
}

if (duration < 0.5) {
return "0s";
}

const res: string[] = [];

for (const { accessor, suffix } of times) {
const value = accessor(duration);
if (res.length === 0 && !value) {
Expand Down
1 change: 1 addition & 0 deletions packages/web-awesome/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"eslint-plugin-react": "^7.36.1",
"eslint-plugin-react-hooks": "^4.6.2",
"filesize": "^10.1.6",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"globals": "^15.9.0",
"html-webpack-plugin": "^5.6.3",
"mini-css-extract-plugin": "^2.9.1",
Expand Down
12 changes: 10 additions & 2 deletions packages/web-awesome/src/components/BaseLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { fetchTestResult, fetchTestResultNav, testResultStore } from "@/stores/t
import { fetchTreeData, treeStore } from "@/stores/tree";
import * as styles from "./styles.scss";

export const BaseLayout = ({ testResultId }) => {
export type BaseLayoutProps = {
testResultId?: string;
};

export const BaseLayout = ({ testResultId }: BaseLayoutProps) => {
useEffect(() => {
getTheme();
getLocale();
Expand All @@ -23,7 +27,11 @@ export const BaseLayout = ({ testResultId }) => {
fetchTestResult(testResultId);
fetchTestResultNav();
} else {
Promise.all([ensureReportDataReady(), fetchStats(), fetchPieChartData(), fetchTreeData(), fetchEnvInfo()]);
ensureReportDataReady();
fetchStats();
fetchPieChartData();
fetchTreeData();
fetchEnvInfo();
}
}, [testResultId]);

Expand Down
5 changes: 2 additions & 3 deletions packages/web-awesome/src/components/LanguagePicker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { DropdownButton } from "@allurereport/web-components";
import { Menu } from "@allurereport/web-components";
import { DropdownButton, Menu } from "@allurereport/web-components";
import { LANG_LOCALE, type LangLocale } from "@/i18n/constants";
import { currentLocale } from "@/stores";
import { setLocale } from "@/stores/locale";

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const langPickerOptions = Object.entries(LANG_LOCALE).map(([key, { full }]) => ({
key: key as LangLocale,
value: full,
}));

export const LanguagePicker = () => {
const locale = currentLocale.value;

const handleSelect = (selectedOption: LangLocale) => {
setLocale(selectedOption);
};
Expand Down
19 changes: 13 additions & 6 deletions packages/web-awesome/src/components/Metadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useI18n } from "@/stores/locale";
import { copyToClipboard } from "@/utils/copyToClipboard";
import * as styles from "./styles.scss";

const { t } = useI18n("ui");
export const MetadataList: FunctionalComponent<MetadataProps & { columns?: number }> = ({
envInfo,
size = "m",
Expand All @@ -19,8 +18,8 @@ export const MetadataList: FunctionalComponent<MetadataProps & { columns?: numbe
class={styles["report-metadata-list"]}
style={{ gridTemplateColumns: `repeat(${columns}, ${100 / columns - 5}%)` }}
>
{envInfo?.map((envInfo) => (
<MetadataKeyValue size={size} title={envInfo.name} value={envInfo.value} values={envInfo.values} />
{envInfo?.map(({ name, values, value }) => (
<MetadataKeyValue key={name} size={size} title={name} value={value} values={values} />
))}
</div>
);
Expand All @@ -30,23 +29,30 @@ export const TestResultMetadataList: FunctionalComponent<MetadataProps> = ({ gro
return (
<div class={styles["report-metadata-list"]}>
{groupedLabels &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Object.entries(groupedLabels)?.map(([name, values]) => (
<MetadataKeyValue size={size} title={name} values={values} />
<MetadataKeyValue key={name} size={size} title={name} values={values} />
))}
</div>
);
};

export const Metadata: FunctionalComponent<MetadataProps> = ({ envInfo }) => {
const { t } = useI18n("ui");
const [isOpened, setIsOpen] = useState(true);

return (
<div class={styles["report-metadata"]}>
<MetadataButton isOpened={isOpened} setIsOpen={setIsOpen} counter={envInfo.length} title={t("metadata")} />
{isOpened && <MetadataList envInfo={envInfo} />}
</div>
);
};
const MetadataTooltip = ({ value }) => {

const MetadataTooltip = (props: { value: string }) => {
const { value } = props;
const { t } = useI18n("ui");

return (
<div className={styles["metadata-tooltip"]}>
<div className={styles["metadata-tooltip-value"]}>
Expand All @@ -61,6 +67,7 @@ const MetadataTooltip = ({ value }) => {
</div>
);
};

const MetaDataKeyLabel: FunctionalComponent<{
size?: "s" | "m";
value: string;
Expand Down Expand Up @@ -101,7 +108,7 @@ const MetadataKeyValue: FunctionalComponent<{
{values?.length ? (
<div className={styles["report-metadata-values"]}>
{values.map((item) => (
<MetaDataKeyLabel value={item} />
<MetaDataKeyLabel key={item} value={item} />
))}
</div>
) : (
Expand Down
9 changes: 3 additions & 6 deletions packages/web-awesome/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const closeModal = () => {
isModalOpen.value = false;
};

const ModalThumb = ({ item, children }) => {
const ModalThumb: FunctionalComponent<{ item: AttachmentTestStepResult }> = ({ item, children }) => {
const isActiveThumb = modalData.value.data?.link?.id === item.link?.id;

const showAttach = (showedItem: AttachmentTestStepResult) => {
Expand All @@ -47,10 +47,7 @@ const ModalThumb = ({ item, children }) => {
};

return (
<div
className={`${styles["modal-thumb"]} ${isActiveThumb ? styles.active : ""}`}
onClick={() => showAttach(item as AttachmentTestStepResult)}
>
<div className={`${styles["modal-thumb"]} ${isActiveThumb ? styles.active : ""}`} onClick={() => showAttach(item)}>
{children}
</div>
);
Expand Down Expand Up @@ -129,7 +126,7 @@ const Modal: FunctionalComponent<ModalProps> = ({ testResult }) => {
<Button
style={"outline"}
onClick={openInNewWindow}
icon={allureIcons.LineGeneralLinkExternal}
icon={allureIcons.lineGeneralLinkExternal}
text={"Open in new tab"}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { Statistic } from "@allurereport/core-api";
import { statusesList } from "@allurereport/core-api";
import { type Statistic, statusesList } from "@allurereport/core-api";
import { Loadable } from "@allurereport/web-components";
import { computed } from "@preact/signals";
import type { FunctionComponent } from "preact";
import type { MetadataProps } from "@/components/ReportMetadata/MetadataItem";
import MetadataItem from "@/components/ReportMetadata/MetadataItem";
import MetadataItem, { type MetadataProps } from "@/components/ReportMetadata/MetadataItem";
import { MetadataTestType } from "@/components/ReportMetadata/MetadataTestType";
import { MetadataWithIcon } from "@/components/ReportMetadata/MetadataWithIcon";
import * as styles from "@/components/ReportMetadata/styles.scss";
Expand All @@ -28,11 +26,11 @@ export const MetadataSummary: FunctionComponent = () => {
}));
const metaDataTests = ["flaky", "retry"]
.map((key) => {
if (!stats[key]) {
if (!stats[key as keyof Statistic]) {
return;
}
const title = testSummary(key);
const props = { title, count: stats[key] || 0, type: key };
const props = { title, count: stats[key as keyof Statistic] || 0, type: key };

return (
<div key={key}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { SvgIcon, allureIcons } from "@allurereport/web-components";
import { Text } from "@allurereport/web-components";
import { SvgIcon, Text, allureIcons } from "@allurereport/web-components";
import type { FunctionComponent } from "preact";
import { h } from "preact";
import type { MetadataProps } from "@/components/ReportMetadata/MetadataItem";
import * as styles from "./styles.scss";

const icons = {
const icons: Record<string, string> = {
flaky: allureIcons.lineGeneralZap,
retry: allureIcons.lineArrowsRefreshCcw1,
new: allureIcons.lineAlertsNotificationBox,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Counter, allureIcons } from "@allurereport/web-components";
import { SvgIcon } from "@allurereport/web-components";
import { Text } from "@allurereport/web-components";
import { Counter, SvgIcon, Text, allureIcons } from "@allurereport/web-components";
import { type FunctionalComponent } from "preact";
import { ArrowButton } from "@/components/ArrowButton";
import * as styles from "./styles.scss";

export const TestResultDropdown = ({ isOpened, setIsOpen, title, icon, counter }) => {
export const TestResultDropdown: FunctionalComponent<{
isOpened: boolean;
setIsOpen: (isOpened: boolean) => void;
title: string;
icon: string;
counter: number;
}> = ({ isOpened, setIsOpen, title, icon, counter }) => {
return (
<div className={styles["test-result-dropdown"]} onClick={() => setIsOpen(!isOpened)}>
<ArrowButton isOpened={isOpened} icon={allureIcons.arrowsChevronDown} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Code, IconButton, Text, TooltipWrapper, allureIcons } from "@allurereport/web-components";
import { type FunctionalComponent } from "preact";
import { useState } from "preact/hooks";
import { useI18n } from "@/stores/locale";
import { copyToClipboard } from "@/utils/copyToClipboard";
Expand All @@ -14,7 +15,7 @@ const TestResultErrorTrace = ({ trace }: { trace: string }) => {
);
};

export const TestResultError = ({ message, trace }) => {
export const TestResultError: FunctionalComponent<{ message: string; trace: string }> = ({ message, trace }) => {
const [isOpen, setIsOpen] = useState(false);
const { t } = useI18n("ui");
const { t: tooltip } = useI18n("controls");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { formatDuration } from "@allurereport/core-api";
import { IconButton, allureIcons } from "@allurereport/web-components";
import { TooltipWrapper } from "@allurereport/web-components";
import { Text } from "@allurereport/web-components";
import { type HistoryTestResult, formatDuration } from "@allurereport/core-api";
import { IconButton, Text, TooltipWrapper, allureIcons } from "@allurereport/web-components";
import { type FunctionalComponent } from "preact";
import { useState } from "preact/hooks";
import { ArrowButton } from "@/components/ArrowButton";
import { TestResultError } from "@/components/TestResult/TestResultError";
Expand All @@ -11,7 +10,9 @@ import { navigateTo, openInNewTab } from "@/index";
import { useI18n } from "@/stores";
import { timestampToDate } from "@/utils/time";

export const TestResultHistoryItem = ({ testResultItem }) => {
export const TestResultHistoryItem: FunctionalComponent<{
testResultItem: HistoryTestResult;
}> = ({ testResultItem }) => {
const { status, message, trace, stop, duration, id } = testResultItem;
const [isOpened, setIsOpen] = useState(false);
const convertedStop = timestampToDate(stop);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FunctionalComponent } from "preact";
import type { AllureAwesomeTestResult } from "types";
import { TestResultHistoryItem } from "@/components/TestResult/TestResultHistory/TestResultHistoryItem";
import { useI18n } from "@/stores";
import { type AllureAwesomeTestResult } from "../../../../types";
import * as styles from "./styles.scss";

export type TestResultHistoryViewProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { SvgIcon, allureIcons } from "@allurereport/web-components";
import { type FunctionalComponent } from "preact";
import { useI18n } from "@/stores";
import { capitalize } from "@/utils/capitalize";
import * as styles from "./styles.scss";

const icons = {
const icons: Record<string, string> = {
flaky: allureIcons.lineIconBomb2,
known: allureIcons.lineAlertsAlertCircle,
muted: allureIcons.lineGeneralEye,
};

export const TestResultInfoStatuses = ({ statuses }) => {
export const TestResultInfoStatuses: FunctionalComponent<{ statuses: [string, boolean][] }> = ({ statuses }) => {
const { t } = useI18n("filters");

return (
<div className={styles["test-result-info-statuses"]}>
{statuses.map(([status], key: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type TestResultInfoProps = {

export const TestResultInfo: FunctionalComponent<TestResultInfoProps> = ({ testResult }) => {
const { name, status, muted, flaky, known, duration, labels, history, retries, attachments, stop } = testResult ?? {};
const formattedDuration = formatDuration(duration);
const formattedDuration = formatDuration(duration as number);
const fullDate = stop && timestampToDate(stop);
const severity = labels?.find((label) => label.name === "severity")?.value ?? "normal";
const { t } = useI18n("ui");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SvgIcon, allureIcons } from "@allurereport/web-components";
import { Text } from "@allurereport/web-components";
import { SvgIcon, Text, allureIcons } from "@allurereport/web-components";
import type { FunctionalComponent } from "preact";
import { useState } from "preact/hooks";
import type { AllureAwesomeTestResult } from "types";
Expand All @@ -13,20 +12,21 @@ interface TestResultLinkProps {
type: string;
}

const linksIconMap: Record<string, string> = {
issue: allureIcons.lineDevBug2,
link: allureIcons.lineGeneralLink1,
tms: allureIcons.lineGeneralChecklist3,
github: allureIcons.github,
};

const TestResultLink: FunctionalComponent<{
link: TestResultLinkProps;
}> = ({ link }) => {
const { url, type } = link;
const iconMap = {
issue: allureIcons.lineDevBug2,
link: allureIcons.lineGeneralLink1,
tms: allureIcons.lineGeneralChecklist3,
github: allureIcons.github,
};

return (
<div className={styles["test-result-link"]}>
<SvgIcon id={iconMap[type] ?? allureIcons.lineGeneralLink1} />
<SvgIcon id={linksIconMap[type] ?? allureIcons.lineGeneralLink1} />
<Text tag={"a"} href={url} target={"_blank"} size={"m"} className={styles["test-result-link-text"]}>
{url}
</Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type HistoryTestResult } from "@allurereport/core-api";
import { SvgIcon, Text, TooltipWrapper, allureIcons } from "@allurereport/web-components";
import type { FunctionalComponent } from "preact";
import type { AllureAwesomeTestResult } from "types";
Expand All @@ -7,14 +8,14 @@ import { capitalize } from "@/utils/capitalize";
import { timestampToDate } from "@/utils/time";
import * as styles from "./styles.scss";

const TestResultPrevStatus = ({ item }) => {
const TestResultPrevStatus: FunctionalComponent<{ item: HistoryTestResult }> = ({ item }) => {
return (
<div className={styles["test-result-prev-status"]} onClick={() => navigateTo(`testresult/${item.id}`)}>
<SvgIcon id={allureIcons.lineShapesDotCircle} className={styles[`status-${item?.status}`]} />
</div>
);
};
const TestResultPrevStatusTooltip = ({ item }) => {
const TestResultPrevStatusTooltip: FunctionalComponent<{ item: HistoryTestResult }> = ({ item }) => {
const convertedStop = item.stop && timestampToDate(item.stop);
const { t } = useI18n("statuses");
const status = t(item.status);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatDuration } from "@allurereport/core-api";
import { IconButton, allureIcons } from "@allurereport/web-components";
import { Text } from "@allurereport/web-components";
import { type TestResult, formatDuration } from "@allurereport/core-api";
import { IconButton, Text, allureIcons } from "@allurereport/web-components";
import { type FunctionalComponent } from "preact";
import { useState } from "preact/hooks";
import { ArrowButton } from "@/components/ArrowButton";
import { TestResultError } from "@/components/TestResult/TestResultError";
Expand All @@ -9,11 +9,13 @@ import TreeItemIcon from "@/components/Tree/TreeItemIcon";
import { navigateTo } from "@/index";
import { timestampToDate } from "@/utils/time";

export const TestResultRetriesItem = ({ testResultItem }) => {
export const TestResultRetriesItem: FunctionalComponent<{
testResultItem: TestResult;
}> = ({ testResultItem }) => {
const { id, status, message, trace, stop, duration } = testResultItem;
const [isOpened, setIsOpen] = useState(false);
const convertedStop = timestampToDate(stop);
const formattedDuration = formatDuration(duration);
const formattedDuration = formatDuration(duration as number);
const navigateUrl = `/testresult/${id}`;

return (
Expand Down
Loading

0 comments on commit 4a12413

Please sign in to comment.