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

@@ -10,11 +10,13 @@ import { TokenContext } from '@/utils/TokenProvider';
import { aggregateBasicInfo, aggregateTestPriority, aggregateTestType, aggregateProgress } from './aggregate';
import Config from '@/config/config';
import { useTheme } from 'next-themes';
import { PriorityMessages } from '@/types/priority';
import { TestTypeMessages } from '@/types/testType';
import TestTypesChart from './TestTypesDonutChart';
import TestPriorityChart from './TestPriorityDonutChart';
import TestProgressBarChart from './TestProgressColumnChart';
import { TestStatusMessages } from '@/types/testStatus';
import { TestTypeMessages } from '@/types/testType';
import { PriorityMessages } from '@/types/priority';
const apiServer = Config.apiServer;
async function fetchProject(jwt: string, projectId: number) {
@@ -43,11 +45,12 @@ async function fetchProject(jwt: string, projectId: number) {
type Props = {
projectId: string;
messages: HomeMessages;
statusMessages: TestStatusMessages;
testTypeMessages: TestTypeMessages;
priorityMessages: PriorityMessages;
};
export function ProjectHome({ projectId, messages, testTypeMessages, priorityMessages }: Props) {
export function ProjectHome({ projectId, messages, statusMessages, testTypeMessages, priorityMessages }: Props) {
const context = useContext(TokenContext);
const { theme, setTheme } = useTheme();
const [project, setProject] = useState({
@@ -71,7 +74,7 @@ export function ProjectHome({ projectId, messages, testTypeMessages, priorityMes
}
try {
const data = await fetchProject(context.token.access_token, projectId);
const data = await fetchProject(context.token.access_token, Number(projectId));
setProject(data);
} catch (error: any) {
console.error('Error in effect:', error.message);
@@ -94,7 +97,7 @@ export function ProjectHome({ projectId, messages, testTypeMessages, priorityMes
const priorityRet = aggregateTestPriority(project);
setPriorityCounts([...priorityRet]);
const { series, categories } = aggregateProgress(project, messages);
const { series, categories } = aggregateProgress(project, statusMessages);
setProgressSeries([...series]);
setProgressCategories([...categories]);
}

View File

@@ -1,6 +1,6 @@
import { ProjectType } from '@/types/project';
import { testTypes, priorities, testRunCaseStatus } from '@/config/selection';
import { HomeMessages } from './page';
import { TestStatusMessages } from '@/types/testStatus';
// aggregate folder, case, run mum
function aggregateBasicInfo(project: ProjectType) {
@@ -50,9 +50,9 @@ function aggregateTestPriority(project: ProjectType) {
return result;
}
function aggregateProgress(project: ProjectType, messages: HomeMessages) {
function aggregateProgress(project: ProjectType, statusMessages: TestStatusMessages) {
let series = testRunCaseStatus.map((status) => {
return { name: messages[status.uid], data: [] };
return { name: statusMessages[status.uid], data: [] };
});
let categories = [];

View File

@@ -2,17 +2,13 @@ import { ProjectHome } from './ProjectHome';
import { useTranslations } from 'next-intl';
import { PriorityMessages } from '@/types/priority';
import { TestTypeMessages } from '@/types/testType';
import { TestStatusMessages } from '@/types/testStatus';
export type HomeMessages = {
folders: string;
testCases: string;
testRuns: string;
progress: string;
untested: string;
passed: string;
failed: string;
retest: string;
skipped: string;
testClassification: string;
byType: string;
byPriority: string;
@@ -25,16 +21,20 @@ export default function Page({ params }: { params: { projectId: string } }) {
testCases: t('test_cases'),
testRuns: t('test_runs'),
progress: t('progress'),
untested: t('untested'),
passed: t('passed'),
failed: t('failed'),
retest: t('retest'),
skipped: t('skipped'),
testClassification: t('test_classification'),
byType: t('by_type'),
byPriority: t('by_priority'),
};
const st = useTranslations('Status');
const statusMessages: TestStatusMessages = {
untested: st('untested'),
passed: st('passed'),
failed: st('failed'),
retest: st('retest'),
skipped: st('skipped'),
};
const tt = useTranslations('Type');
const testTypeMessages: TestTypeMessages = {
other: tt('other'),
@@ -65,6 +65,7 @@ export default function Page({ params }: { params: { projectId: string } }) {
<ProjectHome
projectId={params.projectId}
messages={messages}
statusMessages={statusMessages}
testTypeMessages={testTypeMessages}
priorityMessages={priorityMessages}
/>