-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deploy): derive default deployment name from the filename
- Loading branch information
Showing
2 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
client/src/plugins/deployment-tool/__tests__/DeploymentToolSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} |