refactor: migrate testing framework from Karma/Jasmine to Vitest with Angular support
This commit is contained in:
1 parent
237d995e16
commit
11924df19e
14 files changed
+1351
-273
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideZonelessChangeDetection } from '@angular/core';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { vi } from 'vitest';
|
||||
import { CalendarSettingsDialog } from './calendar-settings-dialog';
|
||||
|
||||
describe('CalendarSettingsDialog', () => {
|
||||
@@ -15,7 +16,7 @@ describe('CalendarSettingsDialog', () => {
|
||||
{
|
||||
provide: MatDialogRef,
|
||||
useValue: {
|
||||
close: jasmine.createSpy('close'),
|
||||
close: vi.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('RulesPanel', () => {
|
||||
it('should start adding new If-Then rule', () => {
|
||||
component.startAddNew(RuleType.IF_THEN);
|
||||
|
||||
expect(component['isAddingNew']()).toBeTrue();
|
||||
expect(component['isAddingNew']()).toBe(true);
|
||||
expect(component['newRuleType']()).toBe(RuleType.IF_THEN);
|
||||
expect(component['editBuffer'].type).toBe(RuleType.IF_THEN);
|
||||
expect(component['editBuffer'].name).toBe('Nouvelle Règle');
|
||||
@@ -42,7 +42,7 @@ describe('RulesPanel', () => {
|
||||
it('should start adding new Time Window rule', () => {
|
||||
component.startAddNew(RuleType.TIME_WINDOW);
|
||||
|
||||
expect(component['isAddingNew']()).toBeTrue();
|
||||
expect(component['isAddingNew']()).toBe(true);
|
||||
expect(component['newRuleType']()).toBe(RuleType.TIME_WINDOW);
|
||||
expect(component['editBuffer'].type).toBe(RuleType.TIME_WINDOW);
|
||||
expect(component['editBuffer'].name).toBe('Nouvelle Période');
|
||||
@@ -52,7 +52,7 @@ describe('RulesPanel', () => {
|
||||
component.startAddNew(RuleType.IF_THEN);
|
||||
component.cancelEdit();
|
||||
|
||||
expect(component['isAddingNew']()).toBeFalse();
|
||||
expect(component['isAddingNew']()).toBe(false);
|
||||
expect(component['editingRuleId']()).toBeNull();
|
||||
expect(Object.keys(component['editBuffer']).length).toBe(0);
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe('RulesPanel', () => {
|
||||
component.saveEdit();
|
||||
|
||||
expect(component.rules.length).toBe(initialCount + 1);
|
||||
expect(component.rules.some((r) => r.name === 'Custom Test Rule')).toBeTrue();
|
||||
expect(component.rules.some((r) => r.name === 'Custom Test Rule')).toBe(true);
|
||||
});
|
||||
|
||||
it('should update an existing rule', () => {
|
||||
@@ -89,7 +89,7 @@ describe('RulesPanel', () => {
|
||||
component.deleteRule(targetId, mockEvent);
|
||||
|
||||
expect(component.rules.length).toBe(initialCount - 1);
|
||||
expect(component.rules.some((r) => r.id === targetId)).toBeFalse();
|
||||
expect(component.rules.some((r) => r.id === targetId)).toBe(false);
|
||||
});
|
||||
|
||||
it('should toggle a rule', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, ChangeDetectionStrategy, inject, signal } from '@angular/core';
|
||||
import { Component, ChangeDetectionStrategy, inject, signal, Injectable } from '@angular/core';
|
||||
import {
|
||||
RuleService,
|
||||
RuleType,
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
} from '@angular/material/core';
|
||||
import { CdkDragDrop, CdkDropList, CdkDrag } from '@angular/cdk/drag-drop';
|
||||
|
||||
@Injectable()
|
||||
class CustomDateAdapter extends NativeDateAdapter {
|
||||
override format(date: Date, displayFormat: unknown): string {
|
||||
if (displayFormat === 'input') {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, input, output, ChangeDetectionStrategy } from '@angular/core';
|
||||
import { Component, input, output, ChangeDetectionStrategy, Injectable } from '@angular/core';
|
||||
import { SelectableDayType, tooltipTypeMapping, VacDay } from '../../../services/calendar-service';
|
||||
import { MatCard } from '@angular/material/card';
|
||||
import { MatOption, MatSelect } from '@angular/material/select';
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
|
||||
@Injectable()
|
||||
class CustomDateAdapter extends NativeDateAdapter {
|
||||
override format(date: Date, displayFormat: unknown): string {
|
||||
if (displayFormat === 'input') {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { provideZonelessChangeDetection } from '@angular/core';
|
||||
import {
|
||||
CalendarService,
|
||||
@@ -228,20 +229,20 @@ describe('SelectedDates', () => {
|
||||
{ id: '3', type: RuleType.IF_THEN, enabled: true } as IfThenRule,
|
||||
];
|
||||
|
||||
const applyTimeWindowRulesSpy = spyOn(selectedDates, 'applyTimeWindowRules');
|
||||
const applyIfThenRulesSpy = spyOn(selectedDates, 'applyIfThenRules');
|
||||
const applyTimeWindowRulesSpy = vi.spyOn(selectedDates, 'applyTimeWindowRules');
|
||||
const applyIfThenRulesSpy = vi.spyOn(selectedDates, 'applyIfThenRules');
|
||||
|
||||
await selectedDates.optimizeVacations(vacationDays, rules, calendarService);
|
||||
|
||||
expect(applyIfThenRulesSpy.calls.count()).toBe(2);
|
||||
expect(applyTimeWindowRulesSpy.calls.count()).toBe(1);
|
||||
expect(applyIfThenRulesSpy.mock.calls.length).toBe(2);
|
||||
expect(applyTimeWindowRulesSpy.mock.calls.length).toBe(1);
|
||||
|
||||
// First rule is IF_THEN
|
||||
expect(applyIfThenRulesSpy.calls.argsFor(0)[1][0].id).toBe('1');
|
||||
expect(applyIfThenRulesSpy.mock.calls[0][1][0].id).toBe('1');
|
||||
// Second rule is TIME_WINDOW
|
||||
expect(applyTimeWindowRulesSpy.calls.argsFor(0)[1][0].id).toBe('2');
|
||||
expect(applyTimeWindowRulesSpy.mock.calls[0][1][0].id).toBe('2');
|
||||
// Third rule is IF_THEN
|
||||
expect(applyIfThenRulesSpy.calls.argsFor(1)[1][0].id).toBe('3');
|
||||
expect(applyIfThenRulesSpy.mock.calls[1][1][0].id).toBe('3');
|
||||
});
|
||||
|
||||
it('should apply time window rules', () => {
|
||||
@@ -268,7 +269,7 @@ describe('SelectedDates', () => {
|
||||
];
|
||||
|
||||
// Mock monthsInAYearFromNow to return a controlled range of days
|
||||
spyOn(calendarService, 'monthsInAYearFromNow').and.returnValue([
|
||||
vi.spyOn(calendarService, 'monthsInAYearFromNow').mockReturnValue([
|
||||
[
|
||||
[
|
||||
new Date(futureYear, 11, 20),
|
||||
@@ -376,7 +377,7 @@ describe('SelectedDates', () => {
|
||||
},
|
||||
];
|
||||
|
||||
spyOn(calendarService, 'monthsInAYearFromNow').and.returnValue([
|
||||
vi.spyOn(calendarService, 'monthsInAYearFromNow').mockReturnValue([
|
||||
[
|
||||
[
|
||||
new Date(futureYear, 6, 1),
|
||||
|
||||
@@ -27,8 +27,8 @@ describe('RuleService', () => {
|
||||
const rules = service.rules;
|
||||
const christmasRule = rules.find((r) => r.type === RuleType.TIME_WINDOW) as TimeWindowRule;
|
||||
expect(christmasRule).toBeDefined();
|
||||
expect(christmasRule.startDate instanceof Date).toBeTrue();
|
||||
expect(christmasRule.endDate instanceof Date).toBeTrue();
|
||||
expect(christmasRule.startDate instanceof Date).toBe(true);
|
||||
expect(christmasRule.endDate instanceof Date).toBe(true);
|
||||
});
|
||||
|
||||
it('should add a new rule', () => {
|
||||
|
||||
Reference in new issue
Block a user