Skip to content

Commit

Permalink
[Lens] Unskip FTR test (#181805)
Browse files Browse the repository at this point in the history
## Summary

This PR should unskip tests that were broken due to a Chome <->
WebDriver bug.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
dej611 committed May 3, 2024
1 parent 50f9918 commit 70813ba
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'timepicker:timeDefaults':
'{ "from": "2015-09-18T19:37:13.000Z", "to": "2015-09-22T23:30:30.000Z"}',
});
await PageObjects.visualize.gotoVisualizationLandingPage({ forceRefresh: true });
});

after(async () => {
Expand Down
96 changes: 74 additions & 22 deletions x-pack/test/functional/apps/lens/group6/workspace_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const log = getService('log');

// Failing: See https://github.com/elastic/kibana/issues/176882
describe.skip('lens workspace size', () => {
function within(actualSize: number, expectedSize: number) {
const tolerance = 50; // 50 px tolerance
return actualSize > expectedSize - tolerance && actualSize < expectedSize + tolerance;
}

describe('lens workspace size', () => {
let originalWindowSize: {
height: number;
width: number;
Expand All @@ -26,13 +30,33 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

const DEFAULT_WINDOW_SIZE = [1400, 900];
const VERTICAL_16_9 = 16 / 9;
const outerWorkspaceDimensions = { width: 700, height: 400 };
let UNCONSTRAINED = outerWorkspaceDimensions.width / outerWorkspaceDimensions.height;

before(async () => {
originalWindowSize = await browser.getWindowSize();
log.debug(
`Changing browser window size to ${DEFAULT_WINDOW_SIZE[0]}x${DEFAULT_WINDOW_SIZE[1]}`
);
await browser.setWindowSize(DEFAULT_WINDOW_SIZE[0], DEFAULT_WINDOW_SIZE[1]);
const { width, height } = await browser.getWindowSize();
log.debug(`Current browser window size set to ${width}x${height}`);

await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
// Detect here if the Chrome bug is present, and adjust the aspect ratio accordingly if not
if (!within(width, DEFAULT_WINDOW_SIZE[0]) || !within(height, DEFAULT_WINDOW_SIZE[1])) {
const { width: containerWidth, height: containerHeight } =
await PageObjects.lens.getWorkspaceVisContainerDimensions();

const newRatio = pxToN(containerWidth) / pxToN(containerHeight);
log.debug(
`Detected Chrome bug () adjusting aspect ratio from ${UNCONSTRAINED} to ${newRatio}`
);
UNCONSTRAINED = newRatio;
}

await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
Expand All @@ -41,38 +65,63 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});

beforeEach(async () => {
await browser.setWindowSize(DEFAULT_WINDOW_SIZE[0], DEFAULT_WINDOW_SIZE[1]);
});

after(async () => {
await browser.setWindowSize(originalWindowSize.width, originalWindowSize.height);
});

const pxToN = (pixels: string) => Number(pixels.substring(0, pixels.length - 2));

const assertWorkspaceDimensions = async (expectedWidth: string, expectedHeight: string) => {
/**
* Due to https://github.com/elastic/kibana/issues/176882 Chrome doesn't respect
* the view dimensions passed via the selenium driver. This means that we cannot
* rely on precise numbers here in the CI, so the best we can do is to check 2 things:
* 1. The size passed are the upper bound for the given visualization
* 2. If the view size is correctly set use it to test, otherwise use a lower value based on the
* current workspace size
* @param expectedMaxWidth
* @param expectedMaxHeight
*/
const assertWorkspaceDimensions = async (
expectedMaxWidth: string,
expectedMaxHeight: string
) => {
const tolerance = 1;

await retry.tryForTime(2000, async () => {
const { width, height } = await PageObjects.lens.getWorkspaceVisContainerDimensions();
log.debug(
`Checking workspace dimensions: ${width} x ${height} against ${expectedMaxWidth}x${expectedMaxHeight}`
);

// Make sure size didn't go past the max passed
expect(pxToN(width)).to.be.below(pxToN(expectedMaxWidth) + 1);
expect(pxToN(height)).to.be.below(pxToN(expectedMaxHeight) + 1);

// now workout the correct size to test
const widthToTest = pxToN(width) > pxToN(expectedMaxWidth) ? expectedMaxWidth : width;
const heightToTest = pxToN(height) > pxToN(expectedMaxHeight) ? expectedMaxHeight : height;

expect(pxToN(width)).to.within(
pxToN(expectedWidth) - tolerance,
pxToN(expectedWidth) + tolerance
pxToN(widthToTest) - tolerance,
pxToN(widthToTest) + tolerance
);
expect(pxToN(height)).to.within(
pxToN(expectedHeight) - tolerance,
pxToN(expectedHeight) + tolerance
pxToN(heightToTest) - tolerance,
pxToN(heightToTest) + tolerance
);
});
};

const assertWorkspaceAspectRatio = async (expectedRatio: number) => {
const tolerance = 0.05;
const tolerance = 0.07;

await retry.try(async () => {
const { width, height } = await PageObjects.lens.getWorkspaceVisContainerDimensions();
log.debug(
`Checking workspace dimensions: ${pxToN(width)} x ${pxToN(height)} with ratio ${
pxToN(width) / pxToN(height)
} vs ${expectedRatio}`
);

expect(pxToN(width) / pxToN(height)).to.within(
expectedRatio - tolerance,
Expand All @@ -93,10 +142,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(actualStyles).to.eql(expectedStyles);
};

const VERTICAL_16_9 = 16 / 9;
const outerWorkspaceDimensions = { width: 690, height: 400 };
const UNCONSTRAINED = outerWorkspaceDimensions.width / outerWorkspaceDimensions.height;

it('workspace size recovers from special vis types', async () => {
/**
* This list is specifically designed to test dimension transitions.
Expand Down Expand Up @@ -165,7 +210,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.lens.switchToVisualization(vis.id, vis.searchText);
});

log.debug(`Testing ${vis.id}... expecting ${vis.expectedWidth}x${vis.expectedHeight}`);
log.debug(
`Testing ${vis.id}... expecting ${
vis.aspectRatio
? `ratio of ${vis.aspectRatio}`
: `${vis.expectedWidth}x${vis.expectedHeight}`
}`
);

if (vis.aspectRatio) {
await assertWorkspaceAspectRatio(vis.aspectRatio);
Expand All @@ -188,12 +239,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
field: 'ip',
});

await assertWorkspaceDimensions('600px', '400px');
await assertWorkspaceDimensions('600px', '430px');

await PageObjects.lens.openDimensionEditor('lnsMetric_breakdownByDimensionPanel');
await testSubjects.setValue('lnsMetric_max_cols', '2');
await PageObjects.lens.closeDimensionEditor();

await assertWorkspaceDimensions('400px', '400px');
await assertWorkspaceDimensions('430px', '430px');
});

it('gauge size (absolute pixels) - horizontal', async () => {
Expand All @@ -214,7 +266,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// and the chart is forced to shrink.
//
// this is a good thing because it makes this a test case for that scenario
await assertWorkspaceDimensions('400px', '400px');
await assertWorkspaceDimensions('430px', '430px');
});

it('gauge size (absolute pixels) - arc', async () => {
Expand All @@ -228,14 +280,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await retry.try(async () => {
await PageObjects.lens.switchToVisualization(GaugeShapes.ARC, 'arc');
});
await assertWorkspaceDimensions('600px', '400px');
await assertWorkspaceDimensions('600px', '430px');
});

it('gauge size (absolute pixels) - circle', async () => {
await retry.try(async () => {
await PageObjects.lens.switchToVisualization(GaugeShapes.CIRCLE, 'circular');
});
await assertWorkspaceDimensions('600px', '400px');
await assertWorkspaceDimensions('600px', '430px');
});

it('XY chart size', async () => {
Expand Down

0 comments on commit 70813ba

Please sign in to comment.