diff --git a/packages/api-explorer/__tests__/AuthBox.test.jsx b/packages/api-explorer/__tests__/AuthBox.test.jsx index afe539023..979a27212 100644 --- a/packages/api-explorer/__tests__/AuthBox.test.jsx +++ b/packages/api-explorer/__tests__/AuthBox.test.jsx @@ -97,10 +97,8 @@ test("should work for Basic (Basic has it's own state)", () => { basic.inputChange('user', 'user'); basic.inputChange('password', 'password'); - // TODO this should be removed. See comment above componentDidMount in Basic - expect(onChange.mock.calls[0][0]).toEqual({ auth: { basic: { user: '', password: '' } } }); - expect(onChange.mock.calls[1][0]).toEqual({ auth: { basic: { user: 'user', password: '' } } }); - expect(onChange.mock.calls[2][0]).toEqual({ + expect(onChange.mock.calls[0][0]).toEqual({ auth: { basic: { user: 'user', password: '' } } }); + expect(onChange.mock.calls[1][0]).toEqual({ auth: { basic: { user: 'user', password: 'password' } }, }); }); diff --git a/packages/api-explorer/__tests__/SecurityInput.test.jsx b/packages/api-explorer/__tests__/SecurityInput.test.jsx index 666928187..c880a65a2 100644 --- a/packages/api-explorer/__tests__/SecurityInput.test.jsx +++ b/packages/api-explorer/__tests__/SecurityInput.test.jsx @@ -121,16 +121,7 @@ describe('basic', () => { securityInput.find('input[name="password"]').instance().value = 'pass'; securityInput.find('input[name="password"]').simulate('change'); - // TODO this should eventually be removed - // see comment above componentDidMount in Basic.jsx - expect(onChange.mock.calls[0][0]).toEqual({ - 'test-basic': { - user: '', - password: '', - }, - }); - - expect(onChange.mock.calls[2][0]).toEqual({ + expect(onChange.mock.calls[1][0]).toEqual({ 'test-basic': { user: 'user', password: 'pass', diff --git a/packages/api-explorer/src/security-input-types/Basic.jsx b/packages/api-explorer/src/security-input-types/Basic.jsx index 95aecda94..c503b1b8a 100644 --- a/packages/api-explorer/src/security-input-types/Basic.jsx +++ b/packages/api-explorer/src/security-input-types/Basic.jsx @@ -7,21 +7,7 @@ class Basic extends React.Component { this.state = { user: props.user || '', password: props.pass || '' }; this.inputChange = this.inputChange.bind(this); } - // TODO refactor this - // This is not ideal... we're having to update the state - // here so that the code sample updates with the base64 - // encoded user/pass on first render. This is a sign of - // bad prop passing somewhere and is quite un-reacty. - // Maybe we should be calling getAuth from the top level - // so the value is correct on the first pass through to - // the CodeSample component. Let me mull this over a little more. - // - // This also has the unfortunate side-effect of making the "Try It" - // button in the explorer turn active by default, as though an edit - // has been made - componentDidMount() { - this.props.change({ user: this.state.user, password: this.state.password }); - } + componentDidUpdate(prevProps, prevState) { // Without this if block the code spirals into an infinite loop if (prevState.user !== this.state.user || prevState.password !== this.state.password)