forked from ManageIQ/manageiq-ui-classic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When catalog item is copied, the default behavior does not copy tags. This PR adds an option of copying tags. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1740399 Depends on #19206
- Loading branch information
Showing
4 changed files
with
115 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
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
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
107 changes: 107 additions & 0 deletions
107
app/javascript/spec/copy-catalog-form/copy-catalog-form.spec.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,107 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import fetchMock from 'fetch-mock'; | ||
import CopyCatalogForm from '../../components/copy-catalog-form/copy-catalog-form'; | ||
|
||
import '../helpers/miqAjaxButton'; | ||
import MiqFormRenderer from '../../forms/data-driven-form'; | ||
|
||
describe('Copy catalog form', () => { | ||
let initialProps; | ||
let cancelUrl; | ||
let copySavedUrl; | ||
let spyMiqAjaxButton; | ||
|
||
beforeEach(() => { | ||
initialProps = { | ||
catalogId: '10000000000000', | ||
originName: 'Template1', | ||
}; | ||
|
||
cancelUrl = `/catalog/servicetemplate_copy_cancel/${initialProps.catalogId}`; | ||
copySavedUrl = '/catalog/servicetemplate_copy_saved'; | ||
spyMiqAjaxButton = jest.spyOn(window, 'miqAjaxButton'); | ||
|
||
fetchMock | ||
.getOnce('/catalog/servicetemplates_names', { names: ['Template1', 'Template2'] }); | ||
}); | ||
|
||
afterEach(() => { | ||
fetchMock.restore(); | ||
}); | ||
|
||
it('should render correctly and set initialValue', (done) => { | ||
const wrapper = mount(<CopyCatalogForm {...initialProps} />); | ||
|
||
setImmediate(() => { | ||
wrapper.update(); | ||
expect(wrapper.find(MiqFormRenderer)).toHaveLength(1); | ||
expect(wrapper.find('input[name="name"]').instance().value).toEqual('Copy of Template1'); | ||
expect(wrapper.find('input[name="copy_tags"]').instance().value).toEqual('false'); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should handle cancel', (done) => { | ||
const wrapper = mount(<CopyCatalogForm {...initialProps} />); | ||
|
||
setImmediate(() => { | ||
wrapper.update(); | ||
wrapper.find('button').last().simulate('click'); // click on cancel | ||
expect(spyMiqAjaxButton).toHaveBeenCalledWith(cancelUrl); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should handle submit', (done) => { | ||
const postData = '{"id":"10000000000000","name":"Copy of Template1","copy_tags":false}'; | ||
fetchMock | ||
.postOnce('/catalog/save_copy_catalog', {}) | ||
|
||
const wrapper = mount(<CopyCatalogForm {...initialProps} />); | ||
|
||
setTimeout(() => { | ||
|
||
wrapper.update(); | ||
setTimeout(() => { | ||
wrapper.find('button').first().simulate('click'); | ||
setImmediate(() => { | ||
expect(spyMiqAjaxButton).toHaveBeenCalledWith(copySavedUrl); | ||
expect(fetchMock.lastOptions().body).toEqual(postData); | ||
done(); | ||
}); | ||
}, 1000); | ||
}, 1000); | ||
}); | ||
|
||
it('should handle submit with copy_tags checked', (done) => { | ||
const postData = '{"id":"10000000000000","name":"Copy of Template1","copy_tags":true}'; | ||
const wrapper = mount(<CopyCatalogForm {...initialProps} />); | ||
fetchMock | ||
.postOnce('/catalog/save_copy_catalog', {}) | ||
|
||
setImmediate(() => { | ||
wrapper.update(); | ||
const check_box = wrapper.find('input[name="copy_tags"]'); | ||
expect(check_box.instance().value).toEqual('false'); | ||
check_box.instance().checked = true; | ||
check_box.simulate('change'); | ||
|
||
expect(check_box.instance().value).toEqual('true'); | ||
|
||
done(); | ||
}); | ||
|
||
setTimeout(() => { | ||
setTimeout(() => { | ||
wrapper.find('button').first().simulate('click'); | ||
setImmediate(() => { | ||
expect(spyMiqAjaxButton).toHaveBeenCalledWith(copySavedUrl); | ||
expect(fetchMock.lastOptions().body).toEqual(postData); | ||
done(); | ||
}); | ||
}, 1000); | ||
}, 1000); | ||
}); | ||
}); |