-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
8b1e8e2
commit 75c0fd8
Showing
11 changed files
with
241 additions
and
11 deletions.
There are no files selected for viewing
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,26 @@ | ||
// @flow | ||
/* global SETTINGS: false */ | ||
import React from 'react'; | ||
|
||
import ProfileFormFields from '../util/ProfileFormFields'; | ||
import type { Profile } from '../flow/profileTypes'; | ||
import type { UIState } from '../reducers/ui'; | ||
|
||
class PrivacyForm extends ProfileFormFields { | ||
props: { | ||
profile: Profile, | ||
ui: UIState, | ||
updateProfile: Function, | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h4 className="privacy-form-heading">Who can see your profile?</h4> | ||
{ this.boundRadioGroupField(['account_privacy'], '', this.privacyOptions) } | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default PrivacyForm; |
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
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
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,96 @@ | ||
// @flow | ||
/* global SETTINGS: false */ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import Loader from 'react-loader'; | ||
import Grid, { Cell } from 'react-mdl/lib/Grid'; | ||
|
||
import Jumbotron from '../components/Jumbotron'; | ||
import { | ||
startProfileEdit, | ||
FETCH_PROCESSING, | ||
} from '../actions/index'; | ||
import ProfileFormContainer from './ProfileFormContainer'; | ||
import PrivacyForm from '../components/PrivacyForm'; | ||
import ProfileProgressControls from '../components/ProfileProgressControls'; | ||
import { | ||
combineValidators, | ||
privacyValidation, | ||
} from '../util/validation'; | ||
import { getPreferredName } from '../util/util'; | ||
import type { Profile } from '../flow/profileTypes'; | ||
import type { UIState } from '../reducers/ui'; | ||
|
||
class SettingsPage extends ProfileFormContainer { | ||
props: { | ||
profiles: {[key: string]: Profile}, | ||
dispatch: Function, | ||
ui: UIState, | ||
}; | ||
|
||
componentWillMount() { | ||
this.startSettingsEdit(); | ||
} | ||
|
||
startSettingsEdit() { | ||
const { dispatch } = this.props; | ||
dispatch(startProfileEdit(SETTINGS.username)); | ||
} | ||
|
||
render() { | ||
const { profiles, ui } = this.props; | ||
let profile; | ||
let errors; | ||
let isEdit = true; | ||
let loaded = false; | ||
let username = SETTINGS.username; | ||
let preferredName = SETTINGS.name; | ||
|
||
if (profiles[username] !== undefined) { | ||
let profileFromStore = profiles[username]; | ||
loaded = profileFromStore.getStatus !== FETCH_PROCESSING; | ||
if (profileFromStore.edit !== undefined) { | ||
errors = profileFromStore.edit.errors; | ||
profile = profileFromStore.edit.profile; | ||
} else { | ||
profile = profileFromStore.profile; | ||
errors = {}; | ||
isEdit = false; | ||
} | ||
preferredName = getPreferredName(profile); | ||
} | ||
|
||
return ( | ||
<Loader loaded={loaded}> | ||
<Jumbotron profile={profile} text={preferredName}> | ||
<div className="card-copy"> | ||
<Grid className="profile-tab-grid privacy-form"> | ||
<Cell col={12}> | ||
<PrivacyForm | ||
{...this.props} | ||
errors={errors} | ||
profile={profile} | ||
updateProfile={this.updateProfile.bind(this, isEdit)} | ||
/> | ||
</Cell> | ||
<Cell col={12}> | ||
<ProfileProgressControls | ||
nextUrl="/dashboard" | ||
isLastTab={true} | ||
saveProfile={this.saveProfile.bind(this, isEdit)} | ||
profile={profile} | ||
ui={ui} | ||
validator={ | ||
combineValidators(privacyValidation) | ||
} | ||
/> | ||
</Cell> | ||
</Grid> | ||
</div> | ||
</Jumbotron> | ||
</Loader> | ||
); | ||
} | ||
} | ||
|
||
export default connect(ProfileFormContainer.mapStateToProps)(SettingsPage); |
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,96 @@ | ||
/* global SETTINGS: false */ | ||
import '../global_init'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import { assert } from 'chai'; | ||
|
||
import { | ||
START_PROFILE_EDIT, | ||
UPDATE_PROFILE_VALIDATION, | ||
REQUEST_PATCH_USER_PROFILE, | ||
RECEIVE_PATCH_USER_PROFILE_SUCCESS, | ||
CLEAR_PROFILE_EDIT, | ||
|
||
receiveGetUserProfileSuccess | ||
} from '../actions'; | ||
import IntegrationTestHelper from '../util/integration_test_helper'; | ||
import * as api from '../util/api'; | ||
import { USER_PROFILE_RESPONSE } from '../constants'; | ||
|
||
describe("SettingsPage", function() { | ||
this.timeout(5000); | ||
let nextButtonSelector = '.progress-button.next'; | ||
let listenForActions, renderComponent, helper, patchUserProfileStub; | ||
let userActions = [START_PROFILE_EDIT]; | ||
|
||
describe ("Settings page tests", () => { | ||
beforeEach(() => { | ||
helper = new IntegrationTestHelper(); | ||
listenForActions = helper.listenForActions.bind(helper); | ||
renderComponent = helper.renderComponent.bind(helper); | ||
patchUserProfileStub = helper.sandbox.stub(api, 'patchUserProfile'); | ||
|
||
helper.profileGetStub. | ||
withArgs(SETTINGS.username). | ||
returns( | ||
Promise.resolve(Object.assign({}, USER_PROFILE_RESPONSE, { | ||
username: SETTINGS.username | ||
})) | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
helper.cleanup(); | ||
}); | ||
|
||
let confirmSaveButtonBehavior = (updatedProfile, pageElements, validationFailure=false) => { | ||
let { div, button } = pageElements; | ||
button = button || div.querySelector(nextButtonSelector); | ||
patchUserProfileStub.throws("Invalid arguments"); | ||
patchUserProfileStub.withArgs(SETTINGS.username, updatedProfile).returns(Promise.resolve(updatedProfile)); | ||
|
||
let actions = []; | ||
if (!validationFailure) { | ||
actions.push( | ||
REQUEST_PATCH_USER_PROFILE, | ||
RECEIVE_PATCH_USER_PROFILE_SUCCESS, | ||
START_PROFILE_EDIT, | ||
CLEAR_PROFILE_EDIT | ||
); | ||
} | ||
actions.push( | ||
UPDATE_PROFILE_VALIDATION | ||
); | ||
return listenForActions(actions, () => { | ||
TestUtils.Simulate.click(button); | ||
}); | ||
}; | ||
|
||
it('shows the privacy form', () => { | ||
return renderComponent("/settings", userActions).then(([, div]) => { | ||
let question = div.getElementsByClassName('privacy-form-heading')[0]; | ||
assert.equal(question.textContent, 'Who can see your profile?'); | ||
}); | ||
}); | ||
|
||
describe('save privacy form', () => { | ||
it('save privacy changes', () => { | ||
return renderComponent("/settings", userActions).then(([, div]) => { | ||
let button = div.querySelector(nextButtonSelector); | ||
let receivedProfile = Object.assign({}, USER_PROFILE_RESPONSE, { | ||
account_privacy: 'public' | ||
}); | ||
|
||
helper.store.dispatch(receiveGetUserProfileSuccess(SETTINGS.username, receivedProfile)); | ||
|
||
assert(button.innerHTML.includes("I'm Done!")); | ||
let updatedProfile = Object.assign({}, receivedProfile, { | ||
email_optin: true, | ||
filled_out: true | ||
}); | ||
|
||
return confirmSaveButtonBehavior(updatedProfile, {button: button}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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