Michael Klein 39c5b91272
ui: chore upgrade to ember-qunit v5 (#14430)
* Refactor remaining `moduleFor`-tests

`moduleFor*` will be removed from ember-qunit v5

* Upgrade ember-qunit to v5

* Update how we use ember-sinon-qunit

With ember-qunit v5 we need to use ember-sinon-qunit differently.

* Fix submit-blank test

We can't click on disabled buttons with new test-helpers.
We need to adapt the test accordingly.

* Make sure we await fill-in with form yaml step

We need to await `fill-in`. This changes the reducer
function in the step to create a proper await
chain.

* Fix show-routing test

We need to await a tick before visiting again.

* Remove redundant `wait one tick`-step

* remove unneeded "next Tick" promise from form step

* Increase timeout show-routing feature

* Comment on pause hack for show-routing test
2022-09-01 17:37:37 +02:00

121 lines
3.5 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul';
module('Unit | Serializer | application', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
assert.ok(serializer);
});
test('respondForDeleteRecord returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
// adapter.uidForURL = this.stub().returnsArg(0);
const respond = function(cb) {
const headers = {};
const body = true;
return cb(headers, body);
};
const expected = {
'primary-key-name': 'name',
};
const actual = serializer.respondForDeleteRecord(respond, {}, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
// assert.ok(adapter.uidForURL.calledOnce);
});
test('respondForQueryRecord returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
const expected = {
Datacenter: 'dc-1',
Name: 'name',
[META]: {},
'primary-key-name': 'name',
};
const respond = function(cb) {
const headers = {};
const body = {
Name: 'name',
};
return cb(headers, body);
};
const actual = serializer.respondForQueryRecord(respond, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
});
test('respondForQuery returns the expected pojo structure', function(assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('application');
serializer.primaryKey = 'primary-key-name';
serializer.slugKey = 'Name';
serializer.fingerprint = function(primary, slug, foreignValue) {
return function(item) {
return {
...item,
...{
Datacenter: foreignValue,
[primary]: item[slug],
},
};
};
};
const expected = [
{
Datacenter: 'dc-1',
Name: 'name1',
'primary-key-name': 'name1',
},
{
Datacenter: 'dc-1',
Name: 'name2',
'primary-key-name': 'name2',
},
];
const respond = function(cb) {
const headers = {};
const body = [
{
Name: 'name1',
},
{
Name: 'name2',
},
];
return cb(headers, body);
};
const actual = serializer.respondForQuery(respond, { Name: 'name', dc: 'dc-1' });
assert.deepEqual(actual, expected);
// assert.ok(adapter.uidForURL.calledTwice);
});
});