Skip to content

Commit

Permalink
test(bezier-react): Improved array test coverage (channel-io#1775)
Browse files Browse the repository at this point in the history
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [ ] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

## Summary
<!-- Please brief explanation of the changes made -->
- changed isLastIndex -> isArrayLastIndex
- Improved `array` test coverage 

## Details
<!-- Please elaborate description of the changes -->
## TO-BE

![image](https://github.com/channel-io/bezier-react/assets/102217654/83978b0f-7b5a-4e75-bce6-62e777380114)

## AS-IS

![image](https://github.com/channel-io/bezier-react/assets/102217654/966f2837-2367-4887-9d2a-d1f530195376)

### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->
  • Loading branch information
SEOKKAMONI authored Dec 7, 2023
1 parent 678099a commit 84e4bd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions packages/bezier-react/src/utils/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import {
compact,
flattenDeep,
isLastIndex,
} from './array'

describe('arrayUtils', () => {
describe('compact', () => {
it('should remove falsy item', () => {
const array = [0, 1, false, 2, '', 3]
expect(compact(array)).toEqual([1, 2, 3])
})
describe('isLastIndex', () => {
it('should return true when the last array index', () => {
const arr = [0, 1, 2, 3, 4]

const result = isLastIndex(arr, 4)

expect(result).toBe(true)
})

it('should return false when not the last array index', () => {
const arr = [0, 1, 2, 3, 4]

const result = isLastIndex(arr, 1)

expect(result).toBe(false)
})
})

describe('compact', () => {
it('should remove falsy item', () => {
const array = [0, 1, false, 2, '', 3]
expect(compact(array)).toEqual([1, 2, 3])
})
})

describe('flattenDeep', () => {
it('should return flatten array', () => {
const array = [1, [2, [3, [4]], 5]]
expect(flattenDeep(array)).toEqual([1, 2, 3, 4, 5])
})
describe('flattenDeep', () => {
it('should return flatten array', () => {
const array = [1, [2, [3, [4]], 5]]
expect(flattenDeep(array)).toEqual([1, 2, 3, 4, 5])
})
})
2 changes: 1 addition & 1 deletion packages/bezier-react/src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArray } from './type'

export function isLastIndex(array: any[], index: number) {
export function isLastIndex(array: ArrayLike<unknown>, index: number) {
return array.length - 1 === index
}

Expand Down

0 comments on commit 84e4bd5

Please sign in to comment.