open-consul/ui/packages/consul-ui/tests/steps/assertions/model.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

export default function(scenario, assert, find, currentPage, pauseUntil, pluralize) {
scenario
.then('pause until I see $number $model model[s]?', function(num, model) {
return pauseUntil(function(resolve, reject, retry) {
UI: Add support for blocking queries on the service instance detail page (#5487) This commit includes several pieces of functionality to enable services to be removed and the page to present information that this has happened but also keep the deleted information on the page. Along with the more usual blocking query based listing. To enable this: 1. Implements `meta` on the model (only available on collections in ember) 2. Adds new `catchable` ComputedProperty alongside a `listen` helper for working with specific errors that can be thrown from EventSources in an ember-like way. Briefly, normal computed properties update when a property changes, EventSources can additionally throw errors so we can catch them and show different visuals based on that. Also: Add support for blocking queries on the service instance detail page 1. Previous we could return undefined when a service instance has no proxy, but this means we have nothing to attach `meta` to. We've changed this to return an almost empty object, so with only a meta property. At first glance there doesn't seem to be any way to provide a proxy object to templates and be able to detect whether it is actually null or not so we instead change some conditional logic in the templates to detect the property we are using to generate the anchor. 2. Made a `pauseUntil` test helper function for steps where we wait for things. This helps for DRYness but also means if we can move away from setInterval to something else later, we can do it in one place 3. Whilst running into point 1 here, we managed to make the blocking queries eternally loop. Whilst this is due to an error in the code and shouldn't ever happen whilst in actual use, we've added an extra check so that we only recur/loop the blocking query if the previous response has a `meta.cursor` Adds support for blocking queries on the node detail page (#5489) 1. Moves data re-shaping for the templates variables into a repository so they are easily covered by blocking queries (into coordinatesRepo) 2. The node API returns a 404 as signal for deregistration, we also close the sessions and coordinates blocking queries when this happens
2019-03-22 17:24:40 +00:00
const len = currentPage()[pluralize(model)].filter(function(item) {
return item.isVisible;
}).length;
if (len === num) {
return resolve();
UI: Add support for blocking queries on the service instance detail page (#5487) This commit includes several pieces of functionality to enable services to be removed and the page to present information that this has happened but also keep the deleted information on the page. Along with the more usual blocking query based listing. To enable this: 1. Implements `meta` on the model (only available on collections in ember) 2. Adds new `catchable` ComputedProperty alongside a `listen` helper for working with specific errors that can be thrown from EventSources in an ember-like way. Briefly, normal computed properties update when a property changes, EventSources can additionally throw errors so we can catch them and show different visuals based on that. Also: Add support for blocking queries on the service instance detail page 1. Previous we could return undefined when a service instance has no proxy, but this means we have nothing to attach `meta` to. We've changed this to return an almost empty object, so with only a meta property. At first glance there doesn't seem to be any way to provide a proxy object to templates and be able to detect whether it is actually null or not so we instead change some conditional logic in the templates to detect the property we are using to generate the anchor. 2. Made a `pauseUntil` test helper function for steps where we wait for things. This helps for DRYness but also means if we can move away from setInterval to something else later, we can do it in one place 3. Whilst running into point 1 here, we managed to make the blocking queries eternally loop. Whilst this is due to an error in the code and shouldn't ever happen whilst in actual use, we've added an extra check so that we only recur/loop the blocking query if the previous response has a `meta.cursor` Adds support for blocking queries on the node detail page (#5489) 1. Moves data re-shaping for the templates variables into a repository so they are easily covered by blocking queries (into coordinatesRepo) 2. The node API returns a 404 as signal for deregistration, we also close the sessions and coordinates blocking queries when this happens
2019-03-22 17:24:40 +00:00
}
return retry();
}, `Expected ${num} ${model}s`);
})
.then('pause until I see $number $model model[s]? on the $component component', function(num, model, component) {
return pauseUntil(function(resolve, reject, retry) {
const obj = find(component);
const len = obj[pluralize(model)].filter(function(item) {
return item.isVisible;
}).length;
if (len === num) {
return resolve();
}
return retry();
}, `Expected ${num} ${model}s`);
})
.then(['I see $num $model model[s]?'], function(num, model) {
const len = currentPage()[pluralize(model)].filter(function(item) {
return item.isVisible;
}).length;
assert.equal(len, num, `Expected ${num} ${pluralize(model)}, saw ${len}`);
})
.then(['I see $num $model model[s]? on the $component component'], function(
num,
model,
component
) {
const obj = find(component);
const len = obj[pluralize(model)].filter(function(item) {
return item.isVisible;
}).length;
assert.equal(len, num, `Expected ${num} ${pluralize(model)}, saw ${len}`);
})
// TODO: I${ dont } see
.then([`I see $num $model model[s]? with the $property "$value"`], function(
// negate,
num,
model,
property,
value
) {
const len = currentPage()[pluralize(model)].filter(function(item) {
if (item.isVisible) {
let prop = item[property];
// cope with pageObjects that can have a multiple: true
if (!Array.isArray(prop)) {
prop = [prop];
}
return prop.includes(value);
}
return false;
}).length;
assert.equal(
len,
num,
`Expected ${num} ${pluralize(model)} with ${property} set to "${value}", saw ${len}`
);
});
}