Skip to content

Commit cf7b763

Browse files
author
timmydoza
authored
Rename region (#22)
* Change most instances of region to edge * Fix tests * Change more instances to edge * Add missing tests
1 parent 6c9f766 commit cf7b763

19 files changed

+167
-155
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3-
import RegionResult from './RegionResult';
3+
import EdgeResult from './EdgeResult';
44
import ProgressBar from '../ProgressBar/ProgressBar';
55
import { Tooltip } from '@material-ui/core';
66

@@ -13,37 +13,37 @@ const testResult: any = {
1313
results: { preflight: { warnings: [], samples: [{ bytesReceived: 1000 }] } },
1414
} as any;
1515

16-
describe('the RegionResult component', () => {
16+
describe('the EdgeResult component', () => {
1717
describe('child ProgressBar component', () => {
1818
it('should have the correct props with no active test', () => {
19-
const wrapper = mount(<RegionResult region="ashburn" isActive={true} />);
19+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={true} />);
2020
expect(wrapper.find(ProgressBar).props()).toEqual({ duration: 0, position: 0 });
2121
});
2222

2323
it('should have the correct props when the active test is Preflight', () => {
24-
const wrapper = mount(<RegionResult region="ashburn" isActive={true} activeTest="Preflight Test" />);
24+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={true} activeTest="Preflight Test" />);
2525
expect(wrapper.find(ProgressBar).props()).toEqual({ duration: 25, position: 62.5 });
2626
});
2727

2828
it('should have the correct props when the active test is Bitrate', () => {
29-
const wrapper = mount(<RegionResult region="ashburn" isActive={true} activeTest="Bitrate Test" />);
29+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={true} activeTest="Bitrate Test" />);
3030
expect(wrapper.find(ProgressBar).props()).toEqual({ duration: 15, position: 100 });
3131
});
3232
});
3333

3434
it('should not render a Tooltip or Progress bar when it is not active and there are no results', () => {
35-
const wrapper = mount(<RegionResult region="ashburn" isActive={false} />);
35+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={false} />);
3636
expect(wrapper.find(ProgressBar).exists()).toBe(false);
3737
expect(wrapper.find(Tooltip).exists()).toBe(false);
3838
});
3939

4040
it('should render a Tooltip when results are present', () => {
41-
const wrapper = mount(<RegionResult region="ashburn" isActive={false} result={testResult} />);
41+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={false} result={testResult} />);
4242
expect(wrapper.find(Tooltip).exists()).toBe(true);
4343
});
4444

4545
it('should render a CheckIcon when the results have no warnings or errors', () => {
46-
const wrapper = mount(<RegionResult region="ashburn" isActive={false} result={testResult} />);
46+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={false} result={testResult} />);
4747
expect(wrapper.find(CheckIcon).exists()).toBe(true);
4848
});
4949

@@ -52,7 +52,7 @@ describe('the RegionResult component', () => {
5252
errors: {},
5353
results: { preflight: { warnings: [{ name: 'high-rtt' }], samples: [{ bytesReceived: 1000 }] } },
5454
} as any;
55-
const wrapper = mount(<RegionResult region="ashburn" isActive={false} result={testResult} />);
55+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={false} result={testResult} />);
5656
expect(wrapper.find(WarningIcon).exists()).toBe(true);
5757
});
5858

@@ -61,7 +61,7 @@ describe('the RegionResult component', () => {
6161
errors: { testError: 'error' },
6262
results: {},
6363
} as any;
64-
const wrapper = mount(<RegionResult region="ashburn" isActive={false} result={testResult} />);
64+
const wrapper = mount(<EdgeResult edge="ashburn" isActive={false} result={testResult} />);
6565
expect(wrapper.find(CloseIcon).exists()).toBe(true);
6666
});
6767
});

src/NetworkTestWidget/RegionResult/RegionResult.tsx renamed to src/NetworkTestWidget/EdgeResult/EdgeResult.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import CloseIcon from '@material-ui/icons/Close';
77
import CheckIcon from '@material-ui/icons/Check';
88
import WarningIcon from '@material-ui/icons/Warning';
99
import ProgressBar from '../ProgressBar/ProgressBar';
10-
import { regionNameMap } from '../../utils';
10+
import { edgeNameMap } from '../../utils';
1111

1212
import { BITRATE_TEST_DURATION } from '../Tests/Tests';
1313
import getTooltipContent from './getTooltipContent';
14-
import { NetworkTestName, Region, TestResults } from '../../types';
14+
import { NetworkTestName, Edge, TestResults } from '../../types';
1515

