This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
portal/src/app/components/dashboard/components/charts/utils/charts.utils.test.ts
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,7 @@ | ||
import { getColorByName } from './charts.utils'; | ||
|
||
describe('Charts Util Test', () => { | ||
test('should get color by name', () => { | ||
expect(getColorByName('bikel1')).toBe('#FF8500'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...me/components/experiment/components/charts/components/dynamic-chart/DynamicChart.test.tsx
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,33 @@ | ||
import { render } from '@testing-library/react'; | ||
import { useDynamicChartData } from './hooks/useDynamicChartData'; | ||
import { BarChart } from '../../../../../../../dashboard/components/charts/BarChart/BarChart'; | ||
import { LineChart } from '../../../../../../../dashboard/components/charts/LineChart/LineChart'; | ||
|
||
jest.mock('../../../../../../../dashboard/components/charts/BarChart/BarChart'); | ||
jest.mock('../../../../../../../dashboard/components/charts/LineChart/LineChart'); | ||
jest.mock('../../../../../../../../shared/components/att-select/AttSelect', () => ({ | ||
AttSelect: jest.fn(() => <div>Mocked AttSelect</div>), | ||
})); | ||
jest.mock('./hooks/useDynamicChartData'); | ||
|
||
describe('DynamicChart', () => { | ||
test('should render Charts', async () => { | ||
(BarChart as jest.Mock).mockImplementation(() => <div>BarChart</div>); | ||
(LineChart as jest.Mock).mockImplementation(() => <div>LineChart</div>); | ||
|
||
|
||
(useDynamicChartData as jest.Mock).mockReturnValue({ | ||
yAxiosOptions: [{ | ||
label: 'averageCPU', | ||
value: 'averageCPU' | ||
}, | ||
{ | ||
label: 'averageMemory', | ||
value: 'averageMemory' | ||
}], | ||
}); | ||
|
||
const { container } = render(<BarChart title='Iterations' labels={[]} data={undefined} keyOfData={''} tooltipKeys={[]} tooltipLabels={[]} />); | ||
expect(container).toBeTruthy(); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...nents/dynamic-chart/components/custom-dropdown-indicator/CustomDropdownIndicator.test.tsx
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,30 @@ | ||
import { render, RenderResult } from '@testing-library/react'; | ||
import { CustomDropdownIndicator } from './CustomDropdownIndicator'; | ||
import { DropdownIndicatorProps } from 'react-select'; | ||
import { AttSelectOption } from '../../../../../../../../../../shared/components/att-select'; | ||
|
||
describe('CustomDropdownIndicator', () => { | ||
const mockProps: DropdownIndicatorProps<AttSelectOption, any> = { | ||
innerProps: undefined as any, | ||
isFocused: false, | ||
isDisabled: false, | ||
clearValue: jest.fn(), | ||
cx: jest.fn(), | ||
getStyles: jest.fn(), | ||
getClassNames: jest.fn(), | ||
getValue: jest.fn(), | ||
hasValue: false, | ||
isMulti: false, | ||
isRtl: false, | ||
options: [], | ||
selectOption: jest.fn(), | ||
selectProps: undefined as any, | ||
setValue: jest.fn(), | ||
theme: undefined as any, | ||
}; | ||
|
||
it('should render CustomDropdownIndicator', () => { | ||
const { container }: RenderResult = render(<CustomDropdownIndicator {...mockProps} />); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
.../components/custom-dropdown-indicator/__snapshots__/CustomDropdownIndicator.test.tsx.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CustomDropdownIndicator should render CustomDropdownIndicator 1`] = ` | ||
<div> | ||
<div | ||
class="css-0" | ||
> | ||
<svg> | ||
arrow-down-selector.svg | ||
</svg> | ||
</div> | ||
</div> | ||
`; |
42 changes: 42 additions & 0 deletions
42
...components/charts/components/dynamic-chart/components/custom-option/CustomOption.test.tsx
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,42 @@ | ||
import { render, RenderResult } from '@testing-library/react'; | ||
import { CustomOption } from './CustomOption'; | ||
import { SelectorCustomOptionProps } from '../../../../../../../../../../shared/components/selector-custom-option'; | ||
|
||
describe('CustomOption', () => { | ||
const mockOption = { value: 'option1', label: 'Option 1' }; | ||
const mockProps: SelectorCustomOptionProps = { | ||
data: mockOption, | ||
isSelected: false, | ||
selectOption: jest.fn(), | ||
label: 'Option 1', | ||
innerProps: {}, | ||
innerRef: jest.fn(), | ||
children: null, | ||
type: 'option', | ||
isDisabled: false, | ||
isFocused: false, | ||
clearValue: jest.fn(), | ||
cx: jest.fn(), | ||
getStyles: jest.fn(), | ||
getClassNames: jest.fn(), | ||
getValue: jest.fn().mockReturnValue([{ label: 'Option 1', value: 'option1' }]), | ||
hasValue: true, | ||
isMulti: true, | ||
isRtl: false, | ||
options: [], | ||
selectProps: expect.any(Object), | ||
setValue: jest.fn(), | ||
theme: expect.any(Object), | ||
onOptionChanged: jest.fn(), | ||
showInputOption: false, | ||
setShowInputOption: jest.fn(), | ||
inputValue: '1111', | ||
setInputValue: jest.fn(), | ||
setMenuIsOpen: jest.fn(), | ||
}; | ||
|
||
it('should render CustomOption', () => { | ||
const { container }: RenderResult = render(<CustomOption {...mockProps} />); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
...omponents/dynamic-chart/components/custom-option/__snapshots__/CustomOption.test.tsx.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CustomOption should render CustomOption 1`] = ` | ||
<div | ||
aria-disabled="false" | ||
class="css-0" | ||
> | ||
<img | ||
alt="option1" | ||
class="icon" | ||
src="bar.svg" | ||
/> | ||
<span> | ||
Option1 | ||
</span> | ||
</div> | ||
`; |
29 changes: 29 additions & 0 deletions
29
.../components/dynamic-chart/components/custom-value-container/CustomValueContainer.test.tsx
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,29 @@ | ||
import { render, RenderResult } from '@testing-library/react'; | ||
import { CustomValueContainer } from './CustomValueContainer'; | ||
import { GroupBase, SetValueAction, ValueContainerProps } from 'react-select'; | ||
import { AttSelectOption } from '../../../../../../../../../../shared/components/att-select'; | ||
|
||
describe('CustomValueContainer', () => { | ||
const mockProps: ValueContainerProps<AttSelectOption<any>, boolean, GroupBase<AttSelectOption<any>>> = { | ||
children: undefined, | ||
isDisabled: false, | ||
clearValue: jest.fn(), | ||
cx: jest.fn(), | ||
getStyles: jest.fn(), | ||
getClassNames: jest.fn(), | ||
getValue: jest.fn(), | ||
hasValue: false, | ||
isMulti: false, | ||
isRtl: false, | ||
options: [], | ||
selectOption: jest.fn(), | ||
selectProps: undefined as any, | ||
setValue: jest.fn(), | ||
theme: undefined as any | ||
}; | ||
|
||
it('should render CustomValueContainer', () => { | ||
const { container }: RenderResult = render(<CustomValueContainer {...mockProps} />); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
...-chart/components/custom-value-container/__snapshots__/CustomValueContainer.test.tsx.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CustomValueContainer should render CustomValueContainer 1`] = ` | ||
<div> | ||
<div | ||
class="css-0" | ||
> | ||
<div | ||
class="input_wrapper" | ||
> | ||
<span | ||
class="placeholder" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
13 changes: 13 additions & 0 deletions
13
...s/experiment/components/charts/components/dynamic-chart/hooks/useDynamicChartData.test.ts
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,13 @@ | ||
import { act, renderHook } from "@testing-library/react"; | ||
import { useDynamicChartData } from "./useDynamicChartData"; | ||
import { MOCK_DATA_FOR_EXPERIMENT } from "../../../../__mocks__/mocks"; | ||
|
||
describe('useDynamicChartData', () => { | ||
test('should get data', async () => { | ||
|
||
const { result } = renderHook(() => useDynamicChartData(MOCK_DATA_FOR_EXPERIMENT)); | ||
act(() => { | ||
expect(result.current).toEqual( {yAxiosOptions: [{label: "averageCPU", value: "averageCPU"}, {label: "averageMemory", value: "averageMemory"}]}); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
...s/experiment/components/charts/components/dynamic-chart/utils/dynamic-chart.utils.test.ts
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,19 @@ | ||
import { ChartType } from '../models/dynamic-chart.interface'; | ||
import { capitalizeFirstLetter, getIconByValue, getTitleByXAxiosValue } from './dynamic-chart.utils'; | ||
import LineSvg from '../../../../../../../../../../../src/assets/images/line.svg'; | ||
import BarSvg from '../../../../../../../../../../../src/assets/images/bar.svg'; | ||
|
||
describe('Dynamic chart util test', () => { | ||
test('should get icon by value', () => { | ||
expect(getIconByValue(ChartType.LINE)).toBe(LineSvg); | ||
expect(getIconByValue(ChartType.BAR)).toBe(BarSvg); | ||
}); | ||
|
||
test('should capitalize first letter', () => { | ||
expect(capitalizeFirstLetter('test')).toBe('Test'); | ||
}); | ||
|
||
test('should get title by XAxios value', () => { | ||
expect(getTitleByXAxiosValue('NUMBER_OF_ITERATIONS')).toBe('Iterations'); | ||
}); | ||
}); |
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,30 @@ | ||
import { act, cleanup, fireEvent, render } from '@testing-library/react'; | ||
import { MutableRefObject, useRef } from 'react'; | ||
import { useOutsideClick } from './useOutsideClick'; | ||
|
||
interface TestComponentProps { | ||
onClickOutside: () => void | ||
} | ||
|
||
describe('useOutsideClick', () => { | ||
let TestComponent: React.FC<TestComponentProps>; | ||
|
||
beforeEach(() => { | ||
TestComponent = function Component({ onClickOutside }: TestComponentProps) { | ||
const innerElementRef: MutableRefObject<HTMLDivElement | null> = useRef<HTMLDivElement | null>(null); | ||
useOutsideClick(innerElementRef, onClickOutside); | ||
return <div ref={innerElementRef} data-testid='inside'>Test Component</div>; | ||
}; | ||
}); | ||
afterEach(cleanup); | ||
|
||
test('should not trigger event when inside element is clicked', () => { | ||
const onClickOutside: jest.Mock = jest.fn(); | ||
const { getByTestId } = render(<TestComponent onClickOutside={onClickOutside} />); | ||
const insideElement: HTMLElement = getByTestId('inside'); | ||
act(() => { | ||
fireEvent.mouseDown(insideElement); | ||
}); | ||
expect(onClickOutside).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |