]> git.ipfire.org Git - thirdparty/paperless-ngx.git/blob
fc139ac26ce7427a94184391633a29e76ec52786
[thirdparty/paperless-ngx.git] /
1 import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
2 import { provideHttpClientTesting } from '@angular/common/http/testing'
3 import { ComponentFixture, TestBed } from '@angular/core/testing'
4 import {
5 FormsModule,
6 NG_VALUE_ACCESSOR,
7 ReactiveFormsModule,
8 } from '@angular/forms'
9 import { NgSelectModule } from '@ng-select/ng-select'
10 import { of } from 'rxjs'
11 import { GroupService } from 'src/app/services/rest/group.service'
12 import { PermissionsGroupComponent } from './permissions-group.component'
13
14 describe('PermissionsGroupComponent', () => {
15 let component: PermissionsGroupComponent
16 let fixture: ComponentFixture<PermissionsGroupComponent>
17 let groupService: GroupService
18 let groupServiceSpy
19
20 beforeEach(async () => {
21 TestBed.configureTestingModule({
22 declarations: [PermissionsGroupComponent],
23 imports: [FormsModule, ReactiveFormsModule, NgSelectModule],
24 providers: [
25 GroupService,
26 provideHttpClient(withInterceptorsFromDi()),
27 provideHttpClientTesting(),
28 ],
29 }).compileComponents()
30
31 groupService = TestBed.inject(GroupService)
32 groupServiceSpy = jest.spyOn(groupService, 'listAll').mockReturnValue(
33 of({
34 count: 2,
35 all: [2, 3],
36 results: [
37 {
38 id: 2,
39 name: 'Group 2',
40 },
41 {
42 id: 3,
43 name: 'Group 3',
44 },
45 ],
46 })
47 )
48 fixture = TestBed.createComponent(PermissionsGroupComponent)
49 fixture.debugElement.injector.get(NG_VALUE_ACCESSOR)
50 component = fixture.componentInstance
51 fixture.detectChanges()
52 })
53
54 it('should get groups, support use of select', () => {
55 component.writeValue({ id: 2, name: 'Group 2' })
56 expect(component.value).toEqual({ id: 2, name: 'Group 2' })
57 expect(groupServiceSpy).toHaveBeenCalled()
58 })
59 })