Skip to content

Commit

Permalink
Creating Bookmarks Toggle and Splitting Account Page
Browse files Browse the repository at this point in the history
  • Loading branch information
jedtan committed Jun 27, 2023
1 parent cc00270 commit 8ecba21
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: actions/checkout@v2
- uses: act ions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
Expand Down
40 changes: 33 additions & 7 deletions src/__tests__/pages/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ToggleButton from '@material-ui/lab/ToggleButton'
import SetUserCauseMutation from 'src/utils/mutations/SetUserCauseMutation'
import CauseIcon from 'src/components/CauseIcon'
import Tooltip from '@material-ui/core/Tooltip'
import localStorageFeaturesManager from 'src/utils/localStorageFeaturesManager'
import Switch from '@material-ui/core/Switch'

jest.mock('next-offline/runtime')
jest.mock('tab-cmp')
Expand All @@ -41,6 +43,9 @@ jest.mock('src/utils/hooks/useCustomTheming')
jest.mock('src/utils/mutations/SetUserCauseMutation')
// eslint-disable-next-line react/prop-types
jest.mock('src/components/CauseIcon', () => ({ icon }) => <div icon={icon} />)
jest.mock('src/utils/localStorageFeaturesManager', () => ({
getFeatureValue: jest.fn(),
}))

const getMockDataResponse = () => ({
user: {
Expand Down Expand Up @@ -116,11 +121,21 @@ describe('account.js', () => {
const AccountPage = require('src/pages/account').default
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const title = content.childAt(0).find(Typography).first()
expect(title.text()).toEqual('Account')
})

it('has an "New Tab Page" title', () => {
expect.assertions(1)
const AccountPage = require('src/pages/account').default
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).at(0)
const title = content.childAt(0).find(Typography).first()
expect(title.text()).toEqual('New Tab Page')
})

it('has a logout button', () => {
expect.assertions(1)
const AccountPage = require('src/pages/account').default
Expand Down Expand Up @@ -227,7 +242,7 @@ describe('account.js', () => {
useData.mockReturnValue({ data: undefined })
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(2).dive()
expect(accountItem.find(Typography).first().text()).toEqual('Username')
expect(accountItem.find(Typography).at(1).text()).toEqual('...')
Expand All @@ -239,7 +254,7 @@ describe('account.js', () => {
useData.mockReturnValue({ data: getMockDataResponse() })
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(2).dive()
expect(accountItem.find(Typography).first().text()).toEqual('Username')
expect(accountItem.find(Typography).at(1).text()).toEqual('IAmFake')
Expand All @@ -251,7 +266,7 @@ describe('account.js', () => {
const mockProps = getMockProps()
useData.mockReturnValue({ data: getMockDataResponse() })
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(3)
expect(accountItem.type()).toEqual(Divider)
})
Expand All @@ -262,7 +277,7 @@ describe('account.js', () => {
useData.mockReturnValue({ data: undefined })
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(4).dive()
expect(accountItem.find(Typography).first().text()).toEqual('Email')
expect(accountItem.find(Typography).at(1).text()).toEqual('...')
Expand All @@ -274,7 +289,7 @@ describe('account.js', () => {
useData.mockReturnValue({ data: getMockDataResponse() })
const mockProps = getMockProps()
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(4).dive()
expect(accountItem.find(Typography).first().text()).toEqual('Email')
expect(accountItem.find(Typography).at(1).text()).toEqual(
Expand All @@ -288,10 +303,21 @@ describe('account.js', () => {
const mockProps = getMockProps()
useData.mockReturnValue({ data: getMockDataResponse() })
const wrapper = shallow(<AccountPage {...mockProps} />)
const content = wrapper.at(0).dive().find(Paper).first()
const content = wrapper.at(0).dive().find(Paper).at(1)
const accountItem = content.childAt(5)
expect(accountItem.type()).toEqual(Divider)
})

it('displays a Bookmarks Toggle after Switch Cause if there is cause', () => {
expect.assertions(1)
const AccountPage = require('src/pages/account').default
const mockProps = getMockProps()
useData.mockReturnValue({ data: getMockDataResponse() })
localStorageFeaturesManager.getFeatureValue.mockReturnValue(true)
const wrapper = mount(<AccountPage {...mockProps} />)
const content = wrapper.find(Switch)
expect(content.length).toEqual(1)
})
})

const getRevertAccountItem = (wrapper) =>
Expand Down
Binary file added src/assets/images/shortcut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions src/components/AddShortcutPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useState } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import PropTypes from 'prop-types'
import { Backdrop, Typography } from '@material-ui/core'
import TextField from '@material-ui/core/TextField'
import Notification from './Notification'
import shortcutImage from 'src/assets/images/shortcut.png'
import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'
import SearchInput from 'src/components/SearchInput'
import Alert from '@material-ui/lab/Alert'
import InfoIcon from '@material-ui/icons/InfoOutlined'
import Logo from 'src/components/Logo'

const useStyles = makeStyles((theme) => ({
content: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
color: 'white'
},
shortcut: {
width: '300px',
},
addIcon: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
},
circle: {
height: '48px',
width: '48px'
},
white: {
color: 'white',
borderColor: 'white'
}
}))
const AddShortcutPage = ({app, user}) => {
const classes = useStyles()
const onSettingsClick = () => {

}

return (
<Backdrop open={true}>
<Logo style={{ height: 40 }} color='white'/>
<div className={classes.content}>
<SearchInput app={app} user={user} />
<div className={classes.addIcon}>
<AddCircleOutlineIcon className={classes.circle}/>
<Typography>Add Shortcut</Typography>
</div>
<img src={shortcutImage} alt="shortcut" className={classes.shortcut} />
<Typography>Add more shortcuts and they’ll appear here!</Typography>
<Alert icon={<InfoIcon className={classes.white} />} severity="info" variant="outlined" className={classes.white}>
Don't want shortcuts? You can hide them from your settings page.
<Button
className={classes.white}
onClick={onSettingsClick}
>
Settings
</Button>
</Alert>
</div>
</Backdrop>
)
}

AddShortcutPage.propTypes = {
onCancel: PropTypes.func,
onSave: PropTypes.func,
}

AddShortcutPage.defaultProps = {
onCancel: () => {},
onSave: () => {},
}

export default AddShortcutPage
77 changes: 77 additions & 0 deletions src/components/AddShortcutPage.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import AddShortcutPage from './AddShortcutPage'

export default {
title: 'Components/AddShortcutPage',
component: AddShortcutPage,
parameters: {
backgrounds: {
default: 'grey',
values: [
{ name: 'grey', value: '#F2F2F2' },
{ name: 'black', value: '#000000' },
],
},
},
}

const useStyles = makeStyles((theme) => ({
widthDiv: {
width: theme.spacing(150),
},
}))

const Template = (args) => {
const classes = useStyles()
return (
<div className={classes.widthDiv}>
<AddShortcutPage {...args} />
</div>
)
}

export const basic = Template.bind({})
basic.args = {
app: {
searchEngines: {
edges: [
{
node: {
name: 'DuckDuckGo',
engineId: 'DuckDuckGo',
rank: 3,
isCharitable: false,
inputPrompt: 'Search DuckDuckGo',
},
},
{
node: {
name: 'Google',
engineId: 'Google',
rank: 1,
isCharitable: false,
inputPrompt: 'Search Google',
},
},
{
node: {
name: 'Ecosia',
engineId: 'Ecosia',
rank: 2,
isCharitable: false,
inputPrompt: 'Search Ecosia',
},
},
],
},
},
user: {
searchEngine: {
name: 'Google',
engineId: 'Google',
inputPrompt: 'Search Google',
},
yahooPaidSearchRewardOptIn: false,
},
}
2 changes: 1 addition & 1 deletion src/components/Confetti.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const standard = Template.bind({})
standard.args = {}
standard.parameters = {
chromatic: {
disableSnapshot: true,
disableSnapshot: true,
},
}
1 change: 1 addition & 0 deletions src/components/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const useStyles = makeStyles((theme) => ({
boxSizing: 'border-box',
display: 'flex',
justifyContent: 'center',
flexDirection: 'column',
},
menuItem: {
display: 'block',
Expand Down
Loading

0 comments on commit 8ecba21

Please sign in to comment.