-
Notifications
You must be signed in to change notification settings - Fork 179
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
fix(app): properly enable/disable robot update from file button #6483
Changes from 2 commits
011a35b
b421743
544a8ff
65b3d19
18c7fe7
95ad791
3fed4cd
9492dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import * as selectors from '../selectors' | ||
import { mockReachableRobot } from '../../discovery/__fixtures__' | ||
import { | ||
HEALTH_STATUS_NOT_OK, | ||
getViewableRobots, | ||
getRobotApiVersion, | ||
} from '../../discovery/selectors' | ||
getRobotApiVersionByName, | ||
getRobotByName, | ||
} from '../../discovery' | ||
|
||
jest.mock('../../discovery/selectors') | ||
|
||
describe('buildroot selectors', () => { | ||
beforeEach(() => { | ||
getViewableRobots.mockReturnValue([]) | ||
getRobotApiVersionByName.mockReturnValue(null) | ||
getRobotByName.mockReturnValue(null) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.resetAllMocks() | ||
}) | ||
|
||
const SPECS = [ | ||
|
@@ -81,10 +90,10 @@ describe('buildroot selectors', () => { | |
version: '1.0.0', | ||
}, | ||
}, | ||
args: [{ name: 'robot-name' }], | ||
args: ['robot-name'], | ||
expected: 'upgrade', | ||
setup: () => { | ||
getRobotApiVersion.mockReturnValueOnce('0.9.9') | ||
getRobotApiVersionByName.mockReturnValue('0.9.9') | ||
}, | ||
}, | ||
{ | ||
|
@@ -98,7 +107,7 @@ describe('buildroot selectors', () => { | |
args: [{ name: 'robot-name' }], | ||
expected: 'downgrade', | ||
setup: () => { | ||
getRobotApiVersion.mockReturnValueOnce('1.0.1') | ||
getRobotApiVersionByName.mockReturnValue('1.0.1') | ||
}, | ||
}, | ||
{ | ||
|
@@ -112,7 +121,7 @@ describe('buildroot selectors', () => { | |
args: [{ name: 'robot-name' }], | ||
expected: 'reinstall', | ||
setup: () => { | ||
getRobotApiVersion.mockReturnValueOnce('1.0.0') | ||
getRobotApiVersionByName.mockReturnValue('1.0.0') | ||
}, | ||
}, | ||
{ | ||
|
@@ -126,7 +135,7 @@ describe('buildroot selectors', () => { | |
args: [{ name: 'robot-name' }], | ||
expected: null, | ||
setup: () => { | ||
getRobotApiVersion.mockReturnValueOnce('1.0.0') | ||
getRobotApiVersionByName.mockReturnValue('1.0.0') | ||
}, | ||
}, | ||
{ | ||
|
@@ -159,7 +168,7 @@ describe('buildroot selectors', () => { | |
}, | ||
expected: { name: 'robot-name', host: '10.10.0.0', port: 31950 }, | ||
setup: () => | ||
getViewableRobots.mockReturnValueOnce([ | ||
getViewableRobots.mockReturnValue([ | ||
{ name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, | ||
{ name: 'robot-name', host: '10.10.0.0', port: 31950 }, | ||
{ name: 'another-robot-name', host: '10.10.0.2', port: 31950 }, | ||
|
@@ -180,7 +189,7 @@ describe('buildroot selectors', () => { | |
serverHealth: { capabilities: { buildrootUpdate: '/' } }, | ||
}, | ||
setup: () => | ||
getViewableRobots.mockReturnValueOnce([ | ||
getViewableRobots.mockReturnValue([ | ||
{ name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, | ||
{ | ||
name: 'robot-name', | ||
|
@@ -191,12 +200,104 @@ describe('buildroot selectors', () => { | |
{ name: 'another-robot-name', host: '10.10.0.2', port: 31950 }, | ||
]), | ||
}, | ||
{ | ||
name: 'getBuildrootUpdateDisplayInfo returns not responding if no robot', | ||
selector: selectors.getBuildrootUpdateDisplayInfo, | ||
state: { buildroot: {} }, | ||
setup: () => { | ||
getRobotByName.mockReturnValue(null) | ||
}, | ||
expected: expect.objectContaining({ | ||
autoUpdateDisabledReason: expect.stringMatching( | ||
/update server is not responding/ | ||
), | ||
updateFromFileDisabledReason: expect.stringMatching( | ||
/update server is not responding/ | ||
), | ||
}), | ||
}, | ||
{ | ||
name: | ||
'getBuildrootUpdateDisplayInfo returns not responding if robot has unhealthy update server', | ||
selector: selectors.getBuildrootUpdateDisplayInfo, | ||
state: { buildroot: {} }, | ||
setup: () => { | ||
getRobotByName.mockReturnValue({ | ||
...mockReachableRobot, | ||
serverHealthStatus: HEALTH_STATUS_NOT_OK, | ||
}) | ||
}, | ||
expected: expect.objectContaining({ | ||
autoUpdateDisabledReason: expect.stringMatching( | ||
/update server is not responding/ | ||
), | ||
updateFromFileDisabledReason: expect.stringMatching( | ||
/update server is not responding/ | ||
), | ||
}), | ||
}, | ||
{ | ||
name: | ||
'getBuildrootUpdateDisplayInfo returns not allowed if another robot is updating', | ||
selector: selectors.getBuildrootUpdateDisplayInfo, | ||
state: { buildroot: { session: { robotName: 'other-robot-name' } } }, | ||
setup: () => { | ||
getRobotByName.mockImplementation((state, name) => { | ||
return { ...mockReachableRobot, name } | ||
}) | ||
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. Why would we overwrite the Wouldn't we want to always just return the name of getRobotByName.mockReturnValueOnce(mockReachableRobot) 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. Oops, test was bad. Good catch! |
||
getViewableRobots.mockReturnValue([ | ||
{ name: 'other-robot-name', host: '10.10.0.1', port: 31950 }, | ||
]) | ||
}, | ||
expected: expect.objectContaining({ | ||
autoUpdateDisabledReason: expect.stringMatching( | ||
/updating a different robot/ | ||
), | ||
updateFromFileDisabledReason: expect.stringMatching( | ||
/updating a different robot/ | ||
), | ||
}), | ||
}, | ||
{ | ||
name: | ||
'getBuildrootUpdateDisplayInfo returns allowed only from file if no auto files', | ||
selector: selectors.getBuildrootUpdateDisplayInfo, | ||
state: { buildroot: {} }, | ||
setup: () => { | ||
getRobotByName.mockReturnValue(mockReachableRobot) | ||
}, | ||
expected: { | ||
autoUpdateAction: expect.stringMatching(/unavailable/i), | ||
autoUpdateDisabledReason: expect.stringMatching( | ||
/no update files found/i | ||
), | ||
updateFromFileDisabledReason: null, | ||
}, | ||
}, | ||
{ | ||
name: | ||
'getBuildrootUpdateDisplayInfo returns allowed with action if all good', | ||
selector: selectors.getBuildrootUpdateDisplayInfo, | ||
state: { buildroot: { version: '1.0.0' } }, | ||
setup: () => { | ||
getRobotByName.mockReturnValue(mockReachableRobot) | ||
getRobotApiVersionByName.mockReturnValue('0.9.9') | ||
}, | ||
expected: { | ||
autoUpdateAction: expect.stringMatching(/upgrade/i), | ||
autoUpdateDisabledReason: null, | ||
updateFromFileDisabledReason: null, | ||
}, | ||
}, | ||
] | ||
|
||
SPECS.forEach(spec => { | ||
const { name, selector, state, expected, setup } = spec | ||
const args = spec.args || [] | ||
if (typeof setup === 'function') setup() | ||
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. Fun fact: mock setup wasn't working at all in these tests... 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. 🙃 |
||
it(name, () => expect(selector(state, ...args)).toEqual(expected)) | ||
|
||
it(name, () => { | ||
if (typeof setup === 'function') setup() | ||
expect(selector(state, ...args)).toEqual(expected) | ||
}) | ||
}) | ||
}) |
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.
how come you switched
mockReturnValueOnce
tomockReturnValue
?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.
I think
mockReturnValue
is more accurate to how the selectors would actually behave; a selector (if it chose to) might call some selector it is dependent on multiple times with the same input, and you would expect the same output.These tests weren't very well written (by me) with respect to mocks, so I've refactored to be more clear