mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
dashfolders: prettify on tests file
This commit is contained in:
parent
1e496ec76c
commit
5b6ee6f37b
@ -1,12 +1,12 @@
|
|||||||
import { AclCtrl } from "../acl";
|
import { AclCtrl } from '../acl';
|
||||||
|
|
||||||
describe("AclCtrl", () => {
|
describe('AclCtrl', () => {
|
||||||
const backendSrv = {
|
const backendSrv = {
|
||||||
getDashboard: jest.fn(() =>
|
getDashboard: jest.fn(() =>
|
||||||
Promise.resolve({ id: 1, meta: { isFolder: false } })
|
Promise.resolve({ id: 1, meta: { isFolder: false } })
|
||||||
),
|
),
|
||||||
get: jest.fn(() => Promise.resolve([])),
|
get: jest.fn(() => Promise.resolve([])),
|
||||||
post: jest.fn(() => Promise.resolve([]))
|
post: jest.fn(() => Promise.resolve([])),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ctrl;
|
let ctrl;
|
||||||
@ -24,45 +24,45 @@ describe("AclCtrl", () => {
|
|||||||
backendSrvPostMock = backendSrv.post as any;
|
backendSrvPostMock = backendSrv.post as any;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when permissions are added", () => {
|
describe('when permissions are added', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const userItem = {
|
const userItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
login: "user2"
|
login: 'user2',
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.userPicked(userItem);
|
ctrl.userPicked(userItem);
|
||||||
|
|
||||||
const teamItem = {
|
const teamItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "ug1"
|
name: 'ug1',
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.groupPicked(teamItem);
|
ctrl.groupPicked(teamItem);
|
||||||
|
|
||||||
ctrl.newType = "Editor";
|
ctrl.newType = 'Editor';
|
||||||
ctrl.typeChanged();
|
ctrl.typeChanged();
|
||||||
|
|
||||||
ctrl.newType = "Viewer";
|
ctrl.newType = 'Viewer';
|
||||||
ctrl.typeChanged();
|
ctrl.typeChanged();
|
||||||
|
|
||||||
return ctrl.update();
|
return ctrl.update();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should sort the result by role, team and user", () => {
|
it('should sort the result by role, team and user', () => {
|
||||||
expect(ctrl.items[0].role).toBe("Viewer");
|
expect(ctrl.items[0].role).toBe('Viewer');
|
||||||
expect(ctrl.items[1].role).toBe("Editor");
|
expect(ctrl.items[1].role).toBe('Editor');
|
||||||
expect(ctrl.items[2].teamId).toBe(2);
|
expect(ctrl.items[2].teamId).toBe(2);
|
||||||
expect(ctrl.items[3].userId).toBe(2);
|
expect(ctrl.items[3].userId).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should save permissions to db", () => {
|
it('should save permissions to db', () => {
|
||||||
expect(backendSrvPostMock.mock.calls[0][0]).toBe(
|
expect(backendSrvPostMock.mock.calls[0][0]).toBe(
|
||||||
"/api/dashboards/id/1/acl"
|
'/api/dashboards/id/1/acl'
|
||||||
);
|
);
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[0].role).toBe("Viewer");
|
expect(backendSrvPostMock.mock.calls[0][1].items[0].role).toBe('Viewer');
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[0].permission).toBe(1);
|
expect(backendSrvPostMock.mock.calls[0][1].items[0].permission).toBe(1);
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[1].role).toBe("Editor");
|
expect(backendSrvPostMock.mock.calls[0][1].items[1].role).toBe('Editor');
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[1].permission).toBe(1);
|
expect(backendSrvPostMock.mock.calls[0][1].items[1].permission).toBe(1);
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[2].teamId).toBe(2);
|
expect(backendSrvPostMock.mock.calls[0][1].items[2].teamId).toBe(2);
|
||||||
expect(backendSrvPostMock.mock.calls[0][1].items[2].permission).toBe(1);
|
expect(backendSrvPostMock.mock.calls[0][1].items[2].permission).toBe(1);
|
||||||
@ -71,94 +71,94 @@ describe("AclCtrl", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when duplicate role permissions are added", () => {
|
describe('when duplicate role permissions are added', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctrl.items = [];
|
ctrl.items = [];
|
||||||
|
|
||||||
ctrl.newType = "Editor";
|
ctrl.newType = 'Editor';
|
||||||
ctrl.typeChanged();
|
ctrl.typeChanged();
|
||||||
|
|
||||||
ctrl.newType = "Editor";
|
ctrl.newType = 'Editor';
|
||||||
ctrl.typeChanged();
|
ctrl.typeChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw a validation error", () => {
|
it('should throw a validation error', () => {
|
||||||
expect(ctrl.error).toBe(ctrl.duplicateError);
|
expect(ctrl.error).toBe(ctrl.duplicateError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add the duplicate permission", () => {
|
it('should not add the duplicate permission', () => {
|
||||||
expect(ctrl.items.length).toBe(1);
|
expect(ctrl.items.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when duplicate user permissions are added", () => {
|
describe('when duplicate user permissions are added', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctrl.items = [];
|
ctrl.items = [];
|
||||||
|
|
||||||
const userItem = {
|
const userItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
login: "user2"
|
login: 'user2',
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.userPicked(userItem);
|
ctrl.userPicked(userItem);
|
||||||
ctrl.userPicked(userItem);
|
ctrl.userPicked(userItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw a validation error", () => {
|
it('should throw a validation error', () => {
|
||||||
expect(ctrl.error).toBe(ctrl.duplicateError);
|
expect(ctrl.error).toBe(ctrl.duplicateError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add the duplicate permission", () => {
|
it('should not add the duplicate permission', () => {
|
||||||
expect(ctrl.items.length).toBe(1);
|
expect(ctrl.items.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when duplicate team permissions are added", () => {
|
describe('when duplicate team permissions are added', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctrl.items = [];
|
ctrl.items = [];
|
||||||
|
|
||||||
const teamItem = {
|
const teamItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "ug1"
|
name: 'ug1',
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.groupPicked(teamItem);
|
ctrl.groupPicked(teamItem);
|
||||||
ctrl.groupPicked(teamItem);
|
ctrl.groupPicked(teamItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw a validation error", () => {
|
it('should throw a validation error', () => {
|
||||||
expect(ctrl.error).toBe(ctrl.duplicateError);
|
expect(ctrl.error).toBe(ctrl.duplicateError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add the duplicate permission", () => {
|
it('should not add the duplicate permission', () => {
|
||||||
expect(ctrl.items.length).toBe(1);
|
expect(ctrl.items.length).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when one inherited and one not inherited team permission are added", () => {
|
describe('when one inherited and one not inherited team permission are added', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctrl.items = [];
|
ctrl.items = [];
|
||||||
|
|
||||||
const inheritedTeamItem = {
|
const inheritedTeamItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "ug1",
|
name: 'ug1',
|
||||||
dashboardId: -1
|
dashboardId: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.items.push(inheritedTeamItem);
|
ctrl.items.push(inheritedTeamItem);
|
||||||
|
|
||||||
const teamItem = {
|
const teamItem = {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "ug1"
|
name: 'ug1',
|
||||||
};
|
};
|
||||||
ctrl.groupPicked(teamItem);
|
ctrl.groupPicked(teamItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not throw a validation error", () => {
|
it('should not throw a validation error', () => {
|
||||||
expect(ctrl.error).toBe("");
|
expect(ctrl.error).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add both permissions", () => {
|
it('should add both permissions', () => {
|
||||||
expect(ctrl.items.length).toBe(2);
|
expect(ctrl.items.length).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user