Skip to content

Commit

Permalink
Merge pull request #583 from gemini-testing/users/shadowusr/INFRADUTY…
Browse files Browse the repository at this point in the history
…-27411

fix: do not lose meta.url if it is specified and apply base host to all urls in meta
fix: critical bug when suite height wouldn't be updated on resize
  • Loading branch information
shadowusr authored Aug 1, 2024
2 parents 0c0a39a + 346fdbc commit ad29f91
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 14 deletions.
11 changes: 11 additions & 0 deletions docs/en/html-reporter-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ For example:
}
```

When value of any key is set to `auto`, the base url will be set base host specified in the UI or kept intact if there base host isn't specified.

For example, if you have the following `metaInfoBaseUrls` value:
```javascript
{ custom_url: 'auto' }
```

And set `meta.custom_url` field to `https://example.com/some/path` in your tests, you'll see in meta:
- A link to `https://example.com/some/path` when base host is not set in the UI
- A link to `https://another-host.com/some/path` when base host in the UI is set to 'https://another-host.com'

### saveFormat

**DEPRECATED**
Expand Down
12 changes: 12 additions & 0 deletions docs/ru/html-reporter-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ throw err;
}
```

Когда значение любого ключа установлено на `auto`, базовый URL будет установлен на базовый хост, указанный в интерфейсе отчета, или останется неизменным, если базовый хост не указан.

Например, если у вас есть следующее значение `metaInfoBaseUrls`:

```javascript
{ custom_url: 'auto' }
```

И вы установите поле `meta.custom_url` в `https://example.com/some/path` в ваших тестах, вы увидите в мете:
- Ссылку на `https://example.com/some/path`, если базовый хост не установлен в интерфейсе пользователя
- Ссылку на `https://another-host.com/some/path`, если базовый хост в интерфейсе пользователя установлен в `https://another-host.com`

### saveFormat

**Параметр устарел**
Expand Down
4 changes: 2 additions & 2 deletions lib/adapters/test-result/transformers/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ReporterTestResult} from '../index';
import {DbTestResult} from '../../../sqlite-client';
import {getError, getRelativeUrl, getUrlWithBase} from '../../../common-utils';
import {getError, getUrlWithBase} from '../../../common-utils';
import _ from 'lodash';

