GlobalHTMLObserver extends GuidedTourObserver<GlobalHTMLObserver> { void onHTMLElementEvent(final Event event) { getMonitorBridge().ifPresent(bridge -> bridge.refresh(getUserInteraction(event))); } @Inject  GlobalHTMLObserver(final Disposer<GlobalHTMLObserver> selfDisposer); @PostConstruct void init(); String getDataAttributes(final HTMLElement element);  }
@Test public void testOnHTMLElementEvent() { final Event event = mock(Event.class); final HTMLElement htmlElement = mock(HTMLElement.class); final DOMTokenList classList = mock(DOMTokenList.class); final UserInteraction expected = mock(UserInteraction.class); final List<String> classStringList = asList("pf-label", "pf-label--red", "pf-label--xl"); final NamedNodeMap<Attr> attrNamedNodeMap = spy(new NamedNodeMap<>()); final Attr node1 = new Attr(); final Attr node2 = new Attr(); htmlElement.id = "user-name-label"; htmlElement.tagName = "div"; htmlElement.classList = classList; htmlElement.attributes = attrNamedNodeMap; event.target = htmlElement; classList.length = classStringList.size(); attrNamedNodeMap.length = 2; node1.nodeName = "data-field"; node1.nodeValue = "username"; node2.nodeName = "data-key"; node2.nodeValue = "123"; when(classList.asList()).thenReturn(classStringList); doReturn(node1).when(attrNamedNodeMap).item(0); doReturn(node2).when(attrNamedNodeMap).item(1); doReturn(expected).when(htmlObserver).makeUserInteraction("CLICK", "div[data-field=\"username\"][data-key=\"123\"]#user-name-label.pf-label.pf-label--red.pf-label--xl"); htmlObserver.onHTMLElementEvent(event); verify(bridge).refresh(userInteractionArgumentCaptor.capture()); final UserInteraction actual = userInteractionArgumentCaptor.getValue(); assertEquals(expected, actual); }