Files
weave-scope/client/app/scripts/utils/__tests__/web-api-utils-test.js
Filip Barl b6dfe25499 Time travel control (#2524)
* Hacky working prototype.

* Operate with time.Duration offset instead of fixed timestamp.

* Polished the backend code.

* Made a nicer UI component.

* Small refactorings of the websockets code.

* Fixed the backend tests.

* Better websocketing and smoother transitions

* Small styling refactoring.

* Detecting empty topologies.

* Improved error messaging.

* Addressed some of David's comments.

* Moved nodesDeltaBuffer to a global state to fix the paused status rendering bug.

* Small styling changes

* Changed the websocket global state variables a bit.

* Polishing & refactoring.

* More polishing.

* Final refactoring.

* Addressed a couple of bugs.

* Hidden the timeline control behind Cloud context and a feature flag.

* Addressed most of @davkal's comments.

* Added mixpanel tracking.
2017-06-12 11:22:17 +02:00

88 lines
3.1 KiB
JavaScript

import {OrderedMap as makeOrderedMap} from 'immutable';
import { buildUrlQuery, basePath, getApiPath, getWebsocketUrl } from '../web-api-utils';
describe('WebApiUtils', () => {
describe('basePath', () => {
it('should handle /scope/terminal.html', () => {
expect(basePath('/scope/terminal.html')).toBe('/scope');
});
it('should handle /scope/', () => {
expect(basePath('/scope/')).toBe('/scope');
});
it('should handle /scope', () => {
expect(basePath('/scope')).toBe('/scope');
});
it('should handle /', () => {
expect(basePath('/')).toBe('');
});
});
describe('buildUrlQuery', () => {
it('should handle empty options', () => {
expect(buildUrlQuery(makeOrderedMap({}))).toBe('');
});
it('should combine multiple options', () => {
expect(buildUrlQuery(makeOrderedMap([
['foo', 2],
['bar', 4]
]))).toBe('foo=2&bar=4');
});
});
describe('getApiPath', () => {
afterEach(() => {
delete process.env.SCOPE_API_PREFIX;
});
it('returns the correct url when running standalone', () => {
expect(getApiPath('/')).toEqual('');
});
it('returns the correct url when running in an iframe', () => {
expect(getApiPath('/api/app/proud-cloud-77')).toEqual('/api/app/proud-cloud-77');
});
it('returns the correct url when running as a component', () => {
process.env.SCOPE_API_PREFIX = '/api';
expect(getApiPath('/app/proud-cloud-77')).toEqual('/api/app/proud-cloud-77');
});
it('returns the correct url from an arbitrary path', () => {
expect(getApiPath('/demo/')).toEqual('/demo');
});
it('returns the correct url from an *.html page', () => {
expect(getApiPath('/contrast.html')).toEqual('');
});
it('returns the correct url from an /*.html page while in an iframe', () => {
expect(getApiPath('/api/app/proud-cloud-77/contrast.html')).toEqual('/api/app/proud-cloud-77');
});
});
describe('getWebsocketUrl', () => {
const host = 'localhost:4042';
afterEach(() => {
delete process.env.SCOPE_API_PREFIX;
});
it('returns the correct url when running standalone', () => {
expect(getWebsocketUrl(host, '/')).toEqual(`ws://${host}`);
});
it('returns the correct url when running in an iframe', () => {
expect(getWebsocketUrl(host, '/api/app/proud-cloud-77')).toEqual(`ws://${host}/api/app/proud-cloud-77`);
});
it('returns the correct url when running as a component', () => {
process.env.SCOPE_API_PREFIX = '/api';
expect(getWebsocketUrl(host, '/app/proud-cloud-77')).toEqual(`ws://${host}/api/app/proud-cloud-77`);
});
it('returns the correct url from an arbitrary path', () => {
expect(getWebsocketUrl(host, '/demo/')).toEqual(`ws://${host}/demo`);
});
it('returns the correct url from an *.html page', () => {
expect(getWebsocketUrl(host, '/contrast.html')).toEqual(`ws://${host}`);
});
it('returns the correct url from an /*.html page while in an iframe', () => {
expect(getWebsocketUrl(host, '/api/app/proud-cloud-77/contrast.html')).toEqual(`ws://${host}/api/app/proud-cloud-77`);
});
});
});