-
Notifications
You must be signed in to change notification settings - Fork 60
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
add tests for table #215
Merged
Merged
add tests for table #215
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Don't process node_modules except for AWS UI. | ||
module.exports = { | ||
ignore: [/node_modules\/?!@awsui\/components-react/], | ||
presets: ['@babel/preset-env'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { DataStream, Viewport } from '@iot-app-kit/core'; | ||
import { Annotations, COMPARISON_OPERATOR, getThresholds, StatusIcon } from '@synchro-charts/core'; | ||
import { ColumnDefinition, createTableItems, DefaultTableMessages, Item } from '../utils'; | ||
import { Table } from './index'; | ||
|
||
globalThis.IS_REACT_ACT_ENVIRONMENT = true; | ||
const dataStreamId = 'datastream-1'; | ||
const dataStream: DataStream = { | ||
id: dataStreamId, | ||
data: [ | ||
{ x: new Date(2021, 1, 1).getTime(), y: 100 }, | ||
{ x: new Date(2022, 1, 1).getTime(), y: 200 }, | ||
], | ||
resolution: 0, | ||
}; | ||
|
||
const items: Item[] = [ | ||
{ | ||
value: { | ||
$cellRef: { | ||
id: dataStreamId, | ||
resolution: 0, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const columnDefinitions: ColumnDefinition[] = [ | ||
{ | ||
header: 'value', | ||
key: 'value', | ||
}, | ||
]; | ||
|
||
let container: HTMLDivElement; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
act(() => { | ||
ReactDOM.unmountComponentAtNode(container); | ||
container.remove(); | ||
}); | ||
}); | ||
|
||
it('renders correct data when viewport defined by duration', async () => { | ||
const tableItems = createTableItems( | ||
{ | ||
dataStreams: [dataStream], | ||
items, | ||
viewport: { | ||
duration: '1000', | ||
}, | ||
}, | ||
DefaultTableMessages | ||
); | ||
|
||
act(() => { | ||
ReactDOM.render( | ||
<Table columnDefinitions={columnDefinitions} messageOverrides={DefaultTableMessages} items={tableItems} />, | ||
container | ||
); | ||
}); | ||
|
||
const cell = container.getElementsByClassName('iot-table-cell').item(0) as HTMLDivElement; | ||
expect(cell.innerHTML).toMatch('200'); | ||
}); | ||
|
||
it('renders correct data when the viewport defined by start and end time', async () => { | ||
const viewport: Viewport = { | ||
start: new Date(2021, 0, 0, 0, 0, 0), | ||
end: new Date(2021, 12, 30, 0, 0, 0), | ||
}; | ||
const tableItems = createTableItems({ dataStreams: [dataStream], items, viewport }, DefaultTableMessages); | ||
act(() => { | ||
ReactDOM.render( | ||
<Table columnDefinitions={columnDefinitions} messageOverrides={DefaultTableMessages} items={tableItems} />, | ||
container | ||
); | ||
}); | ||
|
||
const cell = container.getElementsByClassName('iot-table-cell').item(0) as HTMLDivElement; | ||
expect(cell.innerHTML).toMatch('100'); | ||
}); | ||
|
||
it('renders loading circle when datastream is in loading state', async () => { | ||
const loadingDatastream: DataStream = { | ||
isLoading: true, | ||
data: [], | ||
id: dataStreamId, | ||
resolution: 0, | ||
}; | ||
const tableItems = createTableItems( | ||
{ dataStreams: [loadingDatastream], items, viewport: { duration: '1000' } }, | ||
DefaultTableMessages | ||
); | ||
|
||
act(() => { | ||
ReactDOM.render( | ||
<Table columnDefinitions={columnDefinitions} messageOverrides={DefaultTableMessages} items={tableItems} />, | ||
container | ||
); | ||
}); | ||
|
||
const svg = container.getElementsByTagName('svg').item(0) as SVGElement; | ||
expect(svg).toBeTruthy(); | ||
}); | ||
|
||
it('renders icon and applies style when a datastream breaches threshold', async () => { | ||
const annotations: Annotations = { | ||
y: [ | ||
{ | ||
color: 'red', | ||
value: 30, | ||
comparisonOperator: COMPARISON_OPERATOR.GREATER_THAN, | ||
icon: StatusIcon.ERROR, | ||
dataStreamIds: [dataStreamId], | ||
}, | ||
], | ||
}; | ||
const tableItems = createTableItems( | ||
{ dataStreams: [dataStream], items, viewport: { duration: '1000' }, thresholds: getThresholds(annotations) }, | ||
DefaultTableMessages | ||
); | ||
|
||
act(() => { | ||
ReactDOM.render( | ||
<Table columnDefinitions={columnDefinitions} messageOverrides={DefaultTableMessages} items={tableItems} />, | ||
container | ||
); | ||
}); | ||
|
||
const cell = container.getElementsByClassName('iot-table-cell').item(0) as HTMLDivElement; | ||
expect(cell.style.color).toEqual('red'); | ||
const iconContainer = cell.childNodes.item(0); | ||
expect(iconContainer).toBeTruthy(); | ||
const text = cell.childNodes.item(1) as Text; | ||
expect(text.wholeText).toMatch('200'); | ||
}); | ||
|
||
it('renders icon and displays error message when datastream is in error state', () => { | ||
const tableItems = createTableItems( | ||
{ | ||
dataStreams: [ | ||
{ | ||
data: [], | ||
id: dataStreamId, | ||
error: { | ||
msg: 'Error', | ||
}, | ||
resolution: 0, | ||
}, | ||
], | ||
items, | ||
viewport: { duration: '1000' }, | ||
}, | ||
DefaultTableMessages | ||
); | ||
|
||
act(() => { | ||
ReactDOM.render( | ||
<Table columnDefinitions={columnDefinitions} messageOverrides={DefaultTableMessages} items={tableItems} />, | ||
container | ||
); | ||
}); | ||
|
||
const cell = container.getElementsByClassName('iot-table-cell').item(0) as HTMLDivElement; | ||
const iconContainer = cell.childNodes.item(0); | ||
expect(iconContainer).toBeTruthy(); | ||
|
||
const text = cell.childNodes.item(1) as Text; | ||
expect(text.wholeText).toMatch('Error'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 happened here?