Exemple #1
0
    it('should throw error if the ace editor CSS style cannot be found', () => {
      const mockSession = jasmine.createSpyObj('Session', ['setTabSize', 'setUseSoftTabs']);
      const mockEditor = jasmine.createSpyObj(
          'Editor',
          [
            'destroy',
            'setFontSize',
            'setHighlightActiveLine',
            'setReadOnly',
          ]);
      mockEditor.session = mockSession;
      mockAce.edit.and.returnValue(mockEditor);

      const mockShadowRoot = jasmine.createSpyObj('ShadowRoot', ['appendChild', 'querySelector']);
      const containerEl = Mocks.object('containerEl');
      containerEl.parentNode = mockShadowRoot;

      mockDocument.getElementById.and.returnValue(null);

      spyOn(input, 'addDisposable').and.callThrough();

      assert(() => {
        input['getEditor_'](containerEl);
      }).to.throwError(/css not found/);

      assert(mockDocument.getElementById).to.haveBeenCalledWith('ace_editor.css');
    });
Exemple #2
0
    it('should set the correct target element to active', () => {
      const rootEl = Mocks.object('rootEl');
      const fullPath = 'fullPath';

      const slotName = 'slotName';
      const path = 'path';
      const childWithPath = document.createElement('div');
      childWithPath.setAttribute('gs-view-path', path);
      childWithPath.setAttribute('slot', slotName);

      const childNoPath = document.createElement('div');

      const element = document.createElement('div');
      element.appendChild(childNoPath);
      element.appendChild(childWithPath);
      element[__fullPath] = fullPath;

      const appendedPath = 'appendedPath';
      spyOn(LocationService, 'appendParts').and.returnValue(appendedPath);

      spyOn(LocationService, 'hasMatch').and.returnValue(true);

      spyOn(viewSlot, 'setRootElVisible_');

      const fakeSwitchValueSetter = new FakeMonadSetter<string | null>(null);

      const updates = viewSlot.updateActiveView_(element, rootEl, fakeSwitchValueSetter);
      assert(fakeSwitchValueSetter.findValue(updates)!.value).to.equal(slotName);
      assert(viewSlot['setRootElVisible_']).to.haveBeenCalledWith(rootEl, true);
      assert(LocationService.appendParts).to.haveBeenCalledWith(ImmutableList.of([fullPath, path]));
      assert(LocationService.hasMatch).to.haveBeenCalledWith(appendedPath);
      assert(childWithPath.getAttribute('gs-view-active')).to.equal('true');
    });
Exemple #3
0
    it('should resolve with the file content correctly', async () => {
      const mockListenableFileReader = jasmine.createSpyObj('ListenableFileReader', ['dispose']);
      spyOn(ListenableDom, 'of').and.returnValue(mockListenableFileReader);

      const content = 'content';
      const mockFileReader = jasmine.createSpyObj('FileReader', ['readAsText']);
      mockFileReader.result = content;
      mockFileReader.readyState = 2;
      spyOn(service, 'createFileReader_').and.returnValue(mockFileReader);
      const listenToSpy = spyOn(service, 'listenTo');

      const file = Mocks.object('file');

      const promise = service['processFile_'](file);
      assert(mockFileReader.readAsText).to.haveBeenCalledWith(file);
      assert(ListenableDom.of).to.haveBeenCalledWith(mockFileReader);
      assert(service.listenTo).to.haveBeenCalledWith(
          mockListenableFileReader,
          DomEvent.LOADEND,
          Matchers.any(Function) as any);
      listenToSpy.calls.argsFor(0)[2]();

      const actualContent = await promise;
      assert(actualContent).to.equal(content);
      assert(mockListenableFileReader.dispose).to.haveBeenCalledWith();
    });
 it('should throw error if shadow root is null', () => {
   const element = Mocks.object('element');
   element.shadowRoot = null;
   assert(() => {
     themedElement.onCreated(element);
   }).to.throwError(/root is null/);
 });
Exemple #5
0
 beforeEach(() => {
   const injector = Mocks.object('injector');
   mockThemeService = jasmine.createSpyObj('ThemeService', ['applyTheme', 'install']);
   mockRegistrar = jasmine.createSpyObj('Registrar', ['register']);
   main = new Main(injector, mockThemeService, mockRegistrar);
   TestDispose.add(main);
 });
Exemple #6
0
 it('should remove the "hidden" classname when setting to be visible', () => {
   const mockClassList = jasmine.createSpyObj('ClassList', ['toggle']);
   const rootEl = Mocks.object('rootEl');
   rootEl.classList = mockClassList;
   viewSlot['setRootElVisible_'](rootEl, true);
   assert(mockClassList.toggle).to.haveBeenCalledWith('hidden', false);
 });
Exemple #7
0
    it(`should hide the overlay if set to hide`, async () => {
      Graph.createProvider($.host.fitParentWidth.getId(), false);
      Graph.createProvider($.host.anchorPoint.getId(), AnchorLocation.BOTTOM_LEFT);
      Graph.createProvider($.host.anchorTarget.getId(), AnchorLocation.TOP_RIGHT);

      const parentElement = Mocks.object('parentElement');
      parentElement.clientWidth = 123;

      const element = Mocks.object('element');
      element.parentElement = parentElement;
      Object.setPrototypeOf(element, HTMLElement.prototype);
      Graph.createProvider($.host.el.getId(), element);

      await menu['setOverlayVisible_'](false, Graph.getTimestamp());
      assert(mockOverlayService.hideOverlay).to.haveBeenCalledWith(menu['id_']);
    });
Exemple #8
0
 it('should set the top and height correctly', () => {
   const start = 123;
   const length = 456;
   const style = Mocks.object('style');
   tab.setHighlightEl(start, length, {style} as HTMLElement);
   assert(style).to.equal(Matchers.objectContaining({top: `${start}px`, height: `${length}px`}));
 });
 it(`should return the ID in the container element`, () => {
   const shownId = Symbol('shownId');
   const containerEl = Mocks.object('containerEl');
   containerEl[__shownId] = shownId;
   spyOn(service, 'getOverlayContainerEl_').and.returnValue(containerEl);
   assert(service['getShownId_']()).to.equal(shownId);
 });
Exemple #10
0
    it('should resolve if there are no menu contents', async () => {
      Graph.createProvider($.host.fitParentWidth.getId(), true);
      Graph.createProvider($.host.anchorPoint.getId(), AnchorLocation.BOTTOM_LEFT);
      Graph.createProvider($.host.anchorTarget.getId(), AnchorLocation.TOP_RIGHT);

      const parentElement = Mocks.object('parentElement');
      parentElement.clientWidth = 123;

      const element = Mocks.object('element');
      element.parentElement = parentElement;
      element.firstElementChild = null;
      Object.setPrototypeOf(element, HTMLElement.prototype);
      Graph.createProvider($.host.el.getId(), element);

      await menu['setOverlayVisible_'](true, Graph.getTimestamp());
    });