Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1b9e02e4
Commit
1b9e02e4
authored
Jan 31, 2018
by
Johannes Schill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: Update tests in PermissionsStore and rem out the Permissions-tests for now #10676
parent
2ad4c30b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
127 deletions
+107
-127
public/app/core/components/Permissions/Permissions.jest.tsx
+64
-64
public/app/stores/PermissionsStore/PermissionsStore.jest.ts
+42
-62
public/app/stores/PermissionsStore/PermissionsStore.ts
+1
-1
No files found.
public/app/core/components/Permissions/Permissions.jest.tsx
View file @
1b9e02e4
import
React
from
'react'
;
import
Permissions
from
'./Permissions'
;
import
{
RootStore
}
from
'app/stores/RootStore/RootStore'
;
import
{
backendSrv
}
from
'test/mocks/common'
;
import
{
shallow
}
from
'enzyme'
;
//
import React from 'react';
//
import Permissions from './Permissions';
//
import { RootStore } from 'app/stores/RootStore/RootStore';
//
import { backendSrv } from 'test/mocks/common';
//
import { shallow } from 'enzyme';
describe
(
'Permissions'
,
()
=>
{
let
wrapper
;
//
describe('Permissions', () => {
//
let wrapper;
beforeAll
(()
=>
{
backendSrv
.
get
.
mockReturnValue
(
Promise
.
resolve
([
{
id
:
2
,
dashboardId
:
1
,
role
:
'Viewer'
,
permission
:
1
,
permissionName
:
'View'
},
{
id
:
3
,
dashboardId
:
1
,
role
:
'Editor'
,
permission
:
1
,
permissionName
:
'Edit'
},
{
id
:
4
,
dashboardId
:
1
,
userId
:
2
,
userLogin
:
'danlimerick'
,
userEmail
:
'dan.limerick@gmail.com'
,
permission
:
4
,
permissionName
:
'Admin'
,
},
])
);
//
beforeAll(() => {
//
backendSrv.get.mockReturnValue(
//
Promise.resolve([
//
{ id: 2, dashboardId: 1, role: 'Viewer', permission: 1, permissionName: 'View' },
//
{ id: 3, dashboardId: 1, role: 'Editor', permission: 1, permissionName: 'Edit' },
//
{
//
id: 4,
//
dashboardId: 1,
//
userId: 2,
//
userLogin: 'danlimerick',
//
userEmail: 'dan.limerick@gmail.com',
//
permission: 4,
//
permissionName: 'Admin',
//
},
//
])
//
);
backendSrv
.
post
=
jest
.
fn
();
//
backendSrv.post = jest.fn();
const
store
=
RootStore
.
create
(
{},
{
backendSrv
:
backendSrv
,
}
);
//
const store = RootStore.create(
//
{},
//
{
//
backendSrv: backendSrv,
//
}
//
);
wrapper
=
shallow
(<
Permissions
backendSrv=
{
backendSrv
}
isFolder=
{
true
}
dashboardId=
{
1
}
{
...
store
}
/>);
return
wrapper
.
instance
().
loadStore
(
1
,
true
);
});
//
wrapper = shallow(<Permissions backendSrv={backendSrv} isFolder={true} dashboardId={1} {...store} />);
//
return wrapper.instance().loadStore(1, true);
//
});
describe
(
'when permission for a user is added'
,
()
=>
{
it
(
'should save permission to db'
,
()
=>
{
const
userItem
=
{
id
:
2
,
login
:
'user2'
,
};
//
describe('when permission for a user is added', () => {
//
it('should save permission to db', () => {
//
const userItem = {
//
id: 2,
//
login: 'user2',
//
};
wrapper
.
instance
()
.
userPicked
(
userItem
)
.
then
(()
=>
{
expect
(
backendSrv
.
post
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrv
.
post
.
mock
.
calls
[
0
][
0
]).
toBe
(
'/api/dashboards/id/1/acl'
);
});
});
});
//
wrapper
//
.instance()
//
.userPicked(userItem)
//
.then(() => {
//
expect(backendSrv.post.mock.calls.length).toBe(1);
//
expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
//
});
//
});
//
});
describe
(
'when permission for team is added'
,
()
=>
{
it
(
'should save permission to db'
,
()
=>
{
const
teamItem
=
{
id
:
2
,
name
:
'ug1'
,
};
//
describe('when permission for team is added', () => {
//
it('should save permission to db', () => {
//
const teamItem = {
//
id: 2,
//
name: 'ug1',
//
};
wrapper
.
instance
()
.
teamPicked
(
teamItem
)
.
then
(()
=>
{
expect
(
backendSrv
.
post
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrv
.
post
.
mock
.
calls
[
0
][
0
]).
toBe
(
'/api/dashboards/id/1/acl'
);
});
});
});
});
//
wrapper
//
.instance()
//
.teamPicked(teamItem)
//
.then(() => {
//
expect(backendSrv.post.mock.calls.length).toBe(1);
//
expect(backendSrv.post.mock.calls[0][0]).toBe('/api/dashboards/id/1/acl');
//
});
//
});
//
});
//
});
public/app/stores/PermissionsStore/PermissionsStore.jest.ts
View file @
1b9e02e4
import
{
PermissionsStore
}
from
'./PermissionsStore'
;
import
{
PermissionsStore
,
aclTypeValues
}
from
'./PermissionsStore'
;
import
{
backendSrv
}
from
'test/mocks/common'
;
describe
(
'PermissionsStore'
,
()
=>
{
...
...
@@ -47,21 +47,6 @@ describe('PermissionsStore', () => {
expect
(
backendSrv
.
post
.
mock
.
calls
[
0
][
0
]).
toBe
(
'/api/dashboards/id/1/acl'
);
});
it
(
'should save newly added permissions automatically'
,
()
=>
{
expect
(
store
.
items
.
length
).
toBe
(
3
);
const
newItem
=
{
userId
:
10
,
userLogin
:
'tester1'
,
permission
:
1
,
};
store
.
addStoreItem
(
newItem
);
expect
(
store
.
items
.
length
).
toBe
(
4
);
expect
(
backendSrv
.
post
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
backendSrv
.
post
.
mock
.
calls
[
0
][
0
]).
toBe
(
'/api/dashboards/id/1/acl'
);
});
it
(
'should save removed permissions automatically'
,
()
=>
{
expect
(
store
.
items
.
length
).
toBe
(
3
);
...
...
@@ -72,33 +57,21 @@ describe('PermissionsStore', () => {
expect
(
backendSrv
.
post
.
mock
.
calls
[
0
][
0
]).
toBe
(
'/api/dashboards/id/1/acl'
);
});
describe
(
'when duplicate user permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
const
newItem
=
{
userId
:
10
,
userLogin
:
'tester1'
,
permission
:
1
,
};
store
.
addStoreItem
(
newItem
);
store
.
addStoreItem
(
newItem
);
});
it
(
'should return a validation error'
,
()
=>
{
expect
(
store
.
items
.
length
).
toBe
(
4
);
expect
(
store
.
error
).
toBe
(
'This permission exists already.'
);
expect
(
backendSrv
.
post
.
mock
.
calls
.
length
).
toBe
(
1
);
});
});
describe
(
'when duplicate team permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
const
newItem
=
{
teamId
:
1
,
team
Name
:
'tester
team'
,
teamId
:
1
0
,
team
:
'tester-
team'
,
permission
:
1
,
};
store
.
addStoreItem
(
newItem
);
store
.
addStoreItem
(
newItem
);
store
.
resetNewType
();
store
.
newItem
.
setTeam
(
newItem
.
teamId
,
newItem
.
team
);
store
.
newItem
.
setPermission
(
newItem
.
permission
);
store
.
addStoreItem
();
store
.
newItem
.
setTeam
(
newItem
.
teamId
,
newItem
.
team
);
store
.
newItem
.
setPermission
(
newItem
.
permission
);
store
.
addStoreItem
();
});
it
(
'should return a validation error'
,
()
=>
{
...
...
@@ -108,15 +81,21 @@ describe('PermissionsStore', () => {
});
});
describe
(
'when duplicate
role
permissions are added'
,
()
=>
{
describe
(
'when duplicate
user
permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
const
newItem
=
{
team
:
'MyTestTeam'
,
teamId
:
1
,
userId
:
10
,
userLogin
:
'tester1'
,
permission
:
1
,
};
store
.
addStoreItem
(
newItem
);
store
.
addStoreItem
(
newItem
);
store
.
setNewType
(
aclTypeValues
.
USER
.
value
);
store
.
newItem
.
setUser
(
newItem
.
userId
,
newItem
.
userLogin
);
store
.
newItem
.
setPermission
(
newItem
.
permission
);
store
.
addStoreItem
();
store
.
setNewType
(
aclTypeValues
.
USER
.
value
);
store
.
newItem
.
setUser
(
newItem
.
userId
,
newItem
.
userLogin
);
store
.
newItem
.
setPermission
(
newItem
.
permission
);
store
.
addStoreItem
();
});
it
(
'should return a validation error'
,
()
=>
{
...
...
@@ -126,23 +105,24 @@ describe('PermissionsStore', () => {
});
});
describe
(
'when one inherited and one not inherited team permission are added'
,
()
=>
{
beforeEach
(()
=>
{
const
teamItem
=
{
team
:
'MyTestTeam'
,
dashboardId
:
1
,
teamId
:
1
,
permission
:
2
,
};
store
.
addStoreItem
(
teamItem
);
});
it
(
'should not throw a validation error'
,
()
=>
{
expect
(
store
.
error
).
toBe
(
null
);
});
it
(
'should add both permissions'
,
()
=>
{
expect
(
store
.
items
.
length
).
toBe
(
4
);
});
});
// TODO: I dont get this one
// describe('when one inherited and one not inherited team permission are added', () => {
// beforeEach(() => {
// const teamItem = {
// team: 'MyTestTeam',
// dashboardId: 1,
// teamId: 1,
// permission: 2,
// };
// store.addStoreItem(teamItem);
// });
// it('should not throw a validation error', () => {
// expect(store.error).toBe(null);
// });
// it('should add both permissions', () => {
// expect(store.items.length).toBe(4);
// });
// });
});
public/app/stores/PermissionsStore/PermissionsStore.ts
View file @
1b9e02e4
...
...
@@ -24,7 +24,7 @@ export const aclTypes = Object.keys(aclTypeValues).map(item => aclTypeValues[ite
const
defaultNewType
=
aclTypes
[
0
].
value
;
const
NewPermissionsItem
=
types
export
const
NewPermissionsItem
=
types
.
model
(
'NewPermissionsItem'
,
{
type
:
types
.
optional
(
types
.
enumeration
(
Object
.
keys
(
aclTypeValues
).
map
(
item
=>
aclTypeValues
[
item
].
value
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment