Skip to content

Commit

Permalink
feat(account-settings): username view (#1752)
Browse files Browse the repository at this point in the history
* Move Account page to separate dir

* Add account snapshot tests

* Allow console logs in tests

* Add data-test attribute to Input

* Add username to Settings component
  • Loading branch information
121watts authored Dec 5, 2018
1 parent 8e6d785 commit f450000
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"build": "parcel build -d build --no-source-maps --log-level 2 src/index.html",
"clean": "rm -rf ./build && rm -rf ./.cache && rm -rf node_modules",
"test": "jest --maxWorkers=2",
"test:watch": "jest --watch",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
"test:watch": "jest --watch --verbose false",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --watch --verbose false",
"lint": "npm run tslint && npm run tsc",
"tslint": "tslint -c ./tslint.json '{src,test}/**/*.ts?(x)'",
"tslint:fix": "tslint --fix -c ./tslint.json '{src,test}/**/*.ts?(x)'",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/clockface/components/inputs/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface Props {
customClass?: string
maxLength?: number
tabIndex?: number
dataTest?: string
}

class Input extends Component<Props> {
Expand Down Expand Up @@ -82,6 +83,7 @@ class Input extends Component<Props> {
maxLength,
autocomplete,
tabIndex,
dataTest,
} = this.props

return (
Expand All @@ -107,6 +109,7 @@ class Input extends Component<Props> {
disabled={status === ComponentStatus.Disabled}
maxLength={maxLength}
tabIndex={tabIndex}
data-test={dataTest}
/>
{this.icon}
{this.statusIndicator}
Expand Down
28 changes: 28 additions & 0 deletions ui/src/me/components/account/Account.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Libraries
import React from 'react'
import {shallow} from 'enzyme'

// Components
import Account from 'src/me/components/account/Account'

const setup = (override?) => {
const props = {
params: {tab: 'settings'},
...override,
}

const wrapper = shallow(<Account {...props} />)

return {wrapper}
}

describe('Account', () => {
describe('rendering', () => {
it('renders!', () => {
const {wrapper} = setup()

expect(wrapper.exists()).toBe(true)
expect(wrapper).toMatchSnapshot()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {WithRouterProps} from 'react-router'
import {Page} from 'src/pageLayout'
import ProfilePage from 'src/shared/components/profile_page/ProfilePage'
import ProfilePageSection from 'src/shared/components/profile_page/ProfilePageSection'
import Settings from 'src/me/components/account/Settings'

export default class Account extends PureComponent<WithRouterProps> {
public render() {
Expand All @@ -14,7 +15,7 @@ export default class Account extends PureComponent<WithRouterProps> {
<Page>
<Page.Header fullWidth={false}>
<Page.Header.Left>
<Page.Title title="Your name here" />
<Page.Title title="My Account" />
</Page.Header.Left>
<Page.Header.Right />
</Page.Header>
Expand All @@ -25,7 +26,7 @@ export default class Account extends PureComponent<WithRouterProps> {
parentUrl="/account"
>
<ProfilePageSection id="settings" title="Settings" url="settings">
<div>Settings go here</div>
<Settings />
</ProfilePageSection>
<ProfilePageSection id="tokens" title="Tokens" url="tokens">
<div>Tokens go here</div>
Expand Down
36 changes: 36 additions & 0 deletions ui/src/me/components/account/Settings.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Libraries
import React from 'react'
import {mount} from 'enzyme'

// Components
import {Settings} from 'src/me/components/account/Settings'
import {me} from '../../mockUserData'

const setup = (override?) => {
const props = {
me,
...override,
}

const wrapper = mount(<Settings {...props} />)

return {wrapper}
}

describe('Account', () => {
describe('rendering', () => {
it('renders!', () => {
const {wrapper} = setup()

expect(wrapper.exists()).toBe(true)
expect(wrapper).toMatchSnapshot()
})

it('displays the users info by default', () => {
const {wrapper} = setup()

const nameInput = wrapper.find({'data-test': 'nameInput'})
expect(nameInput.props().value).toBe(me.name)
})
})
})
68 changes: 68 additions & 0 deletions ui/src/me/components/account/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Libraries
import React, {PureComponent, ChangeEvent} from 'react'
import {connect} from 'react-redux'

// Types
import {MeState} from 'src/types/v2'
import {
Form,
Button,
Input,
Columns,
ComponentSize,
ComponentStatus,
Panel,
} from 'src/clockface'

interface StateProps {
me: MeState
}

interface State {
me: MeState
}

export class Settings extends PureComponent<StateProps, State> {
constructor(props) {
super(props)
this.state = {
me: this.props.me,
}
}

public render() {
const {me} = this.state

return (
<Panel>
<Panel.Header title="About Me">
<Button text="Edit About Me" />
</Panel.Header>
<Panel.Body>
<Form>
<Form.Element label="Username" colsXS={Columns.Six}>
<Input
value={me.name}
dataTest="nameInput"
titleText="Username"
size={ComponentSize.Small}
status={ComponentStatus.Disabled}
onChange={this.handleChangeInput}
/>
</Form.Element>
</Form>
</Panel.Body>
</Panel>
)
}

private handleChangeInput = (_: ChangeEvent<HTMLInputElement>): void => {
// console.log('changing: ', e)
}
}

const mstp = ({me}) => ({
me,
})

export default connect<StateProps>(mstp)(Settings)
48 changes: 48 additions & 0 deletions ui/src/me/components/account/__snapshots__/Account.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Account rendering renders! 1`] = `
<Page>
<PageHeader
fullWidth={false}
inPresentationMode={false}
>
<PageHeaderLeft
offsetPixels={0}
>
<PageTitle
title="My Account"
/>
</PageHeaderLeft>
<PageHeaderRight
offsetPixels={0}
/>
</PageHeader>
<PageContents
fullWidth={false}
scrollable={true}
>
<withRouter(ProfilePage)
activeTabUrl="settings"
name="Account"
parentUrl="/account"
>
<ProfilePageSection
id="settings"
title="Settings"
url="settings"
>
<Connect(Settings) />
</ProfilePageSection>
<ProfilePageSection
id="tokens"
title="Tokens"
url="tokens"
>
<div>
Tokens go here
</div>
</ProfilePageSection>
</withRouter(ProfilePage)>
</PageContents>
</Page>
`;
140 changes: 140 additions & 0 deletions ui/src/me/components/account/__snapshots__/Settings.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Account rendering renders! 1`] = `
<Settings
me={
Object {
"id": "id-of-groot",
"links": Object {
"log": "/api/v2/users/id-of-groot/log",
"self": "/api/v2/users/id-of-groot",
},
"name": "groot",
}
}
>
<Panel>
<div
className="panel"
>
<PanelHeader
title="About Me"
>
<div
className="panel-header"
>
<div
className="panel-title"
>
About Me
</div>
<div
className="panel-controls"
>
<ComponentSpacer
align="right"
>
<div
className="component-spacer component-spacer--right component-spacer--horizontal"
>
<Button
active={false}
color="default"
shape="none"
size="sm"
status="default"
text="Edit About Me"
type="submit"
>
<button
className="button button-sm button-default"
disabled={false}
tabIndex={0}
title="Edit About Me"
type="submit"
>
Edit About Me
</button>
</Button>
</div>
</ComponentSpacer>
</div>
</div>
</PanelHeader>
<PanelBody>
<div
className="panel-body"
>
<Form>
<form
className="form--wrapper"
onSubmit={[Function]}
>
<FormElement
colsXS={6}
errorMessage=""
helpText=""
label="Username"
>
<div
className="form--element col-xs-6"
>
<FormLabel
label="Username"
>
<label
className="form--label"
>
Username
</label>
</FormLabel>
<Input
autoFocus={false}
autocomplete="off"
dataTest="nameInput"
disabledTitleText="This input is disabled"
name=""
onChange={[Function]}
placeholder=""
size="sm"
spellCheck={false}
status="disabled"
titleText="Username"
value="groot"
>
<div
className="input input-sm input--disabled"
style={
Object {
"width": "100%",
}
}
>
<input
autoComplete="off"
autoFocus={false}
className="input-field"
data-test="nameInput"
disabled={true}
name=""
onChange={[Function]}
placeholder=""
spellCheck={false}
title="This input is disabled"
value="groot"
/>
<div
className="input-shadow"
/>
</div>
</Input>
</div>
</FormElement>
</form>
</Form>
</div>
</PanelBody>
</div>
</Panel>
</Settings>
`;
2 changes: 1 addition & 1 deletion ui/src/me/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MePage from 'src/me/containers/MePage'
import Account from 'src/me/components/Account'
import Account from 'src/me/components/account/Account'

export {MePage, Account}
Loading

0 comments on commit f450000

Please sign in to comment.