pageconfig.spec.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) Jupyter Development Team.
  2. import 'jest';
  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 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. });