Skip to content

Commit

Permalink
feat: add tests for sorting and grouping in UserMo
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Dec 1, 2023
1 parent 3f74784 commit e4dbdbb
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserModulesComponent } from './user-modules.component';
import { ModuleUtilService } from 'src/app/services/module-util.service';

describe('UserModulesComponent', () => {
let component: UserModulesComponent;
let fixture: ComponentFixture<UserModulesComponent>;
let moduleUtilService: ModuleUtilService;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UserModulesComponent ],
providers: [ ModuleUtilService ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(UserModulesComponent);
component = fixture.componentInstance;
moduleUtilService = TestBed.inject(ModuleUtilService);
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should sort modules correctly', () => {
const mockModules = [
{ name: 'Module 1', type: 'Type B', manufacturer: 'Manufacturer A' },
{ name: 'Module 2', type: 'Type A', manufacturer: 'Manufacturer B' },
{ name: 'Module 3', type: 'Type C', manufacturer: 'Manufacturer C' }
];
component.onSortChange('type');
expect(moduleUtilService.sortModules(mockModules, 'type')).toEqual([
{ name: 'Module 2', type: 'Type A', manufacturer: 'Manufacturer B' },
{ name: 'Module 1', type: 'Type B', manufacturer: 'Manufacturer A' },
{ name: 'Module 3', type: 'Type C', manufacturer: 'Manufacturer C' }
]);
});

it('should group modules correctly', () => {
const mockModules = [
{ name: 'Module 1', type: 'Type B', manufacturer: 'Manufacturer A' },
{ name: 'Module 2', type: 'Type A', manufacturer: 'Manufacturer B' },
{ name: 'Module 3', type: 'Type B', manufacturer: 'Manufacturer C' }
];
component.onGroupChange('type');
expect(moduleUtilService.groupModulesByType(mockModules)).toEqual({
'Type A': [{ name: 'Module 2', type: 'Type A', manufacturer: 'Manufacturer B' }],
'Type B': [
{ name: 'Module 1', type: 'Type B', manufacturer: 'Manufacturer A' },
{ name: 'Module 3', type: 'Type B', manufacturer: 'Manufacturer C' }
]
});
});
});

0 comments on commit e4dbdbb

Please sign in to comment.