-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathACL.test.ts
More file actions
57 lines (46 loc) · 1.77 KB
/
ACL.test.ts
File metadata and controls
57 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { shallowMount, VueWrapper } from '@vue/test-utils';
import { createApp, h } from 'vue';
import ACL from '@/lib/ACL';
import Vacl from '@/index';
describe('vue', () => {
const component = {
render() {
return h('div');
}
};
it('can be installed correctly', () => {
const app = createApp(component).use(Vacl);
expect(app.config.globalProperties.$vacl).toBeInstanceOf(ACL);
});
it('provides the acl globally to all components', () => {
const wrapper = shallowMount(component, {
global: {
plugins: [[Vacl, { permissions: ['view'] }]]
}
});
expect(wrapper.vm.$vacl).toBeInstanceOf(ACL);
expect(wrapper.vm.$vacl.can('view')).toBe(true);
expect(wrapper.vm.$vacl.has('admin')).toBe(false);
});
it('should be able to configure global accessor name', () => {
const wrapper = shallowMount(component, {
global: {
plugins: [[Vacl, { accessor: '$acl' }]]
}
});
expect(wrapper.vm.$acl).toBeInstanceOf(ACL);
});
it('should be able to set the directive names from the config', () => {
const div = document.createElement('div');
div.id = 'id';
document.body.appendChild(div);
const app = createApp({
template: `<div v-able="'view'" data-test='visible'></div>
<div v-able="'edit'" data-test='hidden'></div>`
})
.use(Vacl, { directives: { can: 'able' }, permissions: ['view'] });
const wrapper = new VueWrapper(app, app.mount('#id'));
expect(wrapper.find('[data-test="visible"]').isVisible()).toBe(true);
expect(wrapper.find('[data-test="hidden"]').isVisible()).toBe(false);
});
});