mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { Component } from '@angular/core'
|
|
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
|
import { IfPermissionsDirective } from './if-permissions.directive'
|
|
import { PermissionsService } from '../services/permissions.service'
|
|
|
|
@Component({
|
|
template: `
|
|
<div>
|
|
<button *pngxIfPermissions="{ action: 'add', type: '%s_user' }">
|
|
Some Text
|
|
</button>
|
|
</div>
|
|
`,
|
|
})
|
|
class TestComponent {}
|
|
|
|
describe('IfPermissionsDirective', () => {
|
|
let fixture: ComponentFixture<TestComponent>
|
|
let permissionsService: PermissionsService
|
|
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [IfPermissionsDirective, TestComponent],
|
|
providers: [PermissionsService],
|
|
})
|
|
permissionsService = TestBed.inject(PermissionsService)
|
|
})
|
|
|
|
it('should create element if user has permissions', () => {
|
|
jest.spyOn(permissionsService, 'currentUserCan').mockImplementation(() => {
|
|
return true
|
|
})
|
|
|
|
fixture = TestBed.createComponent(TestComponent)
|
|
|
|
fixture.detectChanges()
|
|
|
|
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
|
expect(rootEl.querySelectorAll('button').length).toEqual(1)
|
|
})
|
|
|
|
it('should not create element if user has does not have permissions', () => {
|
|
jest.spyOn(permissionsService, 'currentUserCan').mockImplementation(() => {
|
|
return false
|
|
})
|
|
|
|
fixture = TestBed.createComponent(TestComponent)
|
|
|
|
fixture.detectChanges()
|
|
|
|
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
|
expect(rootEl.querySelectorAll('button').length).toEqual(0)
|
|
})
|
|
})
|