Permissions.jest.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import Permissions from './Permissions';
  3. import { RootStore } from 'app/stores/RootStore/RootStore';
  4. import { backendSrv } from 'test/mocks/common';
  5. import { shallow } from 'enzyme';
  6. describe('Permissions', () => {
  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. return wrapper.instance().loadStore(1, true);
  33. });
  34. describe('when permission for a user is added', () => {
  35. it('should save permission to db', () => {
  36. const userItem = {
  37. id: 2,
  38. login: 'user2',
  39. };
  40. wrapper
  41. .instance()
  42. .userPicked(userItem)
  43. .then(() => {
  44. expect(backendSrv.post.mock.calls.length).toBe(1);
  45. expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
  46. });
  47. });
  48. });
  49. describe('when permission for team is added', () => {
  50. it('should save permission to db', () => {
  51. const teamItem = {
  52. id: 2,
  53. name: 'ug1',
  54. };
  55. wrapper
  56. .instance()
  57. .teamPicked(teamItem)
  58. .then(() => {
  59. expect(backendSrv.post.mock.calls.length).toBe(1);
  60. expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
  61. });
  62. });
  63. });
  64. });