]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Fix the table mouseenter event handling test
authorStephan Müller <smueller@suse.com>
Fri, 5 Jul 2019 09:54:40 +0000 (11:54 +0200)
committerStephan Müller <smueller@suse.com>
Fri, 5 Jul 2019 11:39:29 +0000 (13:39 +0200)
This test only failed if all suites were run, for some reason the window
object got replaced with a mock window. The workaround is not to use
the window object, but mock the called function in order to call the
values as expected by window.

Fixes: https://tracker.ceph.com/issues/40580
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/datatable/table/table.component.spec.ts

index aa86e5de32d6aaf5af4e22aab5ee7a738e1389b4..1a11c43269f18669ca9675d149827245a13d2201 100644 (file)
@@ -80,10 +80,18 @@ describe('TableComponent', () => {
   });
 
   it('should prevent propagation of mouseenter event', (done) => {
-    fixture.detectChanges();
+    let wasCalled = false;
     const mouseEvent = new MouseEvent('mouseenter');
-    mouseEvent.stopPropagation = () => done();
-    fixture.debugElement.nativeElement.dispatchEvent(mouseEvent);
+    mouseEvent.stopPropagation = () => {
+      wasCalled = true;
+    };
+    spyOn(window, 'addEventListener').and.callFake((eventName, fn) => {
+      fn(mouseEvent);
+      expect(eventName).toBe('mouseenter');
+      expect(wasCalled).toBe(true);
+      done();
+    });
+    component.ngOnInit();
   });
 
   describe('test search', () => {