interface Options {
Expand All @@ -18,7 +18,7 @@ export class DbTestResultTransformer {
const suiteUrl = getUrlWithBase(testResult.url, this._options.baseHost);

const metaInfoFull = _.merge(_.cloneDeep(testResult.meta), {
url: getRelativeUrl(suiteUrl) ?? '',
url: testResult.meta?.url ?? suiteUrl ?? '',
file: testResult.file,
sessionId: testResult.sessionId
});
Expand Down
19 changes: 15 additions & 4 deletions lib/static/components/section/body/meta-info/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {connect} from 'react-redux';
import {DefinitionList} from '@gravity-ui/components';
import PropTypes from 'prop-types';
import {map, mapValues, isObject, omitBy, isEmpty} from 'lodash';
import {isUrl, getUrlWithBase} from '../../../../../common-utils';
import {isUrl, getUrlWithBase, getRelativeUrl} from '../../../../../common-utils';

const serializeMetaValues = (metaInfo) => mapValues(metaInfo, (v) => isObject(v) ? JSON.stringify(v) : v);

Expand Down Expand Up @@ -32,7 +32,7 @@ const metaToElements = (metaInfo, metaInfoBaseUrls) => {

if (isUrl(value)) {
url = value;
} else if (metaInfoBaseUrls[key]) {
} else if (metaInfoBaseUrls[key] && metaInfoBaseUrls[key] !== 'auto') {
const baseUrl = metaInfoBaseUrls[key];
const link = isUrl(baseUrl) ? resolveUrl(baseUrl, value) : path.join(baseUrl, value);
url = link;
Expand Down Expand Up @@ -95,8 +95,19 @@ class MetaInfoContent extends Component {
formattedMetaInfo[key] = {content: formattedMetaInfo[key]};
});

if (result.suiteUrl) {
formattedMetaInfo.url = {content: result.metaInfo.url || result.suiteUrl, url: getUrlWithBase(result.suiteUrl, baseHost)};
for (const [key, value] of Object.entries(formattedMetaInfo)) {
if (isUrl(value.content) && (key === 'url' || metaInfoBaseUrls[key] === 'auto')) {
formattedMetaInfo[key] = {
content: getRelativeUrl(value.content),
url: getUrlWithBase(getRelativeUrl(value.content), baseHost)
};
}
}
if (!formattedMetaInfo.url && result.suiteUrl) {
formattedMetaInfo.url = {
content: getRelativeUrl(result.suiteUrl),
url: getUrlWithBase(getRelativeUrl(result.suiteUrl), baseHost)
};
}

return metaToElements(formattedMetaInfo, metaInfoBaseUrls);
Expand Down
2 changes: 1 addition & 1 deletion lib/static/components/suites.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {getVisibleRootSuiteIds} from '../modules/selectors/tree';
function VirtualizedRow(props) {
const resizeObserverRef = useRef(null);

useResizeObserver(resizeObserverRef, () => props.onResize);
useResizeObserver(resizeObserverRef, props.onResize);

return <div ref={props.onInit} style={props.style} className="virtualized__row">
<div ref={resizeObserverRef}>
Expand Down
3 changes: 3 additions & 0 deletions test/func/common.testplane.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports.getCommonConfig = (projectDir) => ({

browsers: {
chrome: {
assertViewOpts: {
ignoreDiffPixelCount: 4
},
windowSize: '1280x1024',
desiredCapabilities: {
browserName: 'chrome',
Expand Down
Binary file not shown.
Binary file modified test/func/tests/screens/1361a92/chrome/retry-selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/func/tests/screens/1361a92/chrome/success.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed test/func/tests/screens/42ea26d/chrome/pink.png
Binary file not shown.
Binary file modified test/func/tests/screens/42ea26d/chrome/retry-selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/func/tests/screens/d90f7de/chrome/retry-selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified test/func/tests/screens/ff4deba/chrome/retry-selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 32 additions & 7 deletions test/unit/lib/static/components/section/body/meta-info/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,37 @@ describe('<MetaInfoContent />', () => {
expectedFileUrl: 'http://127.0.0.1/path/test/file'
},
{
type: 'url with query params and meta value with query params',
type: 'url when baseHost is not set and metaBaseUrls is not set',
metaInfo: {
file: 'test/file?a=b'
file: 'http://localhost/test/file?a=b'
},
metaInfoBaseUrls: {},
baseHost: 'http://example.com/',
expectedFileLabel: 'http://localhost/test/file?a=b',
expectedFileUrl: 'http://localhost/test/file?a=b'
},
{
type: 'url when baseHost is not set and metaBaseUrls set to auto',
metaInfo: {
file: 'http://localhost/test/file?a=b'
},
metaInfoBaseUrls: {
file: 'auto'
},
expectedFileLabel: '/test/file?a=b',
expectedFileUrl: 'http://localhost/test/file?a=b'
},
{
type: 'url when baseHost is set and metaBaseUrls set to auto',
metaInfo: {
file: 'http://localhost/test/file?a=b'
},
metaInfoBaseUrls: {
file: 'http://127.0.0.1/?c=d&e=f'
file: 'auto'
},
expectedFileUrl: 'http://127.0.0.1/test/file?a=b&c=d&e=f'
baseHost: 'http://example.com/',
expectedFileLabel: '/test/file?a=b',
expectedFileUrl: 'http://example.com/test/file?a=b'
}
].forEach((stub) => {
it(`should render link in meta info based upon metaInfoBaseUrls ${stub.type}`, () => {
Expand All @@ -223,11 +246,13 @@ describe('<MetaInfoContent />', () => {
}
};
const config = {metaInfoBaseUrls: stub.metaInfoBaseUrls};
const component = mkMetaInfoContentComponent({resultId: 'some-result'}, {tree, config});
const view = {baseHost: stub.baseHost};
const component = mkMetaInfoContentComponent({resultId: 'some-result'}, {tree, config, view});

const label = stub.expectedFileLabel ?? stub.metaInfo.file;
expect(component.getByText('file')).to.exist;
expect(component.getByText(stub.metaInfo.file)).to.exist;
expect(component.getByText(stub.metaInfo.file).href).to.equal(stub.expectedFileUrl);
expect(component.getByText(label)).to.exist;
expect(component.getByText(label).href).to.equal(stub.expectedFileUrl);
});
});
});

0 comments on commit ad29f91

Please sign in to comment.