Skip to content

Commit

Permalink
fix: 🐛 fixed issue when file contains parent suite
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Sep 23, 2024
1 parent d26a50b commit df1a3dc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 80 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ body:
id: steps-to-reproduce
attributes:
label: 📃 Steps to reproduce the bug
description: We highly suggest including a screenshots and a bug report log (GitHub Gist link).
description: |
We highly suggest including the Error screenshots
and attach the file having issue.
placeholder: Tell us the steps required to replicate your bug.
validations:
required: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
.env
105 changes: 50 additions & 55 deletions app/(app)/loading/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
/* eslint-disable @stylistic/js/max-len */
'use client';

import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { convertToJson, getTestResults } from '@/lib/xml-parser';
import { Progress } from '@/components/ui/progress';
import {
Card,
CardContent,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Button } from '@/components/ui/button';

const LoadingPage = (): JSX.Element => {
const [progress, setProgress] = useState(0);
const [error, setError] = useState<string | null>(null);
const [redirectTimer, setRedirectTimer] = useState(5);
const router = useRouter();

useEffect(() => {
const xmlContent = localStorage.getItem('xml-data');
if (!xmlContent) {
setError('No XML data found');
return;
}
setProgress(10);
try {
setProgress(0);
if (!xmlContent) {
throw new Error('No XML data found');
}
setProgress(25);
const jsonData = convertToJson(xmlContent);
setProgress(30);
const testResult = getTestResults(jsonData);
setProgress(50);
const testResult = getTestResults(jsonData);
setProgress(75);
localStorage.setItem('json-data', JSON.stringify(testResult));
setProgress(100);
router.push('/results');
Expand All @@ -32,58 +41,44 @@ const LoadingPage = (): JSX.Element => {
}
}, [router]);

useEffect(() => {
let timerInterval: NodeJS.Timeout;

if (error) {
timerInterval = setInterval(() => {
setRedirectTimer((prevTimer) => {
if (prevTimer <= 1) {
clearInterval(timerInterval);
router.push('/');
return 0;
}
return prevTimer - 1;
});
}, 1000);
}

return () => {
if (timerInterval) {
clearInterval(timerInterval);
}
};
}, [error, router]);
const handleBack = (): void => {
router.push('/');
};

if (error) {
return (
<div className='flex min-h-screen items-center justify-center bg-gray-100'>
<div className='w-96 rounded-lg bg-white p-8 text-center shadow-md'>
<h1 className='mb-4 text-2xl font-bold text-red-600'>Error</h1>
<p className='mb-4 text-gray-600'>{error}</p>
<p className='text-gray-500'>
Redirecting to home page in {redirectTimer} second
{redirectTimer > 1 ? 's' : ''}...
</p>
</div>
</div>
const handleRaiseIssue = (): void => {
router.push(
'https://github.com/WasiqB/ultra-reporter-app/issues/new?assignees=&labels=bug&projects=&template=bug.yml&title=%F0%9F%90%9B+New+Bug:'
);
}
};

return (
<div className='flex min-h-screen items-center justify-center bg-gray-100'>
<div className='w-96 rounded-lg bg-white p-8 text-center shadow-md'>
<h1 className='mb-4 text-2xl font-bold'>Processing XML</h1>
<div className='mb-4 h-2.5 w-full rounded-full bg-gray-200 dark:bg-gray-700'>
<div
className='h-2.5 rounded-full bg-blue-600'
style={{ width: `${progress}%` }}
></div>
</div>
<p className='text-gray-600'>
Please wait while we process your XML file...
</p>
</div>
<Card className='w-[350px]'>
<CardHeader>
<CardTitle>Processing XML</CardTitle>
</CardHeader>
<CardContent>
<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>
</div>
) : (
<p className='mt-4 text-gray-600'>
Please wait while we process your XML file...
</p>
)}
</CardContent>
{error && (
<CardFooter className='flex justify-between'>
<Button variant='outline' onClick={handleBack}>
Back
</Button>
<Button onClick={handleRaiseIssue}>Raise Issue</Button>
</CardFooter>
)}
</Card>
</div>
);
};
Expand Down
32 changes: 17 additions & 15 deletions lib/xml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,26 @@ const getTestClasses = (classes: any): TestClass[] => {

const getTestCases = (tests: any): TestCase[] => {
const result: TestCase[] = [];
if (tests.length) {
for (const test of tests) {
if (tests) {
if (tests.length) {
for (const test of tests) {
result.push({
name: test['name'],
started_at: test['started-at'],
finished_at: test['finished-at'],
duration_ms: test['duration-ms'],
test_classes: getTestClasses(test.class),
});
}
} else {
result.push({
name: test['name'],
started_at: test['started-at'],
finished_at: test['finished-at'],
duration_ms: test['duration-ms'],
test_classes: getTestClasses(test.class),
name: tests['name'],
started_at: tests['started-at'],
finished_at: tests['finished-at'],
duration_ms: tests['duration-ms'],
test_classes: getTestClasses(tests.class),
});
}
} else {
result.push({
name: tests['name'],
started_at: tests['started-at'],
finished_at: tests['finished-at'],
duration_ms: tests['duration-ms'],
test_classes: getTestClasses(tests.class),
});
}
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"postcss": "^8",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.6",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.13",
"typescript": "^5",
"typescript-eslint": "^8.6.0"
},
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df1a3dc

Please sign in to comment.