Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Remove hacky fix and tests for Basic auth change
Browse files Browse the repository at this point in the history
  • Loading branch information
domharrington committed Jan 25, 2019
1 parent 8521284 commit 8e6ddbd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
6 changes: 2 additions & 4 deletions packages/api-explorer/__tests__/AuthBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
});
});
11 changes: 1 addition & 10 deletions packages/api-explorer/__tests__/SecurityInput.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 1 addition & 15 deletions packages/api-explorer/src/security-input-types/Basic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8e6ddbd

Please sign in to comment.