Skip to content

Commit

Permalink
feat(deploy): derive default deployment name from the filename
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Oct 1, 2019
1 parent 5e3b3c2 commit 49100f8
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client/src/plugins/deployment-tool/DeploymentTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ export default class DeploymentTool extends PureComponent {
}

getDetailsFromUserInput(tab, details) {
const initialDetails = this.getInitialDetails(tab, details);

return new Promise(resolve => {
const handleClose = (result) => {
const handleClose = result => {

this.setState({
modalState: null
Expand All @@ -151,7 +153,7 @@ export default class DeploymentTool extends PureComponent {
this.setState({
modalState: {
tab,
details,
details: initialDetails,
handleClose
}
});
Expand Down Expand Up @@ -187,6 +189,16 @@ export default class DeploymentTool extends PureComponent {
return connectionError;
}

getInitialDetails(tab, providedDetails) {
const details = { ...providedDetails };

if (!details.deploymentName) {
details.deploymentName = withoutExtension(tab.name);
}

return details;
}

getValidatedFields(values) {
const fields = Object.keys(values);

Expand Down Expand Up @@ -286,3 +298,7 @@ export default class DeploymentTool extends PureComponent {
function isFocusedOnInput(event) {
return event.type === 'focus' && ['INPUT', 'TEXTAREA'].includes(event.target.tagName);
}

function withoutExtension(name) {
return name.replace(/\.[^.]+$/, '');
}
137 changes: 137 additions & 0 deletions client/src/plugins/deployment-tool/__tests__/DeploymentToolSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

/* global sinon */

import React from 'react';

import { mount, shallow } from 'enzyme';

import DeploymentTool from '../DeploymentTool';
import DeploymentDetailsModal from '../DeploymentDetailsModal';


describe('<DeploymentTool>', () => {

it('should render', () => {
createDeploymentTool();
});


it('should derive the default deployment name from filename', () => {

// given
const { instance } = createDeploymentTool();

// when
const details = instance.getInitialDetails({ name });

// then
expect(details).to.have.property('deploymentName', name);
});


describe('#deploy', () => {

let fetchStub,
mounted;

beforeEach(() => {
fetchStub = sinon.stub(window, 'fetch');
});

afterEach(() => {
fetchStub.restore();

if (mounted) {
mounted.unmount();
}
});


it('should derive deployment name from filename', async () => {

// given
const activeTab = createTab({ name: 'foo.bpmn' });
const {
wrapper,
instance
} = createDeploymentTool({ activeTab }, mount);

mounted = wrapper;

// when
instance.deploy();

await nextTick();
wrapper.update();

// then
const modal = wrapper.find(DeploymentDetailsModal).first();

const onClose = modal.prop('onClose');
const deploymentName = modal.find('input[name="deploymentName"]').first().getDOMNode().value;

expect(deploymentName).to.eql('foo');

onClose();
});

});
});



// helper ////
function createDeploymentTool({
activeTab = createTab(),
...props
} = {}, render = shallow) {
const subscribe = (event, callback) => {
event === 'app.activeTabChanged' && callback(activeTab);
};

const triggerAction = event => {
switch (event) {
case 'save':
return activeTab;
}
};

const wrapper = render(<DeploymentTool
subscribe={ subscribe }
triggerAction={ triggerAction }
{ ...props }
/>);

return {
wrapper,
instance: wrapper.instance()
};
}

function createTab(overrides = {}) {
return {
id: 42,
name: 'foo.bar',
type: 'bar',
title: 'unsaved',
file: {
name: 'foo.bar',
contents: '',
path: null
},
...overrides
};
}

function nextTick() {
return new Promise(resolve => process.nextTick(() => resolve()));
}

0 comments on commit 49100f8

Please sign in to comment.