pageconfig.spec.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { PageConfig } from '@jupyterlab/coreutils';
  4. describe('@jupyterlab/coreutils', () => {
  5. describe('PageConfig', () => {
  6. beforeEach(() => {
  7. PageConfig.setOption('foo', 'bar');
  8. });
  9. describe('#getOption()', () => {
  10. it('should get a known option', () => {
  11. expect(PageConfig.getOption('foo')).toBe('bar');
  12. });
  13. it('should return an empty string for an unknown option', () => {
  14. expect(PageConfig.getOption('bar')).toBe('');
  15. });
  16. });
  17. describe('#setOption()', () => {
  18. it('should get last option value and set it to the passed value', () => {
  19. expect(PageConfig.setOption('foo', 'bar1')).toBe('bar');
  20. });
  21. it('should get a known option', () => {
  22. expect(PageConfig.getOption('foo')).toBe('bar');
  23. });
  24. it('should add a new option', () => {
  25. expect(PageConfig.setOption('bar', 'foo')).toBe('');
  26. });
  27. it('should get a different known option', () => {
  28. expect(PageConfig.getOption('bar')).toBe('foo');
  29. });
  30. });
  31. describe('#getBaseUrl()', () => {
  32. it('should get the base url of the page', () => {
  33. // The value was passed as a command line arg.
  34. expect(PageConfig.getBaseUrl()).toContain('http://localhost');
  35. });
  36. });
  37. describe('#getWsUrl()', () => {
  38. it('should get the base ws url of the page', () => {
  39. // The value was passed as a command line arg.
  40. const expected = 'ws' + PageConfig.getBaseUrl().slice(4);
  41. expect(PageConfig.getWsUrl()).toBe(expected);
  42. });
  43. it('should handle a good base url', () => {
  44. const url = 'http://foo.com';
  45. expect(PageConfig.getWsUrl(url)).toBe('ws://foo.com/');
  46. });
  47. it('should be an empty string for a bad base url', () => {
  48. const url = 'blargh://foo.com';
  49. expect(PageConfig.getWsUrl(url)).toBe('');
  50. });
  51. });
  52. });
  53. });