mirror of
https://github.com/SomboChea/ui
synced 2024-11-28 00:44:30 +07:00
fix(#300): correctly reference registry url from options
This commit is contained in:
parent
0d9232a92c
commit
ee74474811
@ -1 +1 @@
|
|||||||
require.requireActual('babel/polyfill');
|
jest.requireActual('babel/polyfill');
|
||||||
|
@ -7,14 +7,13 @@ import { configure } from 'enzyme';
|
|||||||
import Adapter from 'enzyme-adapter-react-16';
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
import { GlobalWithFetchMock } from 'jest-fetch-mock';
|
||||||
|
|
||||||
// @ts-ignore : Only a void function can be called with the 'new' keyword
|
|
||||||
configure({ adapter: new Adapter() });
|
configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
// @ts-ignore : Property '__APP_VERSION__' does not exist on type 'Global'.
|
// @ts-ignore : Property '__APP_VERSION__' does not exist on type 'Global'.
|
||||||
global.__APP_VERSION__ = '1.0.0';
|
global.__APP_VERSION__ = '1.0.0';
|
||||||
// @ts-ignore : Property '__VERDACCIO_BASENAME_UI_OPTIONS' does not exist on type 'Global'.
|
// @ts-ignore : Property '__VERDACCIO_BASENAME_UI_OPTIONS' does not exist on type 'Global'.
|
||||||
global.__VERDACCIO_BASENAME_UI_OPTIONS = {};
|
global.__VERDACCIO_BASENAME_UI_OPTIONS = { base: 'http://localhost' };
|
||||||
|
// @ts-ignore : Property 'VERDACCIO_API_URL' does not exist on type 'Global'.
|
||||||
global.VERDACCIO_API_URL = 'https://verdaccio.tld';
|
global.VERDACCIO_API_URL = 'https://verdaccio.tld';
|
||||||
|
|
||||||
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
|
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
|
||||||
|
@ -17,14 +17,18 @@ describe('utils', () => {
|
|||||||
expect(isEmail('')).toBeFalsy();
|
expect(isEmail('')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
|
test('getRegistryURL() - should not change when location change', () => {
|
||||||
|
expect(getRegistryURL()).toBe('http://localhost');
|
||||||
history.pushState({}, 'page title', '/-/web/detail');
|
history.pushState({}, 'page title', '/-/web/detail');
|
||||||
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
|
expect(getRegistryURL()).toBe('http://localhost');
|
||||||
history.pushState({}, 'page title', '/');
|
history.pushState({}, 'page title', '/');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
|
test('getRegistryURL() - should change when UI options change', () => {
|
||||||
expect(getRegistryURL()).toBe('http://localhost');
|
expect(getRegistryURL()).toBe('http://localhost');
|
||||||
|
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost/test';
|
||||||
|
expect(getRegistryURL()).toBe('http://localhost/test');
|
||||||
|
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ export function isEmail(email: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getRegistryURL(): string {
|
export function getRegistryURL(): string {
|
||||||
// Don't add slash if it's not a sub directory
|
return window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
|
||||||
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractFileName(url: string): string {
|
export function extractFileName(url: string): string {
|
||||||
|
Loading…
Reference in New Issue
Block a user