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

View File

@@ -5,6 +5,21 @@
"medium": "Medium", "medium": "Medium",
"low": "Low" "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": { "Index": {
"get_started": "Get Started", "get_started": "Get Started",
"demo": "Demo", "demo": "Demo",
@@ -120,20 +135,7 @@
"skipped": "Skipped", "skipped": "Skipped",
"test_classification": "Test Classification", "test_classification": "Test Classification",
"by_type": "By test type", "by_type": "By test type",
"by_priority": "By test priority", "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"
}, },
"Folders": { "Folders": {
"folder": "Folder", "folder": "Folder",
@@ -179,19 +181,6 @@
"test_case_description": "Test case description", "test_case_description": "Test case description",
"priority": "Priority", "priority": "Priority",
"type": "Type", "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", "template": "Template",
"test_detail": "Test detail", "test_detail": "Test detail",
"preconditions": "Preconditions", "preconditions": "Preconditions",
@@ -264,19 +253,6 @@
"no_cases_found": "No cases found", "no_cases_found": "No cases found",
"are_you_sure_leave": "Are you sure you want to leave the page?", "are_you_sure_leave": "Are you sure you want to leave the page?",
"type": "Type", "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", "preconditions": "Preconditions",
"expected_result": "Expected result", "expected_result": "Expected result",
"details_of_the_step": "Details of the step", "details_of_the_step": "Details of the step",

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
import { PriorityMessages } from '@/types/priority'; import { PriorityMessages } from '@/types/priority';
import CaseEditor from './CaseEditor'; import CaseEditor from './CaseEditor';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { TestTypeMessages } from '@/types/testType';
export default function Page({ export default function Page({
params, params,
@@ -24,19 +25,6 @@ export default function Page({
testCaseDescription: t('test_case_description'), testCaseDescription: t('test_case_description'),
priority: t('priority'), priority: t('priority'),
type: t('type'), 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'), template: t('template'),
testDetail: t('test_detail'), testDetail: t('test_detail'),
preconditions: t('preconditions'), preconditions: t('preconditions'),
@@ -58,6 +46,23 @@ export default function Page({
areYouSureLeave: t('are_you_sure_leave'), 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 priorityTranslation = useTranslations('Priority');
const priorityMessages: PriorityMessages = { const priorityMessages: PriorityMessages = {
critical: priorityTranslation('critical'), critical: priorityTranslation('critical'),
@@ -72,6 +77,7 @@ export default function Page({
folderId={params.folderId} folderId={params.folderId}
caseId={params.caseId} caseId={params.caseId}
messages={messages} messages={messages}
testTypeMessages={testTypeMessages}
priorityMessages={priorityMessages} priorityMessages={priorityMessages}
locale={params.locale} locale={params.locale}
/> />

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
import { ProjectHome } from './ProjectHome'; import { ProjectHome } from './ProjectHome';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { PriorityMessages } from '@/types/priority'; import { PriorityMessages } from '@/types/priority';
import { TestTypeMessages } from '@/types/testType';
export type HomeMessages = { export type HomeMessages = {
folders: string; folders: string;
@@ -15,20 +16,6 @@ export type HomeMessages = {
testClassification: string; testClassification: string;
byType: string; byType: string;
byPriority: 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 } }) { export default function Page({ params }: { params: { projectId: string } }) {
@@ -46,19 +33,23 @@ export default function Page({ params }: { params: { projectId: string } }) {
testClassification: t('test_classification'), testClassification: t('test_classification'),
byType: t('by_type'), byType: t('by_type'),
byPriority: t('by_priority'), byPriority: t('by_priority'),
other: t('other'), };
security: t('security'),
performance: t('performance'), const tt = useTranslations('Type');
accessibility: t('accessibility'), const testTypeMessages: TestTypeMessages = {
functional: t('functional'), other: tt('other'),
acceptance: t('acceptance'), security: tt('security'),
usability: t('usability'), performance: tt('performance'),
smokeSanity: t('smoke_sanity'), accessibility: tt('accessibility'),
compatibility: t('compatibility'), functional: tt('functional'),
destructive: t('destructive'), acceptance: tt('acceptance'),
regression: t('regression'), usability: tt('usability'),
automated: t('automated'), smokeSanity: tt('smoke_sanity'),
manual: t('manual'), compatibility: tt('compatibility'),
destructive: tt('destructive'),
regression: tt('regression'),
automated: tt('automated'),
manual: tt('manual'),
}; };
const pt = useTranslations('Priority'); const pt = useTranslations('Priority');
@@ -71,7 +62,12 @@ export default function Page({ params }: { params: { projectId: string } }) {
return ( 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; delete: string;
newTestCase: string; newTestCase: string;
status: string; status: string;
critical: string;
high: string;
medium: string;
low: string;
noCasesFound: string; noCasesFound: string;
caseTitle: string; caseTitle: string;
caseDescription: string; caseDescription: string;
@@ -102,19 +98,6 @@ type CaseMessages = {
description: string; description: string;
testCaseDescription: string; testCaseDescription: string;
type: 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; template: string;
testDetail: string; testDetail: string;
preconditions: string; preconditions: string;

View File

@@ -80,19 +80,6 @@ type RunMessages = {
noCasesFound: string; noCasesFound: string;
areYouSureLeave: string; areYouSureLeave: string;
type: 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; preconditions: string;
expectedResult: string; expectedResult: string;
detailsOfTheStep: 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 };