Skip to content

Commit

Permalink
#316 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prayerslayer committed Oct 1, 2015
1 parent b450fd8 commit 18e4f54
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
5 changes: 3 additions & 2 deletions client/lib/application/src/access-form/access-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MINT_BUCKET_TEMPLATE from 'MINT_BUCKET_TEMPLATE';

function getDefaultBucket(account) {
return MINT_BUCKET_TEMPLATE
.replace("${id}", account.id);
.replace('${id}', account.id);
}

class AccessForm extends React.Component {
Expand Down Expand Up @@ -130,9 +130,10 @@ class AccessForm extends React.Component {
<label>Credential Distribution</label>
<small>Activate credential distribution into these S3 buckets (<a href='http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html'>Naming Conventions</a>). A <code>*</code> indicates unsaved changes.</small>
{ this.state.s3_buckets.length === 0 && defaultAccount ?
<div>
<div data-block='mint-bucket-suggestion'>
<small>Psst, your mint bucket is probably: </small>
<span
data-block='mint-bucket-add-suggestion'
onClick={this.addBucket.bind(this, getDefaultBucket(defaultAccount))}
className='btn btn-default btn-smaller'>
<Icon name='plus' /> <span>{getDefaultBucket(defaultAccount)}</span>
Expand Down
40 changes: 36 additions & 4 deletions client/lib/application/test/access-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UserStore from 'common/src/data/user/user-store';
import UserActions from 'common/src/data/user/user-actions';
import AccessForm from 'application/src/access-form/access-form.jsx';

const MOCK_KIO = {
const OAUTH_KIO = {
id: 'kio',
username: 'kio-robot',
last_password_rotation: '2015-01-01T12:42:41Z',
Expand All @@ -20,13 +20,21 @@ const MOCK_KIO = {
has_problems: false,
redirect_url: 'http://example.com/oauth',
s3_buckets: [
'kio-stups-bucket'
],
scopes: [{
resource_type_id: 'customer',
scope_id: 'read_all'
}]
};
},
APP_KIO = {
id: 'kio',
team_id: 'stups',
active: true
},
ACCOUNTS = [{
id: '123',
name: 'stups'
}];

class MockFlux extends Flummox {
constructor() {
Expand Down Expand Up @@ -58,10 +66,13 @@ describe('The access control form view', () => {
flux.getStore('essentials').receiveScopes(['customer', [{
id: 'read_all'
}]]);
flux.getStore('mint').receiveOAuthConfig(['kio', MOCK_KIO]);
flux.getStore('mint').receiveOAuthConfig(['kio', OAUTH_KIO]);
flux.getStore('kio').receiveApplication(APP_KIO);
flux.getStore('user').receiveAccounts(ACCOUNTS);
actionSpy = sinon.stub(flux.getActions('mint'), 'saveOAuthConfig', () => {
return Promise.resolve();
});

props = {
flux: flux,
applicationId: 'kio'
Expand All @@ -74,4 +85,25 @@ describe('The access control form view', () => {
TestUtils.Simulate.submit(f);
expect(actionSpy.calledOnce).to.be.true;
});

it('should suggest a mint bucket', () => {
TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'mint-bucket-suggestion');
});

it('should add suggested bucket to list', () => {
expect(() => {
TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'editable-list-item');
}).to.throw;
let btn = TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'mint-bucket-add-suggestion');
TestUtils.Simulate.click(btn);
TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'editable-list-item');
});

it('should not suggest after adding', () => {
let btn = TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'mint-bucket-add-suggestion');
TestUtils.Simulate.click(btn);
expect(() => {
TestUtils.findRenderedDOMComponentWithAttributeValue(form, 'data-block', 'mint-bucket-suggestion');
}).to.throw;
});
});
2 changes: 1 addition & 1 deletion client/mocha-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ global.YTENV_SERVICE_URL_TLD = '';
global.YTENV_DOCKER_REGISTRY = '';
global.YTENV_RESOURCE_WHITELIST = '';
global.YTENV_APPLICATION_WHITELIST = '';
global.YTENV_MINT_BUCKET_TEMPLATE = '';
global.YTENV_MINT_BUCKET_TEMPLATE = '';
3 changes: 2 additions & 1 deletion client/webpack.production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ module.exports = {
DOCKER_REGISTRY: 'YTENV_DOCKER_REGISTRY',
SERVICE_URL_TLD: 'YTENV_SERVICE_URL_TLD',
RESOURCE_WHITELIST: 'YTENV_RESOURCE_WHITELIST',
APPLICATION_WHITELIST: 'YTENV_APPLICATION_WHITELIST'
APPLICATION_WHITELIST: 'YTENV_APPLICATION_WHITELIST',
MINT_BUCKET_TEMPLATE: 'YTENV_MINT_BUCKET_TEMPLATE'
},
eslint: {
configFile: './.eslintrc',
Expand Down
1 change: 1 addition & 0 deletions client/webpack.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
SERVICE_URL_TLD: 'YTENV_SERVICE_URL_TLD',
RESOURCE_WHITELIST: 'YTENV_RESOURCE_WHITELIST',
APPLICATION_WHITELIST: 'YTENV_APPLICATION_WHITELIST',
MINT_BUCKET_TEMPLATE: 'YTENV_MINT_BUCKET_TEMPLATE',
// needed because otherwise two react instances
// are running in tests and they trip each other up
react: 'var React'
Expand Down

0 comments on commit 18e4f54

Please sign in to comment.