Skip to content

Commit

Permalink
fix(gui): wrong base url for tests in gui mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sipayRT committed Sep 13, 2024
1 parent 7a7b9b1 commit 82a9e7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
24 changes: 13 additions & 11 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,24 @@ export const determineFinalStatus = (statuses: TestStatus[]): TestStatus | null
};

export const getUrlWithBase = (url: string | undefined, base: string | undefined): string => {
if (isEmpty(base)) {
return url ?? '';
}

try {
const userUrl = new URL(url ?? '', base);

// Manually overriding properties, because if url is absolute, the above won't work
if (!isEmpty(base)) {
const baseUrl = new URL(base as string);
// Manually overriding properties, because if userUrl is absolute, the above won't work
const baseUrl = new URL(base as string);

userUrl.host = baseUrl.host;
userUrl.protocol = baseUrl.protocol;
userUrl.port = baseUrl.port;
userUrl.username = baseUrl.username;
userUrl.password = baseUrl.password;
userUrl.host = baseUrl.host;
userUrl.protocol = baseUrl.protocol;
userUrl.port = baseUrl.port;
userUrl.username = baseUrl.username;
userUrl.password = baseUrl.password;

for (const [key, value] of baseUrl.searchParams) {
userUrl.searchParams.append(key, value);
}
for (const [key, value] of baseUrl.searchParams) {
userUrl.searchParams.append(key, value);
}

return userUrl.href;
Expand Down
4 changes: 2 additions & 2 deletions lib/static/components/icons/view-in-browser/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classNames from 'classnames';
import {Eye, EyeSlash} from '@gravity-ui/icons';

import * as actions from '../../../modules/actions';
import {getRelativeUrl, getUrlWithBase} from '../../../../common-utils';
import {getUrlWithBase} from '../../../../common-utils';

import './index.styl';

Expand Down Expand Up @@ -41,7 +41,7 @@ class ViewInBrowser extends Component {
return (
<a
className={className}
href={getUrlWithBase(getRelativeUrl(suiteUrl), baseHost)}
href={getUrlWithBase(suiteUrl, baseHost)}
onClick={this.onViewInBrowser}
title="view in browser"
target="_blank"
Expand Down
4 changes: 2 additions & 2 deletions lib/static/new-ui/components/MetaInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function MetaInfoInternal(props: MetaInfoInternalProps): ReactNode {

const metaInfoItemsWithResolvedUrls = metaInfoItems.map((item) => {
if (item.label === 'url' || metaInfoBaseUrls[item.label] === 'auto') {
const url = getUrlWithBase(getRelativeUrl(item.content), baseHost);
const url = getUrlWithBase(item.content, baseHost);
return {
label: item.label,
content: getRelativeUrl(item.content),
Expand Down Expand Up @@ -105,7 +105,7 @@ function MetaInfoInternal(props: MetaInfoInternalProps): ReactNode {
metaInfoItemsWithResolvedUrls.push({
label: 'url',
content: getRelativeUrl(result.suiteUrl),
url: getUrlWithBase(getRelativeUrl(result.suiteUrl), baseHost)
url: getUrlWithBase(result.suiteUrl, baseHost)
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('common-utils', () => {
});

it('should work without baseUrl', () => {
const result = getUrlWithBase('some-url', '');
const result = getUrlWithBase('http://some-url.com/path', '');

assert.equal(result, 'some-url');
assert.equal(result, 'http://some-url.com/path');
});
});

Expand Down

0 comments on commit 82a9e7a

Please sign in to comment.