fde7ca365a
* ui: Acceptance test improvements to prepare for more NS tests * ui: Namespace acceptance testing (#7005) * Update api-double and consul-api-double for http.body * Adds places where we missed passing the nspace through * Hardcode nspace CRUD to use the default nspace for policies and roles * Alter test helpers to allow us to control nspaces from the outside * Amends to allow tests to account for namespace, move ns from queryParam 1. We decided to move how we pass the namespace value through to the backend when performing write actions (create, update). Previoulsy we were using the queryParam although using the post body is the preferred method to send the Namespace details through to the backend. 2. Other various amends to take into account testing across multiple namespaced scenarios * Enable nspace testing by default * Remove last few occurances of old style http assertions We had informally 'deprecated' our old style of http assertions that relied on the order of http calls (even though that order was not important for the assertion). Following on from our namespace work we removed the majority of the old occrances of these old style assertions. This commit removes the remaining few, and also then cleans up the assertions/http.js file to only include the ones we are using. This reduces our available step count further and prevents any confusion over the usage of the old types and the new types. * ui: Namespace CRUD acceptance tests (#7016) * Upgrade consul-api-double * Add all the things required for testing: 1. edit and index page objects 2. enable CONSUL_NSPACE_COUNT cookie setting 3. enable mutating HTTP response bodies based on URL * Add acceptance test for nspace edit/delete/list and searching
114 lines
3.6 KiB
JavaScript
114 lines
3.6 KiB
JavaScript
import Component from '@ember/component';
|
|
import { get, set, computed } from '@ember/object';
|
|
import { alias } from '@ember/object/computed';
|
|
import { inject as service } from '@ember/service';
|
|
import { Promise } from 'rsvp';
|
|
|
|
import SlotsMixin from 'block-slots';
|
|
import WithListeners from 'consul-ui/mixins/with-listeners';
|
|
|
|
export default Component.extend(SlotsMixin, WithListeners, {
|
|
onchange: function() {},
|
|
|
|
error: function() {},
|
|
type: '',
|
|
|
|
dom: service('dom'),
|
|
container: service('search'),
|
|
formContainer: service('form'),
|
|
|
|
item: alias('form.data'),
|
|
|
|
selectedOptions: alias('items'),
|
|
|
|
init: function() {
|
|
this._super(...arguments);
|
|
this.searchable = this.container.searchable(this.type);
|
|
this.form = this.formContainer.form(this.type);
|
|
this.form.clear({ Datacenter: this.dc, Namespace: this.nspace });
|
|
},
|
|
options: computed('selectedOptions.[]', 'allOptions.[]', function() {
|
|
// It's not massively important here that we are defaulting `items` and
|
|
// losing reference as its just to figure out the diff
|
|
let options = this.allOptions || [];
|
|
const items = this.selectedOptions || [];
|
|
if (get(items, 'length') > 0) {
|
|
// find a proper ember-data diff
|
|
options = options.filter(item => !items.findBy('ID', get(item, 'ID')));
|
|
this.searchable.add(options);
|
|
}
|
|
return options;
|
|
}),
|
|
actions: {
|
|
search: function(term) {
|
|
// TODO: make sure we can either search before things are loaded
|
|
// or wait until we are loaded, guess power select take care of that
|
|
return new Promise(resolve => {
|
|
const remove = this.listen(this.searchable, 'change', function(e) {
|
|
remove();
|
|
resolve(e.target.data);
|
|
});
|
|
this.searchable.search(term);
|
|
});
|
|
},
|
|
reset: function() {
|
|
this.form.clear({ Datacenter: this.dc, Namespace: this.nspace });
|
|
},
|
|
open: function() {
|
|
if (!get(this, 'allOptions.closed')) {
|
|
set(this, 'allOptions', this.repo.findAllByDatacenter(this.dc, this.nspace));
|
|
}
|
|
},
|
|
save: function(item, items, success = function() {}) {
|
|
// Specifically this saves an 'new' option/child
|
|
// and then adds it to the selectedOptions, not options
|
|
const repo = this.repo;
|
|
set(item, 'CreateTime', new Date().getTime());
|
|
// TODO: temporary async
|
|
// this should be `set(this, 'item', repo.persist(item));`
|
|
// need to be sure that its saved before adding/closing the modal for now
|
|
// and we don't open the modal on prop change yet
|
|
item = repo.persist(item);
|
|
this.listen(item, 'message', e => {
|
|
this.actions.change.bind(this)(
|
|
{
|
|
target: {
|
|
name: 'items[]',
|
|
value: items,
|
|
},
|
|
},
|
|
items,
|
|
e.data
|
|
);
|
|
success();
|
|
});
|
|
this.listen(item, 'error', this.error.bind(this));
|
|
},
|
|
remove: function(item, items) {
|
|
const prop = this.repo.getSlugKey();
|
|
const value = get(item, prop);
|
|
const pos = items.findIndex(function(item) {
|
|
return get(item, prop) === value;
|
|
});
|
|
if (pos !== -1) {
|
|
return items.removeAt(pos, 1);
|
|
}
|
|
this.onchange({ target: this });
|
|
},
|
|
change: function(e, value, item) {
|
|
const event = this.dom.normalizeEvent(...arguments);
|
|
const items = value;
|
|
switch (event.target.name) {
|
|
case 'items[]':
|
|
set(item, 'CreateTime', new Date().getTime());
|
|
// this always happens synchronously
|
|
items.pushObject(item);
|
|
// TODO: Fire a proper event
|
|
this.onchange({ target: this });
|
|
break;
|
|
default:
|
|
}
|
|
},
|
|
},
|
|
});
|