Skip to content

Commit

Permalink
fix: apply baseHost to urls that have metaBaseUrls set to auto
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Aug 1, 2024
1 parent 93d0111 commit 28ddc84
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 13 deletions.
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
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 28ddc84

Please sign in to comment.