Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #9 from contolini/master
Browse files Browse the repository at this point in the history
Fix Add Asset bug
  • Loading branch information
dgreisen-cfpb committed Aug 5, 2015
2 parents 30f3121 + 50e3853 commit c042fb4
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 29 deletions.
5 changes: 1 addition & 4 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<meta charset="utf-8">
<title>Dash</title>

<!--[if lt IE 9]> <link rel="stylesheet" href="/static/css/main.ie.min.css"> <![endif]-->
<!--[if gt IE 8]><!--> <link rel="stylesheet" href="/static/css/main.min.css"> <!--<![endif]-->

<link rel="stylesheet" href="css/app.min-cdabe0c9.css"/>


Expand All @@ -16,7 +13,7 @@

<section id="app"></section>

<script src="js/app.min-2467c18d.js"></script>
<script src="js/app.min-1c6411a4.js"></script>

</body>
</html>
4 changes: 2 additions & 2 deletions dist/js/app.min-2467c18d.js → dist/js/app.min-1c6411a4.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/js/components/AddAsset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ var TeamActions = require('../actions/TeamActions');
var _ = require('lodash');

var AddAsset = React.createClass({

propTypes: {
teamName: React.PropTypes.string.isRequired,
resourceName: React.PropTypes.string.isRequired,
isAddingAsset: React.PropTypes.bool.isRequired
},
getInitialState: function() {
return {
isOpen: false,
Expand Down
3 changes: 1 addition & 2 deletions src/js/components/TeamPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var TeamPage = React.createClass({
var assetDetails = allAssetDetails[resourceName] || [];
var canAdd = resource.perms.add;
var canRemove = resource.perms.remove;
var addAsset = (canAdd) ? <AddAsset teamName={teamName} resourceNam={resourceName}
var addAsset = (canAdd) ? <AddAsset teamName={teamName} resourceName={resourceName}
isAddingAsset={team.isAddingAsset[resourceName]}/> : '';
var assets = resource.assets || [];
return (
Expand All @@ -80,7 +80,6 @@ var TeamPage = React.createClass({
</div>
)
})
console.log('isInProgress', isInProgress)
return (
<div>{isInProgress}
<h1>{teamName}
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/__tests__/AddAsset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Add asset component', function() {
TestUtils = React.addons.TestUtils;

addAssetComponent = TestUtils.renderIntoDocument(
<AddAsset/>
<AddAsset teamName={''}/>
);
});

Expand Down
52 changes: 41 additions & 11 deletions src/js/utils/__tests__/common-test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
jest.dontMock('../../utils/common');
var common, resources, $, userId;

describe('Get all teams method', function() {
it('should call the teams URL', function() {
var common = require('../../utils/common'),
resources = require('../../utils/resources'),
$ = require('jquery');
common.getAllTeams();
beforeEach(function(){
common = require('../../utils/common');
resources = require('../../utils/resources');
$ = require('jquery');
userId = '123';
});


describe('Get all teams method', function(){
it('should call the teams URL', function(){
common.getAllTeams();
expect($.get).toBeCalledWith(resources.routes.ALL_TEAMS);

});
});

describe('User and team functions/actions', function() {
it('should call the correct routes when user actions are invoked', function() {
var common = require('../../utils/common'),
resources = require('../../utils/resources'),
$ = require('jquery');
describe('User and team functions/actions', function(){
it('should call the correct routes when user actions are invoked', function(){

var opts = {'foo': 'boo'};


common.getAllUsers();
expect($.get).toBeCalledWith(resources.routes.ALL_USERS);

Expand All @@ -44,4 +48,30 @@ describe('User and team functions/actions', function() {
expect($.ajax).toBeCalled();

});

});

describe('User manipulations', function(){
it('should deactivate user', function(){
resources.routes = {
userActions: function(user){
return '/kratos/users/' + userId
}
};
common.deactivateUser(userId);
expect($.ajax.mock.calls[0][0].url).toBe('/kratos/users/' + userId);
expect($.ajax.mock.calls[0][0].type).toEqual('DELETE');

});
it('should reactivate user', function(){
resources.routes = {
userActions: function(user){
return '/kratos/users/' + userId
}
};
common.reactivateUser(userId);
expect($.ajax.mock.calls[0][0].url).toBe('/kratos/users/' + userId);
expect($.ajax.mock.calls[0][0].type).toEqual('PUT');

});
});
6 changes: 6 additions & 0 deletions src/js/utils/__tests__/resources-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ describe('resources functions tests', function() {
var expectedUrl = '/kratos/users/teamName/data/somePath',
actualUrl = resources.routes.userData(opts);
expect(actualUrl).toBe(expectedUrl);
});

it('should create a correct user action request url from opt', function() {
var expectedUrl = '/kratos/users/userId',
actualUrl = resources.routes.userActions(opts.userId);
expect(actualUrl).toBe(expectedUrl);
})
});
35 changes: 26 additions & 9 deletions src/js/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ var resources = require('./resources');
var common = {};


common.getAllTeams = function() {
common.getAllTeams = function(){
return $.get(resources.routes.ALL_TEAMS);
};

common.getAllUsers = function() {
common.getAllUsers = function(){
return $.get(resources.routes.ALL_USERS);
};

common.teamCreate = function(action) {
common.teamCreate = function(action){
return $.ajax({
url: resources.routes.team(action),
dataType: 'json',
type: 'PUT'
});
}

common.teamAddMember = function(action) {
common.teamAddMember = function(action){
return $.ajax({
url: resources.routes.teamMember(action),
dataType: 'json',
type: 'PUT'
});
};

common.teamRemoveMember = function(action) {
common.teamRemoveMember = function(action){
return $.ajax({
url: resources.routes.teamMember(action),
dataType: 'json',
type: 'DELETE'
});
};

common.teamAddAsset = function(action) {
common.teamAddAsset = function(action){
return $.ajax({
url: resources.routes.teamAddAsset(action),
dataType: 'json',
Expand All @@ -46,19 +46,36 @@ common.teamAddAsset = function(action) {
});
};

common.teamRemoveAsset = function(action) {
common.teamRemoveAsset = function(action){
return $.ajax({
url: resources.routes.teamRemoveAsset(action),
dataType: 'json',
type: 'DELETE'
});
};

common.getCurrentUserInfo = function() {
common.getCurrentUserInfo = function(){
return $.get(resources.routes.CURRENT_USER_INFO)
};

common.userData = function(action) {
common.deactivateUser = function(userId){
return $.ajax({
url: resources.routes.userActions(userId),
dataType: 'json',
type: 'DELETE'
});
};

common.reactivateUser = function(userId){
return $.ajax({
url: resources.routes.userActions(userId),
dataType: 'json',
type: 'PUT'
});
};


common.userData = function(action){
return $.ajax({
url: resources.routes.userData(action),
method: 'PUT',
Expand Down
4 changes: 4 additions & 0 deletions src/js/utils/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var resources = {
userData: function( action ) {
return resources.baseUrl + '/users/' + action.id + '/data/' + (action.path || '');
},
userActions: function( userId ){
return resources.routes.ALL_USERS + '/' + userId
},

ALL_TEAMS: '/kratos/orgs/devdesign/teams',
ALL_USERS: '/kratos/users',
CURRENT_USER_INFO: '/kratos/user'
Expand Down

0 comments on commit c042fb4

Please sign in to comment.