-
Notifications
You must be signed in to change notification settings - Fork 961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: unit tests for survey service #1813
feat: unit tests for survey service #1813
Conversation
…shubham/for-1565-write-unit-tests-for-survey-services
…shubham/for-1565-write-unit-tests-for-survey-services
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
Thank you for following the naming conventions for pull request titles! 🙏 |
apps/formbricks-com/components/dummyUI/AddNoCodeEventModalDummy.tsxReordering CSS classes in a consistent manner can improve code readability and maintainability. It's a good practice to follow a specific order, for example, placing responsive classes (like sm:, md:, lg:, etc.) at the end of the class list. className="hidden items-center space-x-2 rounded-lg bg-slate-50 p-3 dark:bg-slate-600 md:flex"
apps/formbricks-com/components/home/Steps.tsxThere are several repeated blocks of code in the Steps component. These blocks can be extracted into a separate component to improve the readability of the code and make it more maintainable. // New Step component
const Step = ({ stepNumber, title, description, children }) => (
<div className="mx-auto mb-12 mt-8 max-w-lg md:mb-0 md:mt-32 md:max-w-none">
<div className="px-4 sm:max-w-4xl sm:px-6 lg:max-w-7xl lg:px-8">
<div className="grid md:grid-cols-2 md:items-center md:gap-16">
<div className="pb-8 sm:pl-10 md:pb-0">
<h4 className="text-brand-dark font-bold">Step {stepNumber}</h4>
<h2 className="xs:text-3xl text-2xl font-bold tracking-tight text-slate-800 dark:text-slate-200 sm:text-3xl">
{title}
</h2>
<p className="text-md mt-6 max-w-lg leading-7 text-slate-500 dark:text-slate-400">
{description}
</p>
</div>
{children}
</div>
</div>
</div>
);
// Usage in Steps component
<Step stepNumber={1} title="Copy + Paste" description="Simply copy a <script> tag to your HTML head - that’s about it. Or use NPM to install Formbricks for React, Vue, Svelte, etc.">
<div className="rounded-lg bg-slate-100 dark:bg-slate-800">
<SetupTabs />
</div>
</Step>
apps/formbricks-com/components/shared/PricingCalculator.tsxThere is a repeated block of code in the LinkSurveySlider, InAppSlider, and UserSegmentationSlider components. This block of code can be extracted into a separate component to improve the readability of the code and adhere to the DRY (Don't Repeat Yourself) principle. const SliderComponent = ({ label, usersCount, price }) => (
<div className="mb-2 flex items-center gap-x-2 md:gap-x-4">
<div className="md:text-md w-3/6 text-left text-sm font-medium text-slate-700 dark:text-slate-200">
{label}
</div>
<div className="md:text-md w-2/6 text-center text-sm font-medium text-slate-700 dark:text-slate-200">
{Math.round(usersCount).toLocaleString()} Submissions
</div>
<div className="md:text-md flex w-1/6 items-center justify-end text-center text-sm font-medium text-slate-700 dark:text-slate-200 md:justify-center">
<span>${price.toFixed(2)}</span>
</div>
</div>
);
The calculation of usersCountForInProductSlider and productSurveysPrice can be memoized using the useMemo hook to avoid unnecessary calculations on each render. const usersCountForInProductSlider = useMemo(() => transformToLog(inProductSlider), [inProductSlider]);
const productSurveysPrice = useMemo(() => calculatePrice(usersCountForInProductSlider), [usersCountForInProductSlider]);
The code block that maps over the array [3, 4, 5, 6] and returns a string based on the value of the mark can be simplified by using a switch statement. This will make the code more readable and easier to maintain. {[3, 4, 5, 6].map((mark) => {
let label;
switch(mark) {
case 3:
label = "1K";
break;
case 4:
label = "10K";
break;
case 5:
label = "100K";
break;
case 6:
label = "1M";
break;
default:
label = "";
}
return (
<span key={mark} className="text-slate-600 dark:text-slate-300">
{label}
</span>
);
})}
apps/formbricks-com/components/shared/Header.tsxConsider using a throttling function to limit the number of times the scroll event listener is fired. This can significantly improve performance, especially on devices with slower processors. useEffect(() => {
const handleScroll = throttle(() => {
if (window.scrollY > 250) {
setStickyNav(true);
} else {
setStickyNav(false);
}
}, 200);
window.addEventListener("scroll", handleScroll);
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
Consider using an object as an argument to the clsx function instead of a template string. This will make the code more readable and easier to maintain. className={clsx({
'text-slate-900 dark:text-slate-100': brick.status,
'text-slate-400': !brick.status,
'font-semibold': true
})}
|
@@ -55,7 +55,7 @@ export const AddNoCodeEventModalDummy: React.FC<EventDetailModalProps> = ({ open | |||
Inner Text | |||
</Label> | |||
</div> | |||
<div className="hidden items-center space-x-2 rounded-lg bg-slate-50 p-3 md:flex dark:bg-slate-600"> | |||
<div className="hidden items-center space-x-2 rounded-lg bg-slate-50 p-3 dark:bg-slate-600 md:flex"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reordered the CSS classes to improve code readability and maintainability. The responsive class 'md:flex' is now placed at the end of the class list.
<div className="hidden items-center space-x-2 rounded-lg bg-slate-50 p-3 dark:bg-slate-600 md:flex"> | |
className="hidden items-center space-x-2 rounded-lg bg-slate-50 p-3 dark:bg-slate-600 md:flex" |
…for-1565-write-unit-tests-for-survey-services
…for-1565-write-unit-tests-for-survey-services
…for-1565-write-unit-tests-for-survey-services
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShubhamPalriwala thanks a lot for making the changes :-)
What does this PR do?
Unit tests for all survey services
PS: Looks like my linter messed up :/ but I just ran pnpm run lint and nothing changed, weird
Type of change
How should this be tested?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated