/
Starolat
/
DeepDive
Обзор
Документация
Войти
/
Starolat
/
DeepDive
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/main-data-module.test.js
102 строки
3 KB
Starolat Sergei
chore: sync project state for Gitverse
16 июн 2026, 16:06
16 июн 2026, 16:06
1cb951e
Код
Авторство
О чём код?
// @ts-check /** * @fileoverview Tests for MainDataModule * @jest-environment jsdom */ import '../js/components/MainDataModule.js'; describe('MainDataModule', () => { let module; beforeEach(() => { module = document.createElement('main-data-module'); document.body.appendChild(module); }); afterEach(() => { module.remove(); }); describe('UT-001: Date Formatting', () => { it('should format date from YYYY-MM-DD to DD.MM.YY', () => { const result = module.formatDate('2024-01-20'); expect(result).toBe('20.01.24'); }); it('should return em-dash for null/undefined', () => { expect(module.formatDate(null)).toBe('—'); expect(module.formatDate(undefined)).toBe('—'); }); it('should return original string for invalid format', () => { expect(module.formatDate('invalid')).toBe('invalid'); }); }); describe('UT-002: Status Badge Rendering', () => { it('should render "В работе" badge', () => { const html = module.renderStatusBadge('В работе'); expect(html).toContain('in-progress'); expect(html).toContain('В работе'); }); it('should render "Завершено" badge', () => { const html = module.renderStatusBadge('Завершено'); expect(html).toContain('completed'); }); it('should render fallback for unknown status', () => { const html = module.renderStatusBadge('Unknown'); expect(html).toContain('pending'); }); }); describe('IT-001: Data Loading', () => { it('should load data on connectedCallback', async () => { // Mock fetchData jest.spyOn(module, 'loadData').mockResolvedValue(); await module.connectedCallback(); expect(module.loadData).toHaveBeenCalled(); }); it('should dispatch data-updated event after loading', (done) => { document.addEventListener('data-updated', (e) => { expect(e.detail).toBeDefined(); expect(Array.isArray(e.detail)).toBe(true); done(); }); module.loadData(); }); }); describe('IT-002: Tab Switching', () => { it('should show diagram tab on click', () => { const diagramTab = module.querySelector('[data-tab="diagram"]'); diagramTab.click(); const diagramContent = module.querySelector('#diagram'); expect(diagramContent.style.display).not.toBe('none'); }); it('should initialize chart on first diagram tab click', () => { const diagramTab = module.querySelector('[data-tab="diagram"]'); diagramTab.click(); expect(module.isChartInitialized).toBe(true); }); }); describe('IT-003: Empty State', () => { it('should show empty state when no data', () => { module.data = []; module.render(); const tableContainer = module.querySelector('#table'); expect(tableContainer.textContent).toContain('Нет данных'); }); }); });