AddPermissions.jest.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import AddPermissions from './AddPermissions';
  3. import { RootStore } from 'app/stores/RootStore/RootStore';
  4. import { backendSrv } from 'test/mocks/common';
  5. import { shallow } from 'enzyme';
  6. describe('AddPermissions', () => {
  7. let wrapper;
  8. beforeAll(() => {
  9. backendSrv.get.mockReturnValue(
  10. Promise.resolve([
  11. { id: 2, dashboardId: 1, role: 'Viewer', permission: 1, permissionName: 'View' },
  12. { id: 3, dashboardId: 1, role: 'Editor', permission: 1, permissionName: 'Edit' },
  13. {
  14. id: 4,
  15. dashboardId: 1,
  16. userId: 2,
  17. userLogin: 'danlimerick',
  18. userEmail: 'dan.limerick@gmail.com',
  19. permission: 4,
  20. permissionName: 'Admin',
  21. },
  22. ])
  23. );
  24. backendSrv.post = jest.fn();
  25. const store = RootStore.create(
  26. {},
  27. {
  28. backendSrv: backendSrv,
  29. }
  30. );
  31. // wrapper = shallow(<Permissions backendSrv={backendSrv} isFolder={true} dashboardId={1} {...store} />);
  32. wrapper = shallow(<AddPermissions permissions={store.permissions} backendSrv={backendSrv} dashboardId={1} />);
  33. //<AddPermissions permissions={permissions} backendSrv={backendSrv} dashboardId={dashboardId} />
  34. // return wrapper.instance().loadStore(1, true);
  35. });
  36. describe('when permission for a user is added', () => {
  37. it('should save permission to db', async () => {
  38. const evt = {
  39. target: {
  40. value: 'User',
  41. },
  42. };
  43. const userItem = {
  44. id: 2,
  45. login: 'user2',
  46. };
  47. const instance = wrapper.instance();
  48. instance.typeChanged(evt);
  49. instance.userPicked(userItem);
  50. wrapper.find('[data-save-permission]').simulate('click');
  51. expect(backendSrv.post.mock.calls.length).toBe(1);
  52. expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
  53. });
  54. });
  55. // describe('when permission for team is added', () => {
  56. // it('should save permission to db', () => {
  57. // const teamItem = {
  58. // id: 2,
  59. // name: 'ug1',
  60. // };
  61. // wrapper
  62. // .instance()
  63. // .teamPicked(teamItem)
  64. // .then(() => {
  65. // expect(backendSrv.post.mock.calls.length).toBe(1);
  66. // expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
  67. // });
  68. // });
  69. // });
  70. });