Skip to content

Commit

Permalink
feat!(screenshots)(CHART)(MetricsComparison):...
Browse files Browse the repository at this point in the history
+ casesConfirmed7DaysAvgFourMonthsTooltip
  • Loading branch information
jalezi committed Jun 10, 2021
1 parent 0920855 commit 4466763
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 30 deletions.
28 changes: 23 additions & 5 deletions navigateToCustomChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ module.exports = async ({

let result;

// if arguments values are known
const funcArgs = options?.funcArgs || [];
if (button && !options?.type) {
if (button && !options?.value) {
result = await func(button, ...funcArgs);
}
if (button && options?.type) {

// if arguments values are dynamic, at the moment only for date range
if (button && options?.value) {
type = { dateFrom, dateTo };
const value = type[options.type];
const value = type[options.value];
result = await func(button, value, page);
}

Expand Down Expand Up @@ -97,7 +100,22 @@ module.exports = async ({
return button;
};

!options?.loop && (returnedElement = await performOnElement());
options?.loop && (returnedElement = await preformOnArrayOfElements());
const preformOnLineChart = async () => {
const index = which instanceof Function ? which(hoverIndex) : which;
const button = await func(index, options, page);
console.log(`Button [${button}] clicked!`);
};

const FuncDict = {
default: performOnElement,
loop: preformOnArrayOfElements,
line: preformOnLineChart,
};

const performFunc = options.type
? FuncDict[options.type]
: FuncDict.default;

returnedElement = await performFunc();
}
};
84 changes: 59 additions & 25 deletions screenshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ const elementHandleSetValue = async (elementHandle, value, page) => {
await page.keyboard.press('Backspace');
await elementHandle.click();
await elementHandle.type(value, { delay: 100 });
console.log(`Element type value: ${value}`);
await page.keyboard.press('Tab');
console.log('Value typed!');
return elementHandle;
};

const castToNumber = index => +index;

// {type: 'loop'}
const findByNameShowTooltip = async (series, name, options) => {
if (!series) {
throw new Error(`Argument [series] is: ${series}!`);
Expand Down Expand Up @@ -116,25 +117,8 @@ const loopAndShowTooltip = async (series, index, options, page) => {

const func = options.func ?? elementHandleClick;

// in some cases not working
// await func(button);
/**
* in some cases not working, mostly attemptimp to click last item.
*
*
* const query = {
* type: 'chart',
* screen: 'Cases',
* custom: 'cases_DateRange_Active_Hospitalized_Deceased_Tooltip',
* hoverIndex: '118',
* hideLegend: 'false',
* dateFrom: '01. 01. 2021',
* dateTo: '30. 04. 2021',
* };
*/

func.name = 'elementHandleHover' && (await button.hover());
func.name = 'elementHandleClick' && (await button.click());
func.name === 'elementHandleHover' && (await button.hover());
func.name === 'elementHandleClick' && (await button.click());
return [button, buttons];
};

Expand All @@ -143,10 +127,10 @@ const mapMunicipalitiesTooltip = [
value => value,
findByNameShowTooltip,
{
loop: true,
getSelector: name => `.highcharts-name-${name}`,
exit: true,
func: elementHandleClick,
type: 'loop',
},
];

Expand All @@ -157,6 +141,40 @@ const filterSelectValue = value => [
{ funcArgs: [value] },
];

const lineChartTooltip = async (index, options, page) => {
const convertedIndex = isNaN(index) ? null : index;
console.log(
`Try to show line chart tooltip with index: ${convertedIndex} on series with index: ${options?.seriesIndex}`
);
const data = await page.evaluate(
(index, options) => {
const { charts } = Highcharts;
const { series } = charts[options.chartsIndex ?? 0];
const { points } = series[options.seriesIndex ?? 0];
const i = index ?? points.length - 1;
const point = points[i];
point.onMouseOver();

const result = {
button: point.key,
c: charts.length,
s: series.length,
p: points.length,
i,
};

return Promise.resolve(result);
},
convertedIndex,
options
);
console.log(`Charts length: ${data.c}`);
console.log(`Series length: ${data.s}`);
console.log(`Points length: ${data.p}`);
console.log(`Tooltip for point with index: ${data.i}`);
return data.button;
};

CHART = {
MetricsComparison: {
name: 'MetricsComparison',
Expand All @@ -166,6 +184,21 @@ CHART = {
['metrics', 1, elementHandleClick],
['range', 1, elementHandleClick],
],
casesConfirmed7DaysAvgFourMonthsTooltip: [
['metrics', 11, elementHandleClick],
['metrics', 1, elementHandleClick],
['range', 1, elementHandleClick],
[
null,
castToNumber,
lineChartTooltip,
{
type: 'line',
chartsIndex: 0,
seriesIndex: 0,
},
],
],
},
},
DailyComparison: {
Expand Down Expand Up @@ -427,11 +460,11 @@ CHART = {
castToNumber,
loopAndShowTooltip,
{
loop: true,
length: () => 60, // todo calc because of february && july, august
selector: 'rect',
exit: true,
func: elementHandleClick,
type: 'loop',
},
],
],
Expand Down Expand Up @@ -483,8 +516,8 @@ CHART = {
['highchartsSeriesRect', castToNumber, elementHandleClick],
],
cases_DateRange_Active_Hospitalized_Deceased_Tooltip: [
['rangeDateInput', 0, elementHandleSetValue, { type: 'dateFrom' }],
['rangeDateInput', 1, elementHandleSetValue, { type: 'dateTo' }],
['rangeDateInput', 0, elementHandleSetValue, { value: 'dateFrom' }],
['rangeDateInput', 1, elementHandleSetValue, { value: 'dateTo' }],
['highchartsLegendItemRect', 2, elementHandleClick],
['highchartsLegendItemRect', 3, elementHandleClick],
['highchartsLegendItemRect', 4, elementHandleClick],
Expand All @@ -495,11 +528,11 @@ CHART = {
castToNumber,
loopAndShowTooltip,
{
loop: true,
length: getDaysDifference,
selector: 'rect',
exit: true,
func: elementHandleHover,
type: 'loop',
sort: true,
},
],
Expand Down Expand Up @@ -613,6 +646,7 @@ OPTIONS = {
rangeDateInput: await element.$$(
'.highcharts-range-input > text > tspan'
),
root: await element.$$('.highcharts-root'),
}),
},
MULTICARD: {
Expand Down

0 comments on commit 4466763

Please sign in to comment.