github.com/GoogleCloudPlatform/testgrid@v0.0.174/web/test/testgrid-data-content.test.ts (about) 1 import { 2 html, 3 fixture, 4 defineCE, 5 unsafeStatic, 6 expect, 7 waitUntil, 8 } from '@open-wc/testing'; 9 10 import { TestgridDataContent} from '../src/testgrid-data-content'; 11 import { Tab } from '@material/mwc-tab'; 12 13 describe('Testgrid Data Content page', () => { 14 let element: TestgridDataContent; 15 beforeEach(async () => { 16 // Need to wrap an element to apply its properties (ex. @customElement) 17 // See https://open-wc.org/docs/testing/helpers/#test-a-custom-class-with-properties 18 const tagName = defineCE(class extends TestgridDataContent {}); 19 const tag = unsafeStatic(tagName); 20 element = await fixture(html`<${tag} .dashboardName=${'fake-dashboard-1'}></${tag}>`); 21 }); 22 23 // TODO - add accessibility tests 24 // TODO - add tests for tab switching behaviour 25 it('fetches the tab names and renders the tab bar', async () => { 26 await waitUntil( 27 () => element.shadowRoot!.querySelector('mwc-tab-bar'), 28 'Data content did not render the tab bar', 29 { 30 timeout: 4000, 31 }, 32 ); 33 34 expect(element.tabNames).to.not.be.empty; 35 }); 36 37 it('renders the dashboard summary if `showTab` attribute is not passed', async () => { 38 await waitUntil( 39 () => element.shadowRoot!.querySelector('mwc-tab-bar'), 40 'Data content did not render the tab bar', 41 { 42 timeout: 4000, 43 }, 44 ); 45 46 expect(element.tabNames).to.not.be.empty; 47 expect(element.activeIndex).to.equal(0); 48 }); 49 50 it('renders the grid display if a tab is clicked', async() => { 51 52 await waitUntil( 53 () => element.shadowRoot!.querySelector('mwc-tab'), 54 'Data content did not render the tab bar', 55 { 56 57 timeout: 4000, 58 }, 59 ); 60 61 const tab: NodeListOf<Tab>| null = element.shadowRoot!.querySelectorAll('mwc-tab'); 62 tab[1]!.click(); 63 64 await waitUntil( 65 () => element.shadowRoot!.querySelector('testgrid-grid'), 66 'Data content did not render the grid data', 67 { 68 timeout: 4000, 69 }, 70 ); 71 72 expect(element.activeIndex).to.not.equal(0); 73 expect(element.showTab).to.equal(true); 74 }); 75 });