Files
carmanagement/apps/homepage/tests/unit/integrations/demo-dialog-host.test.tsx
T
root 149806a773
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 56s
Build & Push / Build & Push Docker Image (push) Failing after 4m53s
Test / API Unit Tests (push) Successful in 1m15s
Test / Homepage Unit Tests (push) Successful in 46s
Test / Carplace Unit Tests (push) Successful in 41s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m6s
fix bug 16 and 17
2026-08-04 00:52:58 -04:00

63 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { DemoDialogHost } from '@/components/integrations/DemoDialogHost';
import { demoOpenEventName } from '@/components/integrations/DemoTrigger';
import enHomepage from '@/content/locales/en/homepage.json';
import { act, render, screen } from '@testing-library/react';
import { beforeAll, describe, expect, it } from 'vitest';
function openDemoForm(source: 'hero' | 'pricing') {
const trigger = document.createElement('button');
document.body.appendChild(trigger);
act(() => {
window.dispatchEvent(
new CustomEvent(demoOpenEventName, {
detail: { source, trigger },
}),
);
});
}
describe('DemoDialogHost', () => {
beforeAll(() => {
HTMLDialogElement.prototype.showModal ??= function showModal() {
this.setAttribute('open', '');
};
HTMLDialogElement.prototype.close ??= function close() {
this.removeAttribute('open');
};
});
it('keeps the full fleet selector for regular demo requests', () => {
render(<DemoDialogHost locale="en" messages={enHomepage.form} enabled />);
openDemoForm('hero');
const fleet = screen.getByLabelText(/Approximate fleet size/) as HTMLSelectElement;
expect(Array.from(fleet.options).map((option) => option.textContent)).toEqual([
'Select an option',
'125 vehicles',
'2675 vehicles',
'76150 vehicles',
'150 or more vehicles',
]);
});
it('limits the pricing request fleet selector to 150 or more vehicles', () => {
render(<DemoDialogHost locale="en" messages={enHomepage.form} enabled />);
openDemoForm('pricing');
const fleet = screen.getByLabelText(/Approximate fleet size/) as HTMLSelectElement;
expect(Array.from(fleet.options).map((option) => option.textContent)).toEqual([
'150 or more vehicles',
]);
expect(fleet.value).toBe('250+');
expect(screen.getByRole('button', { name: 'Request quote' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Create my account' })).not.toBeInTheDocument();
expect(screen.getByRole('dialog', { name: 'Request Enterprise quote' })).toBeVisible();
expect(screen.getByText('Enterprise quote')).toBeInTheDocument();
expect(screen.getByText(/Share company information only/)).toBeInTheDocument();
expect(screen.queryByText('Safe local adapter')).not.toBeInTheDocument();
expect(screen.queryByText(/Non-production mode validates/)).not.toBeInTheDocument();
});
});