Skip to content

Commit

Permalink
Fix generateNumbers function of HelpGuide comp (#212)
Browse files Browse the repository at this point in the history
* Fix generateNumbers function of HelpGuide comp

* Bump version
  • Loading branch information
trankhacvy authored Jan 7, 2020
1 parent be33977 commit c648517
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reapit/elements",
"version": "0.5.25",
"version": "0.5.26",
"description": "A collection of React components and utilities for building apps for Reapit Marketplace",
"main": "dist/index.js",
"umd:main": "dist/elements.umd.production.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ exports[`HelpGuide should match a snapshot 1`] = `
>
<div
className="helpguide-wrapper"
key="helper-guide-child-0"
>
<Component
component={[Function]}
Expand All @@ -87,6 +88,7 @@ exports[`HelpGuide should match a snapshot 1`] = `
</div>
<div
className="helpguide-wrapper"
key="helper-guide-child-1"
>
<Component
component={[Function]}
Expand All @@ -96,6 +98,7 @@ exports[`HelpGuide should match a snapshot 1`] = `
</div>
<div
className="helpguide-wrapper"
key="helper-guide-child-2"
>
<Component
component={[Function]}
Expand All @@ -105,6 +108,7 @@ exports[`HelpGuide should match a snapshot 1`] = `
</div>
<div
className="helpguide-wrapper"
key="helper-guide-child-3"
>
<Component
component={[Function]}
Expand Down
7 changes: 0 additions & 7 deletions src/components/HelpGuide/__tests__/horizontal-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react'
import { shallow } from 'enzyme'
import {
HorizontalTimeline,
generateNumbers,
caculateCircleRef,
caculateLineRef,
calculateElement
Expand All @@ -13,12 +12,6 @@ describe('NumberedTimeline', () => {
expect(shallow(<HorizontalTimeline total={5} currentIndex={3} />)).toMatchSnapshot()
})

it('generateNumbers should run correctly', () => {
;[[5, [0, 1, 2, 3, 4]], [3, [0, 1, 2]]].forEach(([input, expected]) => {
expect(generateNumbers(input as number)()).toEqual(expected)
})
})

it('caculateCircleRef should run correctly', () => {
const mockProps = {
activeRef: {
Expand Down
10 changes: 10 additions & 0 deletions src/components/HelpGuide/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { generateNumbers } from '../utils'

describe('help guide utils', () => {
it('generateNumbers', () => {
const total = 5
const expectResult = [0, 1, 2, 3, 4]

expect(generateNumbers(total)()).toEqual(expectResult)
})
})
7 changes: 0 additions & 7 deletions src/components/HelpGuide/__tests__/vertical-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react'
import { shallow } from 'enzyme'
import {
VerticalTimeline,
generateNumbers,
caculateCircleRef,
caculateLineRef,
calculateElement,
Expand All @@ -14,12 +13,6 @@ describe('NumberedTimeline', () => {
expect(shallow(<VerticalTimeline total={5} currentIndex={3} />)).toMatchSnapshot()
})

it('generateNumbers should run correctly', () => {
;[[5, [0, 1, 2, 3, 4]], [3, [0, 1, 2]]].forEach(([input, expected]) => {
expect(generateNumbers(input as number)()).toEqual(expected)
})
})

it('caculateCircleRef should run correctly', () => {
const mockProps = {
activeRef: {
Expand Down
5 changes: 1 addition & 4 deletions src/components/HelpGuide/horizontal-timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as React from 'react'

export const generateNumbers = (total: number) => () => {
return [...Array(total).keys()]
}
import { generateNumbers } from './utils'

export const caculateCircleRef = ({
activeRef,
Expand Down
6 changes: 5 additions & 1 deletion src/components/HelpGuide/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export const HelpGuide = ({ children, current, isLoading = false }: HelpGuidePro
{renderTimeline(total, currentIndex, isMobileScreen)}
<FlexContainerBasic flexColumn className="justify-center relative">
{React.Children.toArray(children).map((child, index) => (
<div ref={currentIndex === index ? currentStepRef : null} className="helpguide-wrapper">
<div
key={`helper-guide-child-${index}`}
ref={currentIndex === index ? currentStepRef : null}
className="helpguide-wrapper"
>
{child}
</div>
))}
Expand Down
7 changes: 7 additions & 0 deletions src/components/HelpGuide/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const generateNumbers = (total: number) => () => {
const result: number[] = []
for (let i = 0; i < total; i++) {
result.push(i)
}
return result
}
5 changes: 1 addition & 4 deletions src/components/HelpGuide/vertical-timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as React from 'react'
import { generateNumbers } from './utils'

export const LI_MARGIN = 30

export const generateNumbers = (total: number) => () => {
return [...Array(total).keys()]
}

export const caculateCircleRef = ({
activeRef,
circleRef
Expand Down
2 changes: 1 addition & 1 deletion src/styles/components/help-guide.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.helpguide-graphic {
max-width: 400px;
margin: auto;
> img {
& img {
max-width: 100%;
height: auto;
}
Expand Down

0 comments on commit c648517

Please sign in to comment.