refactor: test run case status messages duplication

This commit is contained in:
Takeshi Kimata
2024-07-21 15:16:40 +09:00
parent 1751dd69a2
commit f797ae2581
11 changed files with 92 additions and 76 deletions

View File

@@ -38,6 +38,7 @@ import { TokenContext } from '@/utils/TokenProvider';
import { useTheme } from 'next-themes';
import { useFormGuard } from '@/utils/formGuard';
import { PriorityMessages } from '@/types/priority';
import { TestStatusMessages } from '@/types/testStatus';
const defaultTestRun = {
id: 0,
@@ -54,11 +55,12 @@ type Props = {
projectId: string;
runId: string;
messages: RunMessages;
statusMessages: TestStatusMessages;
priorityMessages: PriorityMessages;
locale: string;
};
export default function RunEditor({ projectId, runId, messages, priorityMessages, locale }: Props) {
export default function RunEditor({ projectId, runId, messages, statusMessages, priorityMessages, locale }: Props) {
const context = useContext(TokenContext);
const { theme, setTheme } = useTheme();
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
@@ -204,7 +206,7 @@ export default function RunEditor({ projectId, runId, messages, priorityMessages
</Tooltip>
</div>
<RunProgressChart statusCounts={runStatusCounts} messages={messages} theme={theme} />
<RunProgressChart statusCounts={runStatusCounts} statusMessages={statusMessages} theme={theme} />
</div>
</div>
<div className="flex-grow">
@@ -316,6 +318,7 @@ export default function RunEditor({ projectId, runId, messages, priorityMessages
onIncludeCase={(includeTestId) => handleIncludeExcludeCase(true, includeTestId)}
onExcludeCase={(excludeCaseId) => handleIncludeExcludeCase(false, excludeCaseId)}
messages={messages}
statusMessages={statusMessages}
priorityMessages={priorityMessages}
/>
</div>

View File

@@ -2,16 +2,17 @@ import React from 'react';
import { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { testRunCaseStatus } from '@/config/selection';
import { RunStatusCountType, RunMessages } from '@/types/run';
import { RunStatusCountType } from '@/types/run';
import { TestStatusMessages } from '@/types/testStatus';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
statusCounts: RunStatusCountType[];
messages: RunMessages;
statusMessages: TestStatusMessages;
theme: string | undefined;
};
export default function RunProgressDounut({ statusCounts, messages, theme }: Props) {
export default function RunProgressDounut({ statusCounts, statusMessages, theme }: Props) {
const [chartData, setChartData] = useState({
series: [],
options: {
@@ -28,7 +29,7 @@ export default function RunProgressDounut({ statusCounts, messages, theme }: Pro
return found ? found.count : 0;
});
const labels = testRunCaseStatus.map((entry) => messages[entry.uid]);
const labels = testRunCaseStatus.map((entry) => statusMessages[entry.uid]);
const colors = testRunCaseStatus.map((entry) => entry.chartColor);
const legend = {
labels: {

View File

@@ -32,6 +32,7 @@ import { RunMessages } from '@/types/run';
import TestCaseDetailDialog from './TestCaseDetailDialog';
import { PriorityMessages } from '@/types/priority';
import TestCasePriority from '@/components/TestCasePriority';
import { TestStatusMessages } from '@/types/testStatus';
type Props = {
cases: CaseType[];
@@ -42,6 +43,7 @@ type Props = {
onIncludeCase: (includeCaseId: number) => {};
onExcludeCase: (excludeCaseId: number) => {};
messages: RunMessages;
statusMessages: TestStatusMessages;
priorityMessages: PriorityMessages;
};
@@ -54,6 +56,7 @@ export default function TestCaseSelector({
onIncludeCase,
onExcludeCase,
messages,
statusMessages,
priorityMessages,
}: Props) {
const headerColumns = [
@@ -157,7 +160,7 @@ export default function TestCaseSelector({
startContent={isIncluded && renderStatusIcon(testRunCaseStatus[runStatus].uid)}
endContent={isIncluded && <ChevronDown size={16} />}
>
<span className="w-12">{isIncluded && messages[testRunCaseStatus[runStatus].uid]}</span>
<span className="w-12">{isIncluded && statusMessages[testRunCaseStatus[runStatus].uid]}</span>
</Button>
</DropdownTrigger>
<DropdownMenu disabledKeys={disabledStatusKeys} aria-label="test case actions">
@@ -167,7 +170,7 @@ export default function TestCaseSelector({
startContent={renderStatusIcon(runCaseStatus.uid)}
onPress={() => onChangeStatus(testCase.id, index)}
>
{messages[runCaseStatus.uid]}
{statusMessages[runCaseStatus.uid]}
</DropdownItem>
))}
</DropdownMenu>

View File

@@ -2,6 +2,7 @@ import RunEditor from './RunEditor';
import { useTranslations } from 'next-intl';
import { RunMessages } from '@/types/run';
import { PriorityMessages } from '@/types/priority';
import { TestStatusMessages } from '@/types/testStatus';
export default function Page({ params }: { params: { projectId: string; runId: string; locale: string } }) {
const t = useTranslations('Run');
@@ -24,11 +25,6 @@ export default function Page({ params }: { params: { projectId: string; runId: s
priority: t('priority'),
actions: t('actions'),
status: t('status'),
untested: t('untested'),
passed: t('passed'),
failed: t('failed'),
retest: t('retest'),
skipped: t('skipped'),
selectTestCase: t('select_test_case'),
testCaseSelection: t('test_case_selection'),
includeInRun: t('include_in_run'),
@@ -36,25 +32,21 @@ export default function Page({ params }: { params: { projectId: string; runId: s
noCasesFound: t('no_cases_found'),
areYouSureLeave: t('are_you_sure_leave'),
type: t('type'),
other: t('other'),
security: t('security'),
performance: t('performance'),
accessibility: t('accessibility'),
functional: t('functional'),
acceptance: t('acceptance'),
usability: t('usability'),
smokeSanity: t('smoke_sanity'),
compatibility: t('compatibility'),
destructive: t('destructive'),
regression: t('regression'),
automated: t('automated'),
manual: t('manual'),
preconditions: t('preconditions'),
expectedResult: t('expected_result'),
detailsOfTheStep: t('details_of_the_step'),
close: t('close'),
};
const st = useTranslations('Status');
const statusMessages: TestStatusMessages = {
untested: st('untested'),
passed: st('passed'),
failed: st('failed'),
retest: st('retest'),
skipped: st('skipped'),
};
const pt = useTranslations('Priority');
const priorityMessages: PriorityMessages = {
critical: pt('critical'),
@@ -68,6 +60,7 @@ export default function Page({ params }: { params: { projectId: string; runId: s
projectId={params.projectId}
runId={params.runId}
messages={messages}
statusMessages={statusMessages}
priorityMessages={priorityMessages}
locale={params.locale}
/>