Skip to content

Commit 9597908

Browse files
committed
Use "as Element" instead of ": Element" in somewhere that can improve efficiency.
1 parent ace3370 commit 9597908

File tree

8 files changed

+60
-58
lines changed

8 files changed

+60
-58
lines changed

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/clusters/Clusters.test.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ it('renders info message about no clusters being available', async () => {
5555
clusters.setState({ clusters: {} });
5656
}
5757
});
58-
const infoElement: Element = container.firstElementChild;
58+
const infoElement = container.firstElementChild as Element;
5959
expect(infoElement.tagName).toBe('DIV');
6060
expect(infoElement.textContent).toBe('No clusters detected.');
6161
});
@@ -84,7 +84,7 @@ it('renders a data-table', async () => {
8484
expect(container.querySelector('.mdc-data-table__table')).toBeTruthy()
8585
);
8686

87-
const topAppBarHeader: Element = container.firstElementChild;
87+
const topAppBarHeader = container.firstElementChild as Element;
8888
expect(topAppBarHeader.tagName).toBe('HEADER');
8989
expect(topAppBarHeader.getAttribute('class')).toContain('mdc-top-app-bar');
9090
expect(topAppBarHeader.getAttribute('class')).toContain(
@@ -94,42 +94,42 @@ it('renders a data-table', async () => {
9494
'mdc-top-app-bar--dense'
9595
);
9696
expect(topAppBarHeader.innerHTML).toContain('Clusters [kernel:no kernel]');
97-
const topAppBarFixedAdjust: Element = container.children[1];
97+
const topAppBarFixedAdjust = container.children[1] as Element;
9898
expect(topAppBarFixedAdjust.tagName).toBe('DIV');
9999
expect(topAppBarFixedAdjust.getAttribute('class')).toContain(
100100
'mdc-top-app-bar--fixed-adjust'
101101
);
102-
const selectBar: Element = container.children[2];
102+
const selectBar = container.children[2] as Element;
103103
expect(selectBar.tagName).toBe('DIV');
104104
expect(selectBar.getAttribute('class')).toContain('mdc-select');
105-
const dialogBox: Element = container.children[3];
105+
const dialogBox = container.children[3] as Element;
106106
expect(dialogBox.tagName).toBe('DIV');
107107
expect(dialogBox.getAttribute('class')).toContain('mdc-dialog');
108-
const clustersComponent: Element = container.children[4];
108+
const clustersComponent = container.children[4] as Element;
109109
expect(clustersComponent.tagName).toBe('DIV');
110110
expect(clustersComponent.getAttribute('class')).toContain('Clusters');
111-
const dataTableDiv: Element = clustersComponent.children[0];
111+
const dataTableDiv = clustersComponent.children[0] as Element;
112112
expect(dataTableDiv.tagName).toBe('DIV');
113113
expect(dataTableDiv.getAttribute('class')).toContain('mdc-data-table');
114-
const dataTable: Element = dataTableDiv.children[0].firstElementChild;
114+
const dataTable = dataTableDiv.children[0].firstElementChild as Element;
115115
expect(dataTable.tagName).toBe('TABLE');
116116
expect(dataTable.getAttribute('class')).toContain('mdc-data-table__table');
117-
const dataTableHead: Element = dataTable.children[0];
117+
const dataTableHead = dataTable.children[0] as Element;
118118
expect(dataTableHead.tagName).toBe('THEAD');
119119
expect(dataTableHead.getAttribute('class')).toContain(
120120
'rmwc-data-table__head'
121121
);
122-
const dataTableHeaderRow: Element = dataTableHead.children[0];
122+
const dataTableHeaderRow = dataTableHead.children[0] as Element;
123123
expect(dataTableHeaderRow.tagName).toBe('TR');
124124
expect(dataTableHeaderRow.getAttribute('class')).toContain(
125125
'mdc-data-table__header-row'
126126
);
127-
const dataTableBody: Element = dataTable.children[1];
127+
const dataTableBody = dataTable.children[1] as Element;
128128
expect(dataTableBody.tagName).toBe('TBODY');
129129
expect(dataTableBody.getAttribute('class')).toContain(
130130
'mdc-data-table__content'
131131
);
132-
const dataTableBodyRow: Element = dataTableBody.children[0];
132+
const dataTableBodyRow = dataTableBody.children[0] as Element;
133133
expect(dataTableBodyRow.tagName).toBe('TR');
134134
expect(dataTableBodyRow.getAttribute('class')).toContain(
135135
'mdc-data-table__row'

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/common/HtmlView.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('HtmlView', () => {
6969
});
7070

7171
await waitFor(() => {
72-
const htmlViewElement: Element = container.firstElementChild;
72+
const htmlViewElement = container.firstElementChild as Element;
7373
expect(htmlViewElement.tagName).toBe('DIV');
7474
expect(htmlViewElement.innerHTML).toBe('<div>Test</div>');
7575
});
@@ -81,7 +81,7 @@ describe('HtmlView', () => {
8181

8282
it(
8383
'only executes incrementally updated Javascript ' +
84-
'as html provider updated',
84+
'as html provider updated',
8585
async () => {
8686
const htmlViewRef: React.RefObject<HtmlView> =
8787
React.createRef<HtmlView>();
@@ -122,7 +122,7 @@ describe('Function importHtml', () => {
122122
await act(async () => {
123123
importHtml([]);
124124
});
125-
const scriptElement: Element = document.head.firstElementChild;
125+
const scriptElement = document.head.firstElementChild as Element;
126126
expect(scriptElement.tagName).toBe('SCRIPT');
127127
expect(scriptElement.getAttribute('src')).toBe(
128128
'https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js'

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/inspector/InspectableList.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,36 @@ it('renders a list', async () => {
7575
/>
7676
);
7777
});
78-
const listElement: Element = container.firstElementChild;
79-
const listHandle: Element = listElement.firstElementChild;
78+
const listElement = container.firstElementChild as Element;
79+
const listHandle = listElement.firstElementChild as Element;
8080
expect(listHandle.tagName).toBe('DIV');
8181
expect(listHandle.getAttribute('class')).toContain(
8282
'rmwc-collapsible-list__handle'
8383
);
84-
const listHandleItem: Element = listHandle.firstElementChild;
84+
const listHandleItem = listHandle.firstElementChild as Element;
8585
expect(listHandleItem.tagName).toBe('LI');
8686
expect(listHandleItem.getAttribute('class')).toContain('mdc-list-item');
87-
const listHandleText: Element = listHandleItem.children[2];
87+
const listHandleText = listHandleItem.children[2] as Element;
8888
expect(listHandleText.getAttribute('class')).toContain('mdc-list-item__text');
89-
const listHandlePrimaryText: Element = listHandleText.firstElementChild;
89+
const listHandlePrimaryText = listHandleText.firstElementChild as Element;
9090
expect(listHandlePrimaryText.getAttribute('class')).toContain(
9191
'mdc-list-item__primary-text'
9292
);
9393
expect(listHandlePrimaryText.textContent).toBe('pipeline_name');
94-
const listHandleMetaIcon: Element = listHandleItem.children[3];
94+
const listHandleMetaIcon = listHandleItem.children[3] as Element;
9595
expect(listHandleMetaIcon.tagName).toBe('I');
9696
expect(listHandleMetaIcon.getAttribute('class')).toContain(
9797
'mdc-list-item__meta'
9898
);
9999
expect(listHandleMetaIcon.textContent).toBe('chevron_right');
100100
// Only check existence of collapsible list children because each child is an
101101
// individual list item that has its own unit tests.
102-
const listChildren: Element = listElement.children[1];
102+
const listChildren = listElement.children[1] as Element;
103103
expect(listChildren.tagName).toBe('DIV');
104104
expect(listChildren.getAttribute('class')).toContain(
105105
'rmwc-collapsible-list__children'
106106
);
107-
const listChildItems: HTMLCollection =
108-
listChildren.firstElementChild.children;
107+
const listChildItems = listChildren.firstElementChild
108+
.children as HTMLCollection;
109109
expect(listChildItems).toHaveLength(2);
110110
});

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/inspector/InspectableListItem.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ it('renders an item', async () => {
5858
/>
5959
);
6060
});
61-
const liElement: Element = container.firstElementChild;
61+
const liElement = container.firstElementChild as Element;
6262
expect(liElement.tagName).toBe('LI');
6363
expect(liElement.getAttribute('class')).toBe('mdc-list-item');
64-
const textElement: Element = liElement.children[1];
64+
const textElement = liElement.children[1] as Element;
6565
expect(textElement.getAttribute('class')).toBe('mdc-list-item__text');
66-
const primaryTextElement: Element = textElement.firstElementChild;
66+
const primaryTextElement = textElement.firstElementChild as Element;
6767
expect(primaryTextElement.getAttribute('class')).toBe(
6868
'mdc-list-item__primary-text'
6969
);
7070
expect(primaryTextElement.textContent).toBe('name');
71-
const secondaryTextElement: Element = textElement.children[1];
71+
const secondaryTextElement = textElement.children[1] as Element;
7272
expect(secondaryTextElement.getAttribute('class')).toBe(
7373
'mdc-list-item__secondary-text'
7474
);

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/inspector/InspectableView.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,31 @@ it('renders options if inspecting a pcollection', async () => {
8989
});
9090
}
9191
});
92-
const inspectableViewElement: Element = container.firstElementChild;
93-
const optionsElement: Element = inspectableViewElement.firstElementChild;
92+
const optionsElement = container.firstElementChild
93+
.firstElementChild as Element;
9494
expect(optionsElement.tagName).toBe('DIV');
95-
const includeWindowInfoCheckbox: Element =
96-
optionsElement.firstElementChild.firstElementChild;
95+
const includeWindowInfoCheckbox = optionsElement.firstElementChild
96+
.firstElementChild as Element;
9797
expect(
9898
includeWindowInfoCheckbox.firstElementChild.getAttribute('class')
9999
).toContain('mdc-checkbox');
100100
expect(
101101
includeWindowInfoCheckbox.firstElementChild.getAttribute('class')
102102
).not.toContain('mdc-checkbox--selected');
103-
const visualizeInFacetsCheckbox: Element =
104-
optionsElement.firstElementChild.children[1];
103+
const visualizeInFacetsCheckbox = optionsElement.firstElementChild
104+
.children[1] as Element;
105105
expect(
106106
visualizeInFacetsCheckbox.firstElementChild.getAttribute('class')
107107
).toContain('mdc-checkbox');
108108
expect(
109109
visualizeInFacetsCheckbox.firstElementChild.getAttribute('class')
110110
).toContain('mdc-checkbox--selected');
111-
const durationTextField: Element =
112-
optionsElement.firstElementChild.children[2];
111+
const durationTextField = optionsElement.firstElementChild
112+
.children[2] as Element;
113113
expect(durationTextField.getAttribute('class')).toContain(
114114
'mdc-text-field--outlined'
115115
);
116-
const nTextField: Element = optionsElement.firstElementChild.children[3];
116+
const nTextField = optionsElement.firstElementChild.children[3] as Element;
117117
expect(nTextField.getAttribute('class')).toContain(
118118
'mdc-text-field--outlined'
119119
);
@@ -130,6 +130,6 @@ it('renders an html view', async () => {
130130
await act(async () => {
131131
root.render(<InspectableView model={fakeModel} />);
132132
});
133-
const inspectableViewElement: Element = container.firstElementChild;
133+
const inspectableViewElement = container.firstElementChild as Element;
134134
expect(inspectableViewElement.innerHTML).toContain('<div>fake html</div>');
135135
});

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/inspector/Inspectables.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ it(`renders info message about no inspectable
6969
inspectables.setState({ inspectables: {} });
7070
}
7171
});
72-
const infoElement: Element = container.firstElementChild;
72+
const infoElement = container.firstElementChild as Element;
7373
expect(infoElement.tagName).toBe('DIV');
7474
expect(infoElement.textContent).toBe(
7575
'No inspectable pipeline nor pcollection has been defined.'
@@ -119,11 +119,11 @@ it('renders inspectables as a list of collapsible lists', async () => {
119119
});
120120

121121
await waitFor(() => {
122-
const listElement: Element = container.firstElementChild;
122+
const listElement = container.firstElementChild as Element;
123123
expect(listElement.tagName).toBe('UL');
124124
expect(listElement.getAttribute('class')).toContain('mdc-list');
125-
// Only checks the length of dummy InspectableList items. Each InspectableList
126-
// has its own unit tests.
125+
// Only checks the length of dummy InspectableList items.
126+
// Each InspectableList has its own unit tests.
127127
expect(listElement.children).toHaveLength(2);
128-
})
128+
});
129129
});

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/inspector/InteractiveInspector.test.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ it('renders the top app bar and drawer wrapped inspectables', async () => {
7575
/>
7676
);
7777
});
78-
const topAppBarHeader: Element = container.firstElementChild;
78+
const topAppBarHeader = container.firstElementChild as Element;
7979
expect(topAppBarHeader.tagName).toBe('HEADER');
8080
expect(topAppBarHeader.getAttribute('class')).toContain('mdc-top-app-bar');
8181
expect(topAppBarHeader.getAttribute('class')).toContain(
@@ -86,26 +86,27 @@ it('renders the top app bar and drawer wrapped inspectables', async () => {
8686
);
8787
expect(topAppBarHeader.innerHTML).toContain('menu');
8888
expect(topAppBarHeader.innerHTML).toContain('Inspector [kernel:no kernel]');
89-
const topAppBarFixedAdjust: Element = container.children[1];
89+
const topAppBarFixedAdjust = container.children[1] as Element;
9090
expect(topAppBarFixedAdjust.tagName).toBe('DIV');
9191
expect(topAppBarFixedAdjust.getAttribute('class')).toContain(
9292
'mdc-top-app-bar--fixed-adjust'
9393
);
94-
const interactiveInspectorDiv: Element = container.children[2];
94+
const interactiveInspectorDiv = container.children[2] as Element;
9595
expect(interactiveInspectorDiv.tagName).toBe('DIV');
9696
expect(interactiveInspectorDiv.getAttribute('class')).toContain(
9797
'InteractiveInspector'
9898
);
99-
const inspectablesAside: Element = interactiveInspectorDiv.firstElementChild;
99+
const inspectablesAside =
100+
interactiveInspectorDiv.firstElementChild as Element;
100101
expect(inspectablesAside.tagName).toBe('ASIDE');
101102
expect(inspectablesAside.innerHTML).toContain(
102103
'<div>No inspectable pipeline nor pcollection has been defined.</div>'
103104
);
104105
expect(inspectablesAside.firstElementChild.getAttribute('class')).toContain(
105106
'mdc-drawer__content'
106107
);
107-
const inspectableViewAsAppContent: Element =
108-
interactiveInspectorDiv.children[1];
108+
const inspectableViewAsAppContent = interactiveInspectorDiv
109+
.children[1] as Element;
109110
expect(inspectableViewAsAppContent.tagName).toBe('DIV');
110111
expect(inspectableViewAsAppContent.getAttribute('class')).toContain(
111112
'mdc-drawer-app-content'
@@ -127,7 +128,7 @@ it('renders the drawer open by default', async () => {
127128
/>
128129
);
129130
});
130-
const inspectablesAside: Element = container.children[2].firstElementChild;
131+
const inspectablesAside = container.children[2].firstElementChild as Element;
131132
expect(inspectablesAside.getAttribute('class')).toContain('mdc-drawer--open');
132133
});
133134

@@ -190,8 +191,10 @@ it('updates session info on change', async () => {
190191
});
191192

192193
await waitFor(() => {
193-
const topAppBarHeader: Element =
194-
container.firstElementChild.firstElementChild.firstElementChild.children[1];
195-
expect(topAppBarHeader.innerHTML).toContain('Inspector [kernel:new kernel]');
194+
const topAppBarHeader = container.firstElementChild.firstElementChild
195+
.firstElementChild.children[1] as Element;
196+
expect(topAppBarHeader.innerHTML).toContain(
197+
'Inspector [kernel:new kernel]'
198+
);
196199
});
197200
});

sdks/python/apache_beam/runners/interactive/extensions/apache-beam-jupyterlab-sidepanel/src/__tests__/kernel/InterruptKernelButton.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { act } from 'react';
1818

1919
import { InterruptKernelButton } from '../../kernel/InterruptKernelButton';
2020

21-
import { waitFor } from '@testing-library/react'
21+
import { waitFor } from '@testing-library/react';
2222

2323
const fakeKernelModel = {
2424
isDone: true,
@@ -73,18 +73,17 @@ it(`displays a button when the kernel model
7373
await act(async () => {
7474
fakeKernelModel.isDone = false;
7575
button?.updateRender();
76-
await new Promise(resolve => setTimeout(resolve, 100));
7776
});
7877

7978
await waitFor(() => {
8079
const button = container.firstElementChild;
8180
expect(button).not.toBeNull();
8281
expect(button?.tagName).toBe('BUTTON');
83-
})
84-
const buttonElement: null | Element = container.firstElementChild;
82+
});
83+
const buttonElement = container.firstElementChild as Element;
8584
expect(buttonElement.getAttribute('class')).toContain('mdc-button');
8685
expect(buttonElement.getAttribute('class')).toContain('mdc-button--raised');
87-
const labelElement: Element = buttonElement.children[1];
86+
const labelElement = buttonElement.children[1] as Element;
8887
expect(labelElement.tagName).toBe('SPAN');
8988
expect(labelElement.getAttribute('class')).toContain('mdc-button__label');
9089
expect(labelElement.innerHTML).toBe('stop');

0 commit comments

Comments
 (0)