Skip to content

Commit

Permalink
remove the old special transform handling in testMode and fix
Browse files Browse the repository at this point in the history
tests to compare to the encoded/decoded values
  • Loading branch information
peuter committed Sep 28, 2022
1 parent e31b839 commit 0473da0
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 61 deletions.
13 changes: 0 additions & 13 deletions source/class/cv/Transform.js
Expand Up @@ -138,12 +138,6 @@ qx.Class.define('cv.Transform', {
*/
encodeBusAndRaw: function (address, value) {
const {transform} = address;
// some transforms must be executed even in testMode (the ones that convert into objects)
if (cv.Config.testMode === true && (transform in cv.Transform.registry && (
!Object.prototype.hasOwnProperty.call(cv.Transform.registry[transform], 'applyInTestMode') ||
cv.Transform.registry[transform].applyInTestMode === false))) {
return {bus: value, raw: value};
}
let {selector, variantInfo} = address;
let basetrans = transform.split('.')[0];
const encoding = transform in cv.Transform.registry
Expand Down Expand Up @@ -195,13 +189,6 @@ qx.Class.define('cv.Transform', {
*/
decode: function (address, value) {
const {transform, ignoreError} = address;
// some transforms must be executed even in testMode (the ones that convert into objects)
if (cv.Config.testMode === true && (transform in cv.Transform.registry && (
!Object.prototype.hasOwnProperty.call(cv.Transform.registry[transform], 'applyInTestMode') ||
cv.Transform.registry[transform].applyInTestMode === false))) {
return value;
}

let {selector, variantInfo} = address;
const basetrans = transform.split('.')[0];

Expand Down
17 changes: 11 additions & 6 deletions source/class/cv/io/Mockup.js
Expand Up @@ -415,11 +415,11 @@ qx.Class.define('cv.io.Mockup', {
}
const ts = new Date().getTime();
// store in window, to make it accessible for protractor
window.writeHistory.push({
const lastWrite = {
address: address,
value: value,
ts: ts
});
};

if (this.__simulations && Object.prototype.hasOwnProperty.call(this.__simulations, address)) {
this._processSimulation(address, value);
Expand All @@ -430,16 +430,21 @@ qx.Class.define('cv.io.Mockup', {
d: {}
};
if (/\d{1,2}\/\d{1,2}\/\d{1,2}/.test(address)) {
if (value.length === 2) {
value = "" + (parseInt(value, 16) & 63);
} else {
value = value.substring(2);
if (/^[\da-fA-F]+$/.test(value)) {
if (value.length <= 2) {
value = '' + (parseInt(value, 16) & 63);
} else {
value = value.substring(2);
}
lastWrite.transformedValue = value;
}
}
answer.d[address] = value;
this.debug('sending value: ' + value + ' to address: ' + address);
this.receive(answer);
}
// store in window, to make it accessible for protractor
window.writeHistory.push(lastWrite);
},

restart: function() {},
Expand Down
2 changes: 0 additions & 2 deletions source/class/cv/transforms/Knx.js
Expand Up @@ -485,7 +485,6 @@ qx.Class.define('cv.transforms.Knx', {

'10.001': {
name: 'DPT_TimeOfDay',
applyInTestMode: true,
lname: {
'de': 'Zeit',
'en': 'time'
Expand Down Expand Up @@ -518,7 +517,6 @@ qx.Class.define('cv.transforms.Knx', {

'11.001': {
name: 'DPT_Date',
applyInTestMode: true,
lname: {
'de': 'Datum',
'en': 'date'
Expand Down
14 changes: 0 additions & 14 deletions source/class/cv/transforms/Mqtt.js
Expand Up @@ -83,7 +83,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'timestring': {
name: 'MQTT_timestring',
applyInTestMode: true,
lname: {
'de': 'Uhrzeit-String',
'en': 'time string'
Expand Down Expand Up @@ -112,7 +111,6 @@ qx.Class.define('cv.transforms.Mqtt', {
'de': 'ISO 8601 Zeit-String',
'en': 'ISO 8601 time string'
},
applyInTestMode: true,
example: '"2022-01-01T16:30:00.000Z"',
unit: '-',
encode: function (phy) {
Expand All @@ -125,7 +123,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_xy': {
name: 'MQTT_color_xy',
applyInTestMode: true,
lname: {
'de': 'xy-Farbe',
'en': 'xy color'
Expand All @@ -150,7 +147,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_xyY': {
name: 'MQTT_color_xyY',
applyInTestMode: true,
lname: {
'de': 'xyY-Farbe',
'en': 'xyY color'
Expand Down Expand Up @@ -178,7 +174,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_hsv': {
name: 'MQTT_color_hsv',
applyInTestMode: true,
lname: {
'de': 'HSV-Farbe als Zeichenkette',
'en': 'HSV color as string'
Expand All @@ -203,7 +198,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_h_s_v': {
name: 'MQTT_color_h_s_v',
applyInTestMode: true,
lname: {
'de': 'HSV-Farbe',
'en': 'HSV color'
Expand Down Expand Up @@ -232,7 +226,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_hsl': {
name: 'MQTT_color_hsl',
applyInTestMode: true,
lname: {
'de': 'HSL-Farbe als Zeichenkette',
'en': 'HSL color as string'
Expand All @@ -257,7 +250,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_h_s_l': {
name: 'MQTT_color_h_s_l',
applyInTestMode: true,
lname: {
'de': 'HSL-Farbe',
'en': 'HSL color'
Expand Down Expand Up @@ -286,7 +278,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_rgb': {
name: 'MQTT_color_rgb',
applyInTestMode: true,
lname: {
'de': 'RGB-Farbe als Zeichenkette',
'en': 'RGB color as string'
Expand All @@ -311,7 +302,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_r_g_b': {
name: 'MQTT_color_r_g_b',
applyInTestMode: true,
lname: {
'de': 'RGB-Farbe',
'en': 'RGB color'
Expand Down Expand Up @@ -340,7 +330,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_rgbw': {
name: 'MQTT_color_rgbw',
applyInTestMode: true,
lname: {
'de': 'RGBW-Farbe als Zeichenkette',
'en': 'RGBW color as string'
Expand All @@ -366,7 +355,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_r_g_b_w': {
name: 'MQTT_color_r_g_b_w',
applyInTestMode: true,
lname: {
'de': 'RGBW-Farbe',
'en': 'RGBW color'
Expand Down Expand Up @@ -397,7 +385,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_rgb_hex': {
name: 'MQTT_color_rgb_hex',
applyInTestMode: true,
lname: {
'de': 'RGB-Farbe',
'en': 'RGB color'
Expand Down Expand Up @@ -427,7 +414,6 @@ qx.Class.define('cv.transforms.Mqtt', {

'color_rgbw_hex': {
name: 'MQTT_color_rgbw_hex',
applyInTestMode: true,
lname: {
'de': 'RGBW-Farbe',
'en': 'RGBW color'
Expand Down
2 changes: 0 additions & 2 deletions source/class/cv/transforms/OpenHab.js
Expand Up @@ -156,7 +156,6 @@ qx.Class.define('cv.transforms.OpenHab', {
},
'datetime': {
name: 'OH_DateTime',
applyInTestMode: true,
encode: function (phy) {
if (phy instanceof Date) {
return phy.toLocaleDateString();
Expand All @@ -172,7 +171,6 @@ qx.Class.define('cv.transforms.OpenHab', {
},
'time': {
name: 'OH_Time',
applyInTestMode: true,
encode: function (phy) {
if (phy instanceof Date) {
return phy.toLocaleTimeString();
Expand Down
18 changes: 16 additions & 2 deletions source/test/protractor/pages/BasePage.js
Expand Up @@ -193,7 +193,7 @@ class BasePage {
}

/**
* Get the last message that has been send to the backend (aka write message)
* Get the last message that has been sent to the backend (aka write message)
* @return {Map}
*/
// eslint-disable-next-line class-methods-use-this
Expand All @@ -204,7 +204,7 @@ class BasePage {
}

/**
* Get the complete list of write messages, which have been send to the backend
* Get the complete list of write messages, which have been sent to the backend
* @return {Promise<Array>}
*/
// eslint-disable-next-line class-methods-use-this
Expand Down Expand Up @@ -240,6 +240,20 @@ class BasePage {
}, locale);
}

decode(address, value) {
return browser.executeAsyncScript(function (address, value, callback) {
const transformedValue = cv.Transform.decode(address, value);
callback(transformedValue);
}, address, value);
}

encode(address, value) {
return browser.executeAsyncScript(function (address, value, callback) {
const transformedValue = cv.Transform.encodeBusAndRaw(address, value);
callback(transformedValue.raw);
}, address, value);
}

/**
* Get widget data
* @param path
Expand Down
37 changes: 22 additions & 15 deletions source/test/protractor/specs/demo-spec.js
Expand Up @@ -63,14 +63,14 @@ describe('cometvisu demo config test:', function () {

expect(widget.element(by.css('.value')).getText()).toEqual('Aus');
cvDemo.getLastWrite().then(function(lastWrite) {
expect(lastWrite.value).toEqual('0');
expect(lastWrite.value).toEqual('80');
});

browser.actions().click(widget).perform();

expect(widget.element(by.css('.value')).getText()).toEqual('An');
cvDemo.getLastWrite().then(function(lastWrite) {
expect(lastWrite.value).toEqual('1');
expect(lastWrite.value).toEqual('81');
});

// send update via backend
Expand All @@ -93,13 +93,13 @@ describe('cometvisu demo config test:', function () {

expect(widget.element(by.css('.value')).getText()).toEqual('Aus');
cvDemo.getLastWrite().then(function (lastWrite) {
expect(lastWrite.value).toEqual(sendValue);
expect(lastWrite.value).toEqual('8' + sendValue);
});
widget.click();

expect(widget.element(by.css('.value')).getText()).toEqual('Aus');
cvDemo.getLastWrite().then(function (lastWrite) {
expect(lastWrite.value).toEqual(sendValue);
expect(lastWrite.value).toEqual('8' + sendValue);
});
});
});
Expand All @@ -115,14 +115,14 @@ describe('cometvisu demo config test:', function () {

expect(widget.element(by.css('.value')).getText()).toEqual('Aus');
cvDemo.getLastWrite().then(function (lastWrite) {
expect(lastWrite.value).toEqual(data.downValue);
expect(lastWrite.value).toEqual('8'+data.downValue);
});

browser.actions().mouseUp(widget).perform();

expect(widget.element(by.css('.value')).getText()).toEqual('An');
cvDemo.getLastWrite().then(function (lastWrite) {
expect(lastWrite.value).toEqual(data.upValue);
expect(lastWrite.value).toEqual('8'+data.upValue);
});
});
});
Expand All @@ -134,43 +134,50 @@ describe('cometvisu demo config test:', function () {
// get widget data from parent
widget.element(by.xpath('parent::div/parent::div')).getAttribute('id').then(function(id) {
cvDemo.getWidgetData(id).then(function (data) {
var address;
let address;
let transform;
for (var addr in data.address) {
address = addr;
transform = data.address[addr].transform;
break;
}

// find the slider knob
var knob = widget.element(by.css('.ui-slider-handle'));
browser.actions().mouseMove(knob, {x: 10, y:10}).mouseDown().perform();

cvDemo.getLastWrite().then(function (lastWrite1) {
browser.actions().mouseMove(knob, {x: 30, y:10}).mouseUp().perform();
browser.sleep(500);
cvDemo.getLastWrite().then(function (lastWrite2) {
expect(lastWrite2.value).toBeGreaterThan(lastWrite1.value);
cvDemo.getLastWrite().then(async function (lastWrite2) {
const firstWrittenValue = await cvDemo.decode({transform: transform}, lastWrite1.transformedValue);
const secondWrittenValue = await cvDemo.decode({transform: transform}, lastWrite2.transformedValue);
expect(secondWrittenValue).toBeGreaterThan(firstWrittenValue);
});
});
var borderWidth = 1; // depending from design, but as the demo is in pure design, we use a hardcoded value here
var borderWidth = 1; // depending on design, but as the demo is in pure design, we use a hardcoded value here

widget.getLocation().then(function(rangePosition) {
widget.getSize().then(function(rangeSize) {
// move the slider by updates from backend
knob.getLocation().then(function (pos) {
knob.getSize().then(function(knobSize) {
knob.getSize().then(async function(knobSize) {
// slider min
cvDemo.sendUpdate(address, data.min || 0);
const minValue = await cvDemo.encode({transform: transform}, data.min || 0);
const maxValue = await cvDemo.encode({transform: transform}, data.max || 100);
await cvDemo.sendUpdate(address, minValue);
// give the slider some time to reach its position
browser.sleep(1500);
browser.sleep(500);
knob.getLocation().then(function (newPos) {
// check with some tolerance
expect(Math.abs(newPos.x-(rangePosition.x + borderWidth - Math.round(knobSize.width/2)))).toBeLessThan(25);
expect(newPos.y).toEqual(pos.y);
});

// slider max
cvDemo.sendUpdate(address, data.max || 100);
await cvDemo.sendUpdate(address, maxValue);
// give the slider some time to reach its position
browser.sleep(1500);
browser.sleep(500);
knob.getLocation().then(function (newPos) {
// check with some tolerance
expect(Math.abs(newPos.x-(rangePosition.x + rangeSize.width - knobSize.width - borderWidth))).toBeLessThan(25);
Expand Down

0 comments on commit 0473da0

Please sign in to comment.