pageconfig.spec.ts 2.0 KB

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