- Implemented TourProgressController to handle API endpoints for tracking guided tours seen by users. - Created UserTourProgress entity to store the highest version of tours seen by each user. - Developed UserTourProgressRepository for database interactions related to user tour progress. - Introduced TourProgressService to manage business logic for marking tours as seen and retrieving seen maps. - Added comprehensive tests for API endpoints and entity behavior to ensure functionality and data integrity.
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { describe, it, expect, afterEach } from 'vitest';
|
|
import { anchorSelector, resolveSteps } from './resolveSteps';
|
|
import { getTour, TOURS } from './registry';
|
|
import type { TourStep } from './types';
|
|
|
|
const STEPS: TourStep[] = [
|
|
{ anchor: 'one', title: 'یک', body: '…' },
|
|
{ anchor: 'two', title: 'دو', body: '…' },
|
|
{ anchor: 'three', title: 'سه', body: '…' },
|
|
];
|
|
|
|
function mount(...anchors: string[]) {
|
|
document.body.innerHTML = anchors.map((a) => `<div data-tour="${a}"></div>`).join('');
|
|
}
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = '';
|
|
});
|
|
|
|
describe('resolveSteps', () => {
|
|
it('استپهای موجود را با حفظ ترتیب نگه میدارد', () => {
|
|
mount('three', 'one');
|
|
|
|
expect(resolveSteps(STEPS).map((s) => s.anchor)).toEqual(['one', 'three']);
|
|
});
|
|
|
|
it('وقتی هیچ المانی نیست، خروجی خالی است', () => {
|
|
expect(resolveSteps(STEPS)).toEqual([]);
|
|
});
|
|
|
|
it('آرایهٔ خالی خروجی خالی میدهد', () => {
|
|
mount('one');
|
|
|
|
expect(resolveSteps([])).toEqual([]);
|
|
});
|
|
|
|
it('سلکتور از روی anchor ساخته میشود', () => {
|
|
expect(anchorSelector('appointments-stats')).toBe('[data-tour="appointments-stats"]');
|
|
});
|
|
});
|
|
|
|
describe('registry', () => {
|
|
it('برای شناسهٔ ناشناس یا خالی null میدهد', () => {
|
|
expect(getTour('does-not-exist')).toBeNull();
|
|
expect(getTour(undefined)).toBeNull();
|
|
});
|
|
|
|
it('تور نوبتها ثبت شده است', () => {
|
|
expect(getTour('appointments')?.id).toBe('appointments');
|
|
});
|
|
|
|
it('هر تور نسخهٔ معتبر و anchorهای بدون تکرار دارد', () => {
|
|
for (const [id, tour] of Object.entries(TOURS)) {
|
|
expect(tour.id).toBe(id);
|
|
expect(tour.version).toBeGreaterThanOrEqual(1);
|
|
expect(tour.steps.length).toBeGreaterThan(0);
|
|
|
|
const anchors = tour.steps.map((s) => s.anchor);
|
|
expect(new Set(anchors).size).toBe(anchors.length);
|
|
}
|
|
});
|
|
});
|