1616
import { rows } from '../../ResultWidget/rows';
1717

@@ -30,7 +30,7 @@ const useStyles = makeStyles({
3030
flex: 1,
3131
padding: '0 1em',
3232
},
33-
regionName: {
33+
edgeName: {
3434
width: '15%',
3535
},
3636
iconContainer: {
@@ -46,12 +46,13 @@ const useStyles = makeStyles({
4646
},
4747
});
4848

49-
interface RegionResultProps {
50-
region: Region;
49+
interface EdgeResultProps {
50+
edge: Edge;
5151
isActive: boolean;
5252
result?: TestResults;
5353
activeTest?: NetworkTestName;
5454
}
55+
5556
const progressBarTimings = {
5657
'Preflight Test': {
5758
position: 62.5,
@@ -63,8 +64,8 @@ const progressBarTimings = {
6364
},
6465
};
6566

66-
export default function RegionResult(props: RegionResultProps) {
67-
const { region, isActive, result, activeTest } = props;
67+
export default function EdgeResult(props: EdgeResultProps) {
68+
const { edge, isActive, result, activeTest } = props;
6869
const classes = useStyles();
6970

7071
const hasError = Object.values(result?.errors ?? {}).length > 0;
@@ -75,7 +76,7 @@ export default function RegionResult(props: RegionResultProps) {
7576

7677
return (
7778
<div className={clsx(classes.container, { [classes.pendingTest]: !isActive && !result })}>
78-
<Typography className={classes.regionName}>{regionNameMap[region]}</Typography>
79+
<Typography className={classes.edgeName}>{edgeNameMap[edge]}</Typography>
7980
<div className={classes.progressContainer}>
8081
{isActive && <ProgressBar position={progressPosition} duration={progressDuration} />}
8182
</div>

src/NetworkTestWidget/NetworkTestWidget.test.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Button } from '@material-ui/core';
33
import NetworkTestWidget from './NetworkTestWidget';
4-
import RegionResult from './RegionResult/RegionResult';
4+
import EdgeResult from './EdgeResult/EdgeResult';
55
import { shallow } from 'enzyme';
66
import useTestRunner from './useTestRunner/useTestRunner';
77

@@ -10,15 +10,15 @@ const mockUseTestRunner = useTestRunner as jest.Mock<any>;
1010

1111
jest.mock('../constants', () => ({
1212
DEFAULT_CODEC_PREFERENCES: ['opus'],
13-
DEFAULT_REGIONS: ['ashburn', 'dublin', 'roaming'],
13+
DEFAULT_EDGES: ['ashburn', 'dublin', 'roaming'],
1414
}));
1515

1616
describe('the NetworkTestWidget component', () => {
17-
it('should not render RegionResult components when there are no results', () => {
17+
it('should not render EdgeResult components when there are no results', () => {
1818
mockUseTestRunner.mockImplementation(() => ({
1919
isRunning: false,
2020
results: [],
21-
activeRegion: undefined,
21+
activeEdge: undefined,
2222
activeTest: undefined,
2323
runTests: jest.fn(),
2424
}));
@@ -31,15 +31,15 @@ describe('the NetworkTestWidget component', () => {
3131
/>
3232
);
3333

34-
expect(wrapper.find(RegionResult).exists()).toBe(false);
34+
expect(wrapper.find(EdgeResult).exists()).toBe(false);
3535
expect(wrapper.find(Button).find({ disabled: false }).length).toBe(2);
3636
});
3737

38-
it('should correctly render RegionResult components while tests are active', () => {
38+
it('should correctly render EdgeResult components while tests are active', () => {
3939
mockUseTestRunner.mockImplementation(() => ({
4040
isRunning: true,
4141
results: [],
42-
activeRegion: 'ashburn',
42+
activeEdge: 'ashburn',
4343
activeTest: 'bitrate',
4444
runTests: jest.fn(),
4545
}));
@@ -52,20 +52,20 @@ describe('the NetworkTestWidget component', () => {
5252
/>
5353
);
5454

55-
expect(wrapper.find(RegionResult).find({ region: 'ashburn' }).props()).toEqual({
55+
expect(wrapper.find(EdgeResult).find({ edge: 'ashburn' }).props()).toEqual({
5656
activeTest: 'bitrate',
5757
isActive: true,
58-
region: 'ashburn',
58+
edge: 'ashburn',
5959
result: undefined,
6060
});
6161
expect(wrapper.find(Button).find({ disabled: true }).length).toBe(2);
6262
});
6363

64-
it('should correctly render RegionResult components when there are results', () => {
64+
it('should correctly render EdgeResult components when there are results', () => {
6565
mockUseTestRunner.mockImplementation(() => ({
6666
isRunning: false,
6767
results: ['mockResults'],
68-
activeRegion: undefined,
68+
activeEdge: undefined,
6969
activeTest: undefined,
7070
runTests: jest.fn(),
7171
}));
@@ -78,10 +78,10 @@ describe('the NetworkTestWidget component', () => {
7878
/>
7979
);
8080

81-
expect(wrapper.find(RegionResult).at(0).props()).toEqual({
81+
expect(wrapper.find(EdgeResult).at(0).props()).toEqual({
8282
activeTest: undefined,
8383
isActive: false,
84-
region: 'ashburn',
84+
edge: 'ashburn',
8585
result: 'mockResults',
8686
});
8787
});
@@ -90,7 +90,7 @@ describe('the NetworkTestWidget component', () => {
9090
mockUseTestRunner.mockImplementation(() => ({
9191
isRunning: false,
9292
results: [],
93-
activeRegion: undefined,
93+
activeEdge: undefined,
9494
activeTest: undefined,
9595
runTests: jest.fn(() => Promise.resolve('mockResults')),
9696
}));

src/NetworkTestWidget/NetworkTestWidget.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState } from 'react';
22
import { Button, Typography } from '@material-ui/core';
33
import useTestRunner from './useTestRunner/useTestRunner';
4-
import RegionResult from './RegionResult/RegionResult';
4+
import EdgeResult from './EdgeResult/EdgeResult';
55
import SettingsModal from './SettingsModal/SettingsModal';
66
import SettingsIcon from '@material-ui/icons/Settings';
7-
import { DEFAULT_REGIONS, DEFAULT_CODEC_PREFERENCES } from '../constants';
7+
import { DEFAULT_EDGES, DEFAULT_CODEC_PREFERENCES } from '../constants';
88

99
interface NetworkTestWidgetProps {
1010
getTURNCredentials: () => Promise<RTCIceServer[]>;
@@ -15,17 +15,17 @@ interface NetworkTestWidgetProps {
1515
}
1616

1717
const initialSettings = {
18-
regions: DEFAULT_REGIONS,
18+
edges: DEFAULT_EDGES,
1919
codecPreferences: DEFAULT_CODEC_PREFERENCES,
2020
};
2121

2222
export default function NetworkTestWidget({ getTURNCredentials, getVoiceToken, onComplete }: NetworkTestWidgetProps) {
23-
const { isRunning, results, activeRegion, runTests, activeTest } = useTestRunner();
23+
const { isRunning, results, activeEdge, runTests, activeTest } = useTestRunner();
2424
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
2525
const [settings, setSettings] = useState(initialSettings);
2626

2727
async function startTest() {
28-
const testResults = await runTests(getVoiceToken, getTURNCredentials, settings.regions, settings.codecPreferences);
28+
const testResults = await runTests(getVoiceToken, getTURNCredentials, settings.edges, settings.codecPreferences);
2929
onComplete(testResults);
3030
}
3131

@@ -36,11 +36,11 @@ export default function NetworkTestWidget({ getTURNCredentials, getVoiceToken, o
3636
</Typography>
3737
{(isRunning || results.length > 0) && (
3838
<div>
39-
{settings.regions.map((region, i) => (
40-
<RegionResult
41-
key={region}
42-
region={region}
43-
isActive={activeRegion === region}
39+
{settings.edges.map((edge, i) => (
40+
<EdgeResult
41+
key={edge}
42+
edge={edge}
43+
isActive={activeEdge === edge}
4444
result={results[i]}
4545
activeTest={activeTest}
4646
/>

src/NetworkTestWidget/SettingsModal/SettingsModal.test.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@ import React from 'react';
22
import { Button } from '@material-ui/core';
33
import { Connection } from 'twilio-client';
44
import { mount, ReactWrapper } from 'enzyme';
5-
import { Region } from '../../types';
5+
import { Edge } from '../../types';
66
import SettingsModal from './SettingsModal';
77

88
jest.mock('../../constants', () => ({
99
DEFAULT_CODEC_PREFERENCES: ['opus'],
10-
DEFAULT_REGIONS: ['ashburn', 'dublin', 'roaming'],
10+
DEFAULT_EDGES: ['ashburn', 'dublin', 'roaming'],
1111
}));
1212

1313
const { PCMU, Opus } = Connection.Codec;
1414

15-
const changeCheckbox = (wrapper: ReactWrapper, region: Region, checked: boolean) =>
15+
const changeCheckbox = (wrapper: ReactWrapper, edge: Edge, checked: boolean) =>
1616
wrapper
1717
.find('input')
18-
.find({ name: region, type: 'checkbox' })
19-
.simulate('change', { target: { checked, name: region } });
18+
.find({ name: edge, type: 'checkbox' })
19+
.simulate('change', { target: { checked, name: edge } });
2020

2121
describe('the SettingsModal component', () => {
2222
const handleSettingsChange = jest.fn();
2323
beforeEach(jest.clearAllMocks);
2424

25-
it('should remove regions', () => {
25+
it('should remove edges', () => {
2626
const wrapper = mount(<SettingsModal isOpen={true} onSettingsChange={handleSettingsChange} />);
2727
changeCheckbox(wrapper, 'ashburn', false);
2828
wrapper.find(Button).simulate('click');
2929
expect(handleSettingsChange).toHaveBeenCalledWith({
3030
codecPreferences: [Opus],
31-
regions: ['dublin', 'roaming'],
31+
edges: ['dublin', 'roaming'],
3232
});
3333
});
3434

35-
it('should add regions', () => {
35+
it('should add edges', () => {
3636
const wrapper = mount(<SettingsModal isOpen={true} onSettingsChange={handleSettingsChange} />);
3737
changeCheckbox(wrapper, 'tokyo', true);
3838
wrapper.find(Button).simulate('click');
3939
expect(handleSettingsChange).toHaveBeenCalledWith({
4040
codecPreferences: [Opus],
41-
regions: ['ashburn', 'dublin', 'roaming', 'tokyo'],
41+
edges: ['ashburn', 'dublin', 'roaming', 'tokyo'],
4242
});
4343
});
4444

45-
it('should not add more than six regions', () => {
45+
it('should not add more than six edges', () => {
4646
const wrapper = mount(<SettingsModal isOpen={true} onSettingsChange={handleSettingsChange} />);
4747
changeCheckbox(wrapper, 'tokyo', true);
4848
changeCheckbox(wrapper, 'frankfurt-ix', true);
@@ -52,19 +52,19 @@ describe('the SettingsModal component', () => {
5252
wrapper.find(Button).simulate('click');
5353
expect(handleSettingsChange).toHaveBeenCalledWith({
5454
codecPreferences: [Opus],
55-
regions: ['ashburn', 'dublin', 'roaming', 'sydney', 'tokyo', 'frankfurt-ix'],
55+
edges: ['ashburn', 'dublin', 'roaming', 'sydney', 'tokyo', 'frankfurt-ix'],
5656
});
5757
});
5858

59-
it('should not remove the last region', () => {
59+
it('should not remove the last edge', () => {
6060
const wrapper = mount(<SettingsModal isOpen={true} onSettingsChange={handleSettingsChange} />);
6161
changeCheckbox(wrapper, 'ashburn', false);
6262
changeCheckbox(wrapper, 'roaming', false);
6363
changeCheckbox(wrapper, 'dublin', false); // ignored
6464
wrapper.find(Button).simulate('click');
6565
expect(handleSettingsChange).toHaveBeenCalledWith({
6666
codecPreferences: [Opus],
67-
regions: ['dublin'],
67+
edges: ['dublin'],
6868
});
6969
});
7070

@@ -77,7 +77,7 @@ describe('the SettingsModal component', () => {
7777
wrapper.find(Button).simulate('click');
7878
expect(handleSettingsChange).toHaveBeenCalledWith({
7979
codecPreferences: [PCMU, Opus],
80-
regions: ['ashburn', 'dublin', 'roaming'],
80+
edges: ['ashburn', 'dublin', 'roaming'],
8181
});
8282
});
8383

@@ -90,7 +90,7 @@ describe('the SettingsModal component', () => {
9090
wrapper.find(Button).simulate('click');
9191
expect(handleSettingsChange).toHaveBeenCalledWith({
9292
codecPreferences: [PCMU, Opus],
93-
regions: ['ashburn', 'dublin', 'roaming'],
93+
edges: ['ashburn', 'dublin', 'roaming'],
9494
});
9595
});
9696
});

0 commit comments

Comments
 (0)