Skip to content

Commit

Permalink
Merge pull request #33 from NicolasOmar/feature/created-pets-widget
Browse files Browse the repository at this point in the history
Feature | Create Widget to look created Pets and its composition | Front end
  • Loading branch information
NicolasOmar authored Dec 11, 2022
2 parents 020bde7 + a679673 commit 553b0ec
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "my-pets",
"version": "0.1.82",
"version": "0.2.0",
"author": "Nicolás Omar González Passerino",
"license": "MIT",
"private": false,
Expand Down
6 changes: 3 additions & 3 deletions src/components/app/app.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { render, screen } from '@testing-library/react'
import { MockedProvider } from '@apollo/client/testing'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import { configureStore } from '@reduxjs/toolkit'
// REDUX
import store from '../../redux/reducers'
import reducer from '../../redux/reducers'
// COMPONENTS
import App from './app'

describe.skip('[App]', () => {
describe('[HAPPY PATH]', () => {
test('Renders without props', () => {
render(
<Provider store={createStore(store)}>
<Provider store={configureStore({ reducer })}>
<MockedProvider mocks={[]} addTypefile={false}>
<App />
</MockedProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/Column/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default Column
Column.propTypes = {
_key: string.isRequired,
testId: string.isRequired,
width: oneOf(parseObjKeys(columnSizes, true)),
width: oneOf([...parseObjKeys(columnSizes, true), ...parseObjKeys(columnSizes)]),
isCentered: bool,
isContainer: bool,
isMultiline: bool,
Expand Down
6 changes: 3 additions & 3 deletions src/components/atoms/ProgressBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { colors, sizes } = BULMA_STYLES
const ProgressBar = ({
value = 0,
maxValue = 100,
isLoading = false,
isInfiniteLoading = false,
color = parseObjKeys(colors)[7],
size = parseObjKeys(sizes)[1]
}) => {
Expand All @@ -19,7 +19,7 @@ const ProgressBar = ({
otherClasses: [colors[color], sizes[size]]
})

return isLoading ? (
return isInfiniteLoading ? (
<progress
data-testid="test-loading-progress-bar"
className={progressClasses}
Expand All @@ -43,7 +43,7 @@ ProgressBar.propTypes = {
// BASE PROPS
value: number,
maxValue: number,
isLoading: bool,
isInfiniteLoading: bool,
// STYLE PROPS
color: oneOf(parseObjKeys(colors)),
size: oneOf(parseObjKeys(sizes))
Expand Down
4 changes: 2 additions & 2 deletions src/components/atoms/ProgressBar/index.mocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"isLargeSize": {
"size": "large"
},
"isLoading": {
"isLoading": true
"isInfiniteLoading": {
"isInfiniteLoading": true
}
}
8 changes: 4 additions & 4 deletions src/components/atoms/ProgressBar/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ IsLargeSize.args = {
...mocks.isLargeSize
}

export const isLoading = Template.bind({})
isLoading.storyName = 'Is just loading'
isLoading.args = {
export const IsInfiniteLoading = Template.bind({})
IsInfiniteLoading.storyName = 'With infinite loading'
IsInfiniteLoading.args = {
...IsLargeSize.args,
...mocks.isLoading
...mocks.IsInfiniteLoading
}
27 changes: 27 additions & 0 deletions src/components/pages/Home/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"petPopulationWidget": {
"key": "widget-item",
"cardContent": [
{
"type": "title",
"content": {
"titleText": "My Pets",
"titleSize": "normal",
"styles": { "marginBottom": "20px" }
}
},
{
"type": "section",
"content": null
}
]
},
"cardListTitle": {
"titleSize": "bigger",
"subText": "Welcome to our beautiful place",
"subSize": "small",
"isCentered": true,
"childWidth": 12,
"styles": { "margin": "20px 0px" }
}
}
101 changes: 63 additions & 38 deletions src/components/pages/Home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,80 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
// GRAPHQL CLIENT
import { useLazyQuery } from '@apollo/client'
import { GET_MY_PETS_POPULATION } from '../../../graphql/queries'
// COMPONENTS
import CardsListTemplate from '../../templates/CardsListTemplate'
import TagList from '../../molecules/TagList'
// HELPER FUNCTIONS
import ProgressBar from '../../atoms/ProgressBar'
// FUNCTIONS
import { getLoggedUser } from '../../../functions/local-storage'
// MOCKS
import config from './config.json'

const { cardListTitle, petPopulationWidget } = config

const Home = () => {
const [user] = useState(getLoggedUser())

const cardsListTitle = {
titleText: `HELLO ${user?.name?.toUpperCase()}`,
titleSize: 'bigger',
subText: 'Welcome to our beautiful place',
subSize: 'small',
isCentered: true,
childWidth: 12,
styles: { margin: '20px 0px' }
}

const cardListData = [
const [cardListData, setCardListData] = useState([
{
key: `widget-item`,
...petPopulationWidget,
cardContent: [
petPopulationWidget.cardContent[0],
{
type: 'title',
content: {
titleText: 'First widget test',
titleSize: 'normal',
styles: { marginBottom: '20px' }
}
},
{
type: 'section',
content: (
<TagList
{...{
dataList: Array(13)
.fill(null)
.map((_, i) => ({
text: `widget-test-${++i}`,
color: i % 2 ? 'success' : 'danger'
}))
}}
/>
)
...petPopulationWidget.cardContent[1],
content: <ProgressBar isInfiniteLoading={true} />
}
]
}
]
])
const [getData, { data }] = useLazyQuery(GET_MY_PETS_POPULATION)

useEffect(() => {
const asyncGetData = async () => await getData()
asyncGetData()
}, [getData])

useEffect(() => {
if (data) {
const [all, ...pets] = data.getMyPetsPopulation
setCardListData([
{
...petPopulationWidget,
cardContent: [
{
...petPopulationWidget.cardContent[0],
content: {
...petPopulationWidget.cardContent[0].content,
titleText: `${
all.quantity === 0 ? `No created Pets yet` : `Created Pets: ${all.quantity}`
}`
}
},
{
...petPopulationWidget.cardContent[1],
content: (
<TagList
{...{
dataList: pets.map(({ name, quantity }, i) => ({
text: `${name}s: ${quantity}`,
color: i % 2 ? 'success' : 'danger'
}))
}}
/>
)
}
]
}
])
}
}, [data])

const cardsListTitle = {
...cardListTitle,
titleText: `HELLO ${user?.name?.toUpperCase()}`
}

return <CardsListTemplate {...{ isFetching: false, cardsListTitle, cardListData }} />
return <CardsListTemplate {...{ cardsListTitle, cardListData }} />
}

export default Home
7 changes: 6 additions & 1 deletion src/components/pages/Home/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MockedProvider } from '@apollo/client/testing'
import { render, screen } from '@testing-library/react'
// COMPONENTS
import Home from '.'
Expand All @@ -12,7 +13,11 @@ describe('[Home]', () => {
})

test('Renders with a dummy logged User', () => {
render(<Home />)
render(
<MockedProvider mocks={[]} addTypename={false}>
<Home />
</MockedProvider>
)
expect(screen.getByText(`HELLO ${nameMock.toUpperCase()}`)).toBeInTheDocument()
})
})
6 changes: 3 additions & 3 deletions src/components/pages/ListMyPets/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('react-router-dom', () => ({
useNavigate: () => mockUseNavigate
}))

describe.skip('[ListMyPets]', () => {
describe('[ListMyPets]', () => {
test('Should render the page with its inputs', () => {
render(
<Provider store={configureStore({ reducer })}>
Expand All @@ -27,7 +27,7 @@ describe.skip('[ListMyPets]', () => {
</Provider>
)

expect(() => screen.getByText('My list of Pets')).toThrow()
expect(screen.getByTestId('test-progress-bar')).toBeInTheDocument()
expect(screen.getByText('My list of Pets')).toBeInTheDocument()
expect(screen.getByTestId('test-loading-progress-bar')).toBeInTheDocument()
})
})
2 changes: 1 addition & 1 deletion src/components/templates/CardsListTemplate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const CardsListTemplate = ({
}) => {
const parseCardsList = () =>
isFetching
? [<ProgressBar key={`card-progress-bar`} isLoading={true} />]
? [<ProgressBar key={`card-progress-bar`} isInfiniteLoading={true} />]
: cardListData.map(
({ key, cardHeader, cardImage, cardContent, cardFooter, childWidth = 3 }, cardI) => {
const cardConfig = {
Expand Down
9 changes: 9 additions & 0 deletions src/graphql/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ export const GET_PET = gql`
}
}
`

export const GET_MY_PETS_POPULATION = gql`
query {
getMyPetsPopulation {
name
quantity
}
}
`

0 comments on commit 553b0ec

Please sign in to comment.