我们在SAP Spartacus B2B Page 的 list和Card页面,点击(i) icon之后,会看到一个popover Component,可以通过下面的选择器访问:
可以通过如下的代码访问:
describe('hint', () => {
beforeEach(() => {
fixture.detectChanges();
});
it('should not show hint by default', () => {
const el = fixture.debugElement.query(
By.css('cx-popover > .popover-body > p')
);
expect(el).toBeFalsy();
});
it('should display hint after click info button', () => {
const infoButton = fixture.debugElement.query(
By.css('button[ng-reflect-cx-popover]')
).nativeElement;
infoButton.click();
const el = fixture.debugElement.query(
By.css('cx-popover > .popover-body > p')
);
expect(el).toBeTruthy();
expect(el.nativeElement.innerText).toBe('organization.budget.hint');
});
});
其中下面这行代码是css属性选择器的用法:
button[ng-reflect-cx-popover]
因为button按钮渲染完毕后,具有属性 ng-reflect-cx-popover