-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tests for acceleration components #1495
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { configure, mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import React from 'react'; | ||
import { dummyAccelerations } from '../../../../../../../test/datasources'; | ||
import { AccelerationDetailsFlyout } from '../acceleration_details_flyout'; | ||
import { cleanup, fireEvent, render } from '@testing-library/react'; | ||
|
||
describe('Acceleration Details Flyout test', () => { | ||
configure({ adapter: new Adapter() }); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('Render acceleration detail flyout', () => { | ||
const wrapper = mount(<AccelerationDetailsFlyout acceleration={dummyAccelerations[0]} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('Render acceleration detail flyout and click on schema tab', () => { | ||
const utils = render(<AccelerationDetailsFlyout acceleration={dummyAccelerations[0]} />); | ||
|
||
fireEvent.click(utils.getByTestId('accelerationDetailsFlyoutTab_schema')); | ||
expect(utils.container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { configure, mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import { AccelerationTable } from '../acceleration_table'; | ||
|
||
import React from 'react'; | ||
import { dummyAccelerations } from '../../../../../../../test/datasources'; | ||
import * as Plugin from '../../../../../../plugin'; | ||
|
||
describe('Acceleration Table Test', () => { | ||
configure({ adapter: new Adapter() }); | ||
|
||
Plugin.getRenderAccelerationDetailsFlyout = jest.fn(); | ||
|
||
it('Render empty acceleration table', () => { | ||
const wrapper = mount(<AccelerationTable accelerations={[]} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add more interaction tests for flyouts and table once we connect these with the backend. These should be good for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, you can mock like this:
so that we can test the render:
|
||
}); | ||
|
||
it('Render acceleration table with dummy acceleration', () => { | ||
const wrapper = mount(<AccelerationTable accelerations={dummyAccelerations} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,13 @@ | |
} from '../accelerations/helpers/utils'; | ||
|
||
export interface AccelerationDetailsFlyoutProps { | ||
acceleration: any; | ||
} | ||
|
||
export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) => { | ||
const { acceleration } = props; | ||
const [selectedTab, setSelectedTab] = useState('details'); | ||
const tabsMap: { [key: string]: any } = { | ||
details: AccelerationDetailsTab, | ||
schema: AccelerationSchemaTab, | ||
sql_definition: AccelerationSqlTab, | ||
|
@@ -42,23 +42,32 @@ | |
const DiscoverButton = () => { | ||
// TODO: display button if can be sent to discover | ||
return ( | ||
<EuiButtonEmpty onClick={onDiscoverButtonClick}> | ||
<EuiButtonEmpty | ||
onClick={onDiscoverButtonClick} | ||
data-test-subj="accelerationDetailsFlyoutDiscoverButton" | ||
> | ||
<EuiIcon type={'discoverApp'} size="m" /> | ||
</EuiButtonEmpty> | ||
); | ||
}; | ||
|
||
const RefreshButton = () => { | ||
return ( | ||
<EuiButtonEmpty onClick={onRefreshButtonClick}> | ||
<EuiButtonEmpty | ||
onClick={onRefreshButtonClick} | ||
data-test-subj="accelerationDetailsFlyoutRefreshButton" | ||
> | ||
<EuiIcon type={getRefreshButtonIcon()} size="m" /> | ||
</EuiButtonEmpty> | ||
); | ||
}; | ||
|
||
const DeleteButton = () => { | ||
return ( | ||
<EuiButtonEmpty onClick={onDeleteButtonClick}> | ||
<EuiButtonEmpty | ||
onClick={onDeleteButtonClick} | ||
data-test-subj="accelerationDetailsFlyoutDeleteButton" | ||
> | ||
<EuiIcon type="trash" size="m" /> | ||
</EuiButtonEmpty> | ||
); | ||
|
@@ -90,6 +99,7 @@ | |
isSelected={tab.id === selectedTab} | ||
disabled={tab.disabled} | ||
key={index} | ||
data-test-subj={'accelerationDetailsFlyoutTab_' + tab.id} | ||
> | ||
{tab.name} | ||
</EuiTab> | ||
|
@@ -97,7 +107,7 @@ | |
}); | ||
}; | ||
|
||
const renderTabContent = (tab: string, tabAcceleration: any) => { | ||
const TabToDisplay = tabsMap[tab]; | ||
return <TabToDisplay acceleration={tabAcceleration} />; | ||
}; | ||
|
@@ -107,7 +117,7 @@ | |
<EuiFlyoutHeader hasBorder> | ||
<EuiFlexGroup direction="row" alignItems="center" gutterSize="m"> | ||
<EuiFlexItem> | ||
<EuiText> | ||
<EuiText data-test-subj="accelerationDetailsFlyoutTitle"> | ||
<h2 className="panel-title">{acceleration.name}</h2> | ||
</EuiText> | ||
</EuiFlexItem> | ||
|
@@ -122,7 +132,12 @@ | |
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="m" /> | ||
<EuiTabs style={{ marginBottom: '-25px' }}>{renderTabs()}</EuiTabs> | ||
<EuiTabs | ||
style={{ marginBottom: '-25px' }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid this inline style, and we can switch to a SCSS to define this. But yeah, this is not related to this PR, and we can do that as a follow up. |
||
data-test-subj="accelerationDetailsTabFlyoutTabs" | ||
> | ||
{renderTabs()} | ||
</EuiTabs> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody>{renderTabContent(selectedTab, acceleration)}</EuiFlyoutBody> | ||
</> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this clean up for?