refactor: test types messages duplication

This commit is contained in:
Takeshi Kimata
2024-07-21 14:49:08 +09:00
parent 74bb379c1a
commit 1751dd69a2
11 changed files with 137 additions and 163 deletions

View File

@@ -1,3 +1,4 @@
import { TestTypeType } from '@/types/testType';
import { PriorityType } from '@/types/priority';
const roles = [{ uid: 'administrator' }, { uid: 'user' }];
@@ -18,7 +19,7 @@ const priorities: PriorityType[] = [
{ uid: 'low', color: '#94d2bd', chartColor: '#94d2bd' },
];
const testTypes = [
const testTypes: TestTypeType[] = [
{ uid: 'other', chartColor: categoricalPalette[0] },
{ uid: 'security', chartColor: categoricalPalette[1] },
{ uid: 'performance', chartColor: categoricalPalette[2] },

View File

@@ -5,6 +5,21 @@
"medium": "Medium",
"low": "Low"
},
"Type": {
"other": "Other",
"security": "Security",
"performance": "Performance",
"accessibility": "Accessibility",
"functional": "Functional",
"acceptance": "Acceptance",
"usability": "Usability",
"smoke_sanity": "Smoke&Sanity",
"compatibility": "Compatibility",
"destructive": "Destructive",
"regression": "Regression",
"automated": "Automated",
"manual": "Manual"
},
"Index": {
"get_started": "Get Started",
"demo": "Demo",
@@ -120,20 +135,7 @@
"skipped": "Skipped",
"test_classification": "Test Classification",
"by_type": "By test type",
"by_priority": "By test priority",
"other": "Other",
"security": "Security",
"performance": "Performance",
"accessibility": "Accessibility",
"functional": "Functional",
"acceptance": "Acceptance",
"usability": "Usability",
"smoke_sanity": "Smoke&Sanity",
"compatibility": "Compatibility",
"destructive": "Destructive",
"regression": "Regression",
"automated": "Automated",
"manual": "Manual"
"by_priority": "By test priority"
},
"Folders": {
"folder": "Folder",
@@ -179,19 +181,6 @@
"test_case_description": "Test case description",
"priority": "Priority",
"type": "Type",
"other": "Other",
"security": "Security",
"performance": "Performance",
"accessibility": "Accessibility",
"functional": "Functional",
"acceptance": "Acceptance",
"usability": "Usability",
"smoke_sanity": "Smoke&Sanity",
"compatibility": "Compatibility",
"destructive": "Destructive",
"regression": "Regression",
"automated": "Automated",
"manual": "Manual",
"template": "Template",
"test_detail": "Test detail",
"preconditions": "Preconditions",
@@ -264,19 +253,6 @@
"no_cases_found": "No cases found",
"are_you_sure_leave": "Are you sure you want to leave the page?",
"type": "Type",
"other": "Other",
"security": "Security",
"performance": "Performance",
"accessibility": "Accessibility",
"functional": "Functional",
"acceptance": "Acceptance",
"usability": "Usability",
"smoke_sanity": "Smoke&Sanity",
"compatibility": "Compatibility",
"destructive": "Destructive",
"regression": "Regression",
"automated": "Automated",
"manual": "Manual",
"preconditions": "Preconditions",
"expected_result": "Expected result",
"details_of_the_step": "Details of the step",

View File

@@ -6,6 +6,21 @@
"medium": "中",
"low": "低"
},
"Type": {
"other": "その他",
"security": "セキュリティ",
"performance": "パフォーマンス",
"accessibility": "アクセシビリティ",
"functional": "機能",
"acceptance": "受け入れ",
"usability": "ユーザビリティ",
"smoke_sanity": "スモーク/サニティ",
"compatibility": "互換性",
"destructive": "破壊",
"regression": "回帰",
"automated": "自動",
"manual": "手動"
},
"Index": {
"get_started": "テスト管理を始める",
"demo": "デモ",
@@ -121,20 +136,7 @@
"skipped": "スキップ",
"test_classification": "テスト分類",
"by_type": "タイプ別",
"by_priority": "優先度別",
"other": "その他",
"security": "セキュリティ",
"performance": "パフォーマンス",
"accessibility": "アクセシビリティ",
"functional": "機能",
"acceptance": "受け入れ",
"usability": "ユーザビリティ",
"smoke_sanity": "スモーク/サニティ",
"compatibility": "互換性",
"destructive": "破壊",
"regression": "回帰",
"automated": "自動",
"manual": "手動"
"by_priority": "優先度別"
},
"Folders": {
"folder": "フォルダー",
@@ -180,19 +182,6 @@
"test_case_description": "テストケース詳細",
"priority": "優先度",
"type": "タイプ",
"other": "その他",
"security": "セキュリティ",
"performance": "パフォーマンス",
"accessibility": "アクセシビリティ",
"functional": "機能",
"acceptance": "受け入れ",
"usability": "ユーザビリティ",
"smoke_sanity": "スモーク/サニティ",
"compatibility": "互換性",
"destructive": "破壊",
"regression": "回帰",
"automated": "自動",
"manual": "手動",
"template": "テンプレート",
"test_detail": "テスト詳細",
"preconditions": "前提条件",
@@ -265,19 +254,6 @@
"no_cases_found": "テストケースが見つかりません",
"are_you_sure_leave": "ページを離れてもよろしいですか",
"type": "タイプ",
"other": "その他",
"security": "セキュリティ",
"performance": "パフォーマンス",
"accessibility": "アクセシビリティ",
"functional": "機能",
"acceptance": "受け入れ",
"usability": "ユーザビリティ",
"smoke_sanity": "スモーク/サニティ",
"compatibility": "互換性",
"destructive": "破壊",
"regression": "回帰",
"automated": "自動",
"manual": "手動",
"test_detail": "テスト詳細",
"preconditions": "前提条件",
"expected_result": "期待結果",

View File

@@ -13,6 +13,7 @@ import { TokenContext } from '@/utils/TokenProvider';
import { useFormGuard } from '@/utils/formGuard';
import { CaseType, AttachmentType, CaseMessages, StepType } from '@/types/case';
import { PriorityMessages } from '@/types/priority';
import { TestTypeMessages } from '@/types/testType';
const defaultTestCase = {
id: 0,
@@ -37,11 +38,20 @@ type Props = {
folderId: string;
caseId: string;
messages: CaseMessages;
testTypeMessages: TestTypeMessages;
priorityMessages: PriorityMessages;
locale: string;
};
export default function CaseEditor({ projectId, folderId, caseId, messages, priorityMessages, locale }: Props) {
export default function CaseEditor({
projectId,
folderId,
caseId,
messages,
testTypeMessages,
priorityMessages,
locale,
}: Props) {
const context = useContext(TokenContext);
const [testCase, setTestCase] = useState<CaseType>(defaultTestCase);
const [isTitleInvalid, setIsTitleInvalid] = useState<boolean>(false);
@@ -285,7 +295,7 @@ export default function CaseEditor({ projectId, folderId, caseId, messages, prio
>
{testTypes.map((type, index) => (
<SelectItem key={type.uid} value={index}>
{messages[type.uid]}
{testTypeMessages[type.uid]}
</SelectItem>
))}
</Select>

View File

@@ -1,6 +1,7 @@
import { PriorityMessages } from '@/types/priority';
import CaseEditor from './CaseEditor';
import { useTranslations } from 'next-intl';
import { TestTypeMessages } from '@/types/testType';
export default function Page({
params,
@@ -24,19 +25,6 @@ export default function Page({
testCaseDescription: t('test_case_description'),
priority: t('priority'),
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'),
template: t('template'),
testDetail: t('test_detail'),
preconditions: t('preconditions'),
@@ -58,6 +46,23 @@ export default function Page({
areYouSureLeave: t('are_you_sure_leave'),
};
const tt = useTranslations('Type');
const testTypeMessages: TestTypeMessages = {
other: tt('other'),
security: tt('security'),
performance: tt('performance'),
accessibility: tt('accessibility'),
functional: tt('functional'),
acceptance: tt('acceptance'),
usability: tt('usability'),
smokeSanity: tt('smoke_sanity'),
compatibility: tt('compatibility'),
destructive: tt('destructive'),
regression: tt('regression'),
automated: tt('automated'),
manual: tt('manual'),
};
const priorityTranslation = useTranslations('Priority');
const priorityMessages: PriorityMessages = {
critical: priorityTranslation('critical'),
@@ -72,6 +77,7 @@ export default function Page({
folderId={params.folderId}
caseId={params.caseId}
messages={messages}
testTypeMessages={testTypeMessages}
priorityMessages={priorityMessages}
locale={params.locale}
/>

View File

@@ -8,12 +8,13 @@ import { ProgressSeriesType } from '@/types/run';
import { HomeMessages } from './page';
import { TokenContext } from '@/utils/TokenProvider';
import { aggregateBasicInfo, aggregateTestPriority, aggregateTestType, aggregateProgress } from './aggregate';
import TestTypesChart from './TestTypesDonutChart';
import TestPriorityChart from './TestPriorityDonutChart';
import TestProgressBarChart from './TestProgressColumnChart';
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';
const apiServer = Config.apiServer;
async function fetchProject(jwt: string, projectId: number) {
@@ -42,10 +43,11 @@ async function fetchProject(jwt: string, projectId: number) {
type Props = {
projectId: string;
messages: HomeMessages;
testTypeMessages: TestTypeMessages;
priorityMessages: PriorityMessages;
};
export function ProjectHome({ projectId, messages, priorityMessages }: Props) {
export function ProjectHome({ projectId, messages, testTypeMessages, priorityMessages }: Props) {
const context = useContext(TokenContext);
const { theme, setTheme } = useTheme();
const [project, setProject] = useState({
@@ -132,7 +134,7 @@ export function ProjectHome({ projectId, messages, priorityMessages }: Props) {
<div className="flex pb-20">
<div style={{ width: '32rem', height: '18rem' }}>
<h3>{messages.byType}</h3>
<TestTypesChart typesCounts={typesCounts} messages={messages} theme={theme} />
<TestTypesChart typesCounts={typesCounts} testTypeMessages={testTypeMessages} theme={theme} />
</div>
<div style={{ width: '30rem', height: '18rem' }}>
<h3>{messages.byPriority}</h3>

View File

@@ -3,16 +3,16 @@ import { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { testTypes } from '@/config/selection';
import { CaseTypeCountType } from '@/types/case';
import { HomeMessages } from './page';
import { TestTypeMessages } from '@/types/testType';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
typesCounts: CaseTypeCountType[];
messages: HomeMessages;
testTypeMessages: TestTypeMessages;
theme: string;
};
export default function TestTypesDonutChart({ typesCounts, messages, theme }: Props) {
export default function TestTypesDonutChart({ typesCounts, testTypeMessages, theme }: Props) {
const [chartData, setChartData] = useState({
series: [],
options: {
@@ -29,7 +29,7 @@ export default function TestTypesDonutChart({ typesCounts, messages, theme }: Pr
return found ? found.count : 0;
});
const labels = testTypes.map((entry) => messages[entry.uid]);
const labels = testTypes.map((entry) => testTypeMessages[entry.uid]);
const colors = testTypes.map((entry) => entry.chartColor);
const legend = {
labels: {

View File

@@ -1,6 +1,7 @@
import { ProjectHome } from './ProjectHome';
import { useTranslations } from 'next-intl';
import { PriorityMessages } from '@/types/priority';
import { TestTypeMessages } from '@/types/testType';
export type HomeMessages = {
folders: string;
@@ -15,20 +16,6 @@ export type HomeMessages = {
testClassification: string;
byType: string;
byPriority: string;
testTypes: string;
other: string;
security: string;
performance: string;
accessibility: string;
functional: string;
acceptance: string;
usability: string;
smokeSanity: string;
compatibility: string;
destructive: string;
regression: string;
automated: string;
manual: string;
};
export default function Page({ params }: { params: { projectId: string } }) {
@@ -46,19 +33,23 @@ export default function Page({ params }: { params: { projectId: string } }) {
testClassification: t('test_classification'),
byType: t('by_type'),
byPriority: t('by_priority'),
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'),
};
const tt = useTranslations('Type');
const testTypeMessages: TestTypeMessages = {
other: tt('other'),
security: tt('security'),
performance: tt('performance'),
accessibility: tt('accessibility'),
functional: tt('functional'),
acceptance: tt('acceptance'),
usability: tt('usability'),
smokeSanity: tt('smoke_sanity'),
compatibility: tt('compatibility'),
destructive: tt('destructive'),
regression: tt('regression'),
automated: tt('automated'),
manual: tt('manual'),
};
const pt = useTranslations('Priority');
@@ -71,7 +62,12 @@ export default function Page({ params }: { params: { projectId: string } }) {
return (
<>
<ProjectHome projectId={params.projectId} messages={messages} priorityMessages={priorityMessages} />
<ProjectHome
projectId={params.projectId}
messages={messages}
testTypeMessages={testTypeMessages}
priorityMessages={priorityMessages}
/>
</>
);
}

View File

@@ -81,10 +81,6 @@ type CasesMessages = {
delete: string;
newTestCase: string;
status: string;
critical: string;
high: string;
medium: string;
low: string;
noCasesFound: string;
caseTitle: string;
caseDescription: string;
@@ -102,19 +98,6 @@ type CaseMessages = {
description: string;
testCaseDescription: string;
type: string;
other: string;
security: string;
performance: string;
accessibility: string;
functional: string;
acceptance: string;
usability: string;
smokeSanity: string;
compatibility: string;
destructive: string;
regression: string;
automated: string;
manual: string;
template: string;
testDetail: string;
preconditions: string;

View File

@@ -80,19 +80,6 @@ type RunMessages = {
noCasesFound: string;
areYouSureLeave: string;
type: string;
other: string;
security: string;
performance: string;
accessibility: string;
functional: string;
acceptance: string;
usability: string;
smokeSanity: string;
compatibility: string;
destructive: string;
regression: string;
automated: string;
manual: string;
preconditions: string;
expectedResult: string;
detailsOfTheStep: string;

View File

@@ -0,0 +1,37 @@
type TestTypeUidType =
| 'other'
| 'security'
| 'performance'
| 'accessibility'
| 'functional'
| 'acceptance'
| 'usability'
| 'smokeSanity'
| 'compatibility'
| 'destructive'
| 'regression'
| 'automated'
| 'manual';
type TestTypeType = {
uid: TestTypeUidType;
chartColor: string;
};
type TestTypeMessages = {
other: string;
security: string;
performance: string;
accessibility: string;
functional: string;
acceptance: string;
usability: string;
smokeSanity: string;
compatibility: string;
destructive: string;
regression: string;
automated: string;
manual: string;
};
export type { TestTypeUidType, TestTypeType, TestTypeMessages };