Skip to content

Commit

Permalink
feat: ✨ enhanced the Error card with icons
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Sep 24, 2024
1 parent df1a3dc commit 2ec1c6e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
15 changes: 10 additions & 5 deletions app/(app)/loading/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CardTitle,
} from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Bug, MoveLeft } from 'lucide-react';

const LoadingPage = (): JSX.Element => {
const [progress, setProgress] = useState(0);
Expand All @@ -24,7 +25,7 @@ const LoadingPage = (): JSX.Element => {
try {
setProgress(0);
if (!xmlContent) {
throw new Error('No XML data found');
throw new Error('No XML data found in the file.');
}
setProgress(25);
const jsonData = convertToJson(xmlContent);
Expand All @@ -36,7 +37,7 @@ const LoadingPage = (): JSX.Element => {
router.push('/results');
} catch (err) {
if (err instanceof Error) {
setError(`${err.name} : ${err.message}`);
setError(`${err.message}`);
}
}
}, [router]);
Expand All @@ -61,8 +62,8 @@ const LoadingPage = (): JSX.Element => {
<Progress value={progress} className='w-full' />
{error ? (
<div className='mt-4'>
<p className='mb-2 font-semibold text-red-600'>Error:</p>
<p className='mb-4 text-gray-600'>{error}</p>
<h3 className='mb-2 font-semibold text-red-600'>Error:</h3>
<p className='mb-4 text-sm text-gray-600'>{error}</p>
</div>
) : (
<p className='mt-4 text-gray-600'>
Expand All @@ -73,9 +74,13 @@ const LoadingPage = (): JSX.Element => {
{error && (
<CardFooter className='flex justify-between'>
<Button variant='outline' onClick={handleBack}>
<MoveLeft className='h-6 w-6 pr-2' />
Back
</Button>
<Button onClick={handleRaiseIssue}>Raise Issue</Button>
<Button onClick={handleRaiseIssue}>
<Bug className='h-6 w-6 pr-2' />
Raise Issue
</Button>
</CardFooter>
)}
</Card>
Expand Down
29 changes: 17 additions & 12 deletions lib/xml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,25 @@ const getTestSuites = (suites: any): TestSuite[] => {
return result;
};

const errorMessage = 'Error while processing the XML file.';

const getTestResults = (jsonData: any): TestResult => {
const testResult = jsonData['testng-results'];

const mapToResult: TestResult = {
failed: parseInt(testResult.failed),
passed: parseInt(testResult.passed),
skipped: parseInt(testResult.skipped),
ignored: parseInt(testResult.ignored),
total: parseInt(testResult.total),
test_suites: getTestSuites(testResult.suite),
};

return mapToResult;
try {
const mapToResult: TestResult = {
failed: parseInt(testResult.failed),
passed: parseInt(testResult.passed),
skipped: parseInt(testResult.skipped),
ignored: parseInt(testResult.ignored),
total: parseInt(testResult.total),
test_suites: getTestSuites(testResult.suite),
};
return mapToResult;
/* eslint-disable @typescript-eslint/no-unused-vars */
} catch (error) {
throw new Error(errorMessage);
}
};

const convertToJson = (data: string): string | null => {
Expand All @@ -152,8 +158,7 @@ const convertToJson = (data: string): string | null => {
},
(error, result) => {
if (error) {
alert(`Error parsing XML file: ${error.name} - ${error.message}`);
return null;
throw new Error(errorMessage);
}
jsonData = result;
}
Expand Down

0 comments on commit 2ec1c6e

Please sign in to comment.