feat: add testing setup with Vitest and Testing Library
- Updated package.json to include Vitest and Testing Library dependencies and scripts for testing. - Created a test suite for the ProvinceProvider context to validate cityId and province detection based on subdomains. - Implemented unit tests for utility functions in helper/index.js, including phone number formatting and validation. - Added tests for state information retrieval in lib/getStateInfo.js, ensuring correct city and state matching based on subdomains. - Developed tests for appointment slot adaptation and availability checks in lib/appointmentSlots.js. - Created tests for token storage functionality in lib/tokenStore.js. - Implemented sanitization and JSON parsing tests in lib/sanitize.js. - Added CASL ability tests in lib/ability.js to verify user access rights. - Created tests for cookie management in lib/refreshCookie.js. - Developed tests for patient user representation in lib/representationAdapters.js. - Implemented client-side state information retrieval tests in lib/getStateInfoClient.js. - Created tests for canonical URL generation in lib/getCanonicalUrl.js. - Developed tests for clinic API service functions in services/clinicApi.js. - Added request wrapper tests in services/response.js to ensure correct API interaction. - Set up Vitest configuration in vitest.config.mjs for JSX support and alias resolution. - Created setup and utility files for testing environment in test/setup.js and test/utils.jsx.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { getStateInfoClient } from '@/lib/getStateInfoClient';
|
||||
import { getCanonicalUrlClient } from '@/lib/getCanonicalUrl';
|
||||
|
||||
function setLocation(loc) {
|
||||
Object.defineProperty(window, 'location', { value: loc, writable: true, configurable: true });
|
||||
}
|
||||
|
||||
describe('getStateInfoClient (window)', () => {
|
||||
it('subdomain شناختهشده → شهر و استان', () => {
|
||||
setLocation({ host: 'arak-nobat.ir', href: 'https://arak-nobat.ir/' });
|
||||
const { matchedCity, matchedState, host } = getStateInfoClient();
|
||||
expect(matchedCity?.name).toBe('اراک');
|
||||
expect(matchedState?.name).toBe('مرکزی');
|
||||
expect(host).toBe('arak-nobat.ir');
|
||||
});
|
||||
|
||||
it('host ناشناخته → بدون تطبیق', () => {
|
||||
setLocation({ host: 'zzz.ir', href: 'https://zzz.ir/' });
|
||||
expect(getStateInfoClient().matchedCity).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCanonicalUrlClient (window)', () => {
|
||||
beforeEach(() => {
|
||||
setLocation({ host: 'arak-nobat.ir', pathname: '/doctors' });
|
||||
});
|
||||
|
||||
it('subdomain → canonical به دامنهی اصلی', () => {
|
||||
expect(getCanonicalUrlClient()).toBe('https://nobat724.com/doctors');
|
||||
});
|
||||
|
||||
it('دامنهی اصلی → null', () => {
|
||||
setLocation({ host: 'nobat724.com', pathname: '/doctors' });
|
||||
expect(getCanonicalUrlClient()).toBeNull();
|
||||
});
|
||||
|
||||
it('www و حروف بزرگ نرمال میشوند (دامنهی اصلی) → null', () => {
|
||||
setLocation({ host: 'WWW.Nobat724.com', pathname: '/x' });
|
||||
expect(getCanonicalUrlClient()).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user