Skip to content

Commit a1ded88

Browse files
Test files and github actions
2 parents d3c3015 + 98e8c5b commit a1ded88

File tree

7 files changed

+212
-12
lines changed

7 files changed

+212
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ReleaseType:
7+
description: 'Release Type'
8+
required: true
9+
default: 'warning'
10+
type: choice
11+
options:
12+
- Major
13+
- Feature
14+
- Bug
15+
16+
jobs:
17+
update-and-publish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: 16.x
27+
scope: '@keyvaluesystems'
28+
29+
- name: Install dependencies
30+
run: npm install
31+
32+
- name: Run tests
33+
run: npm run test
34+
35+
- name: 'Set release type : ${{ inputs.ReleaseType }}'
36+
id: release_type
37+
uses: ASzc/change-string-case-action@v5
38+
with:
39+
string: ${{ inputs.ReleaseType }}
40+
41+
- name: Extract Current Branch and Validate
42+
id: get_current_branch
43+
shell: bash
44+
run: |
45+
BRANCH="${GITHUB_REF#refs/heads/}"
46+
if [ "$BRANCH" == 'main' ]
47+
then
48+
echo "Branch validation Successful"
49+
else
50+
echo "Releases only taken from main branch"
51+
exit 1
52+
fi
53+
54+
- name: Get Latest version from package.json
55+
run: |
56+
# Get the latest version from package.json
57+
LATEST_VERSION=$(node -p "require('./package.json').version")
58+
59+
# Output the latest version as a workflow env
60+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_ENV
61+
62+
- name: Get new version
63+
id: get_next_version
64+
uses: christian-draeger/increment-semantic-version@1.0.3
65+
with:
66+
current-version: ${{ env.latest_version }}
67+
version-fragment: ${{ steps.release_type.outputs.lowercase }}
68+
69+
- name: Update version in package.json and package-lock.json
70+
run: |
71+
OLD_VERSION=${{ env.latest_version }}
72+
NEW_VERSION=${{ steps.get_next_version.outputs.next-version }}
73+
74+
npm version $NEW_VERSION --no-git-tag-version
75+
git config user.name github-actions
76+
git config user.email github-actions@github.com
77+
git add package.json package-lock.json
78+
git commit -m "Bump version from $OLD_VERSION to $NEW_VERSION"
79+
git push origin HEAD:main
80+
81+
- name: Build Package
82+
run: npm run build
83+
84+
- name: Publish package
85+
run: npm publish --access public --//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
86+
if: success()
87+
88+
- name: Revert package.json and package-lock.json
89+
run: |
90+
# Revert package.json and package-lock.json to the previous version
91+
npm version ${{ env.latest_version }} --no-git-tag-version
92+
git commit -am "Revert to version ${{ env.latest_version }}"
93+
git push origin HEAD:main
94+
if: failure()
95+
96+
- name: Create GitHub release
97+
if: success()
98+
uses: actions/create-release@v1
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
with:
102+
tag_name: v${{ steps.get_next_version.outputs.next-version }}
103+
release_name: Release v${{ steps.get_next_version.outputs.next-version }}
104+
# body: Release ${{ env.NEW_VERSION }}
105+
draft: false
106+
prerelease: false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test Suite
2+
3+
on:
4+
pull_request:
5+
# The branches below must be a subset of the branches above
6+
branches: [main]
7+
8+
jobs:
9+
test-and-build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [16.x]
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
fetch-depth: 0
20+
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v2
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
26+
- name: Install dependencies
27+
run: npm install
28+
29+
- name: Linting
30+
run: npm run eslint
31+
32+
- name: Run tests
33+
run: npm run test
34+
35+
- name: Build
36+
run: npm run build

src/lib/inline-images/Avatar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const Avatar = (props: AvatarPropType): JSX.Element => {
1212
nameOnHover,
1313
onUserClick,
1414
name,
15-
styles = {}
15+
styles = {},
16+
id
1617
} = props;
1718
return (
1819
<div
@@ -21,6 +22,7 @@ const Avatar = (props: AvatarPropType): JSX.Element => {
2122
style={{
2223
cursor: onUserClick && 'pointer'
2324
}}
25+
id={id}
2426
>
2527
<img
2628
src={avatarUrl}

src/lib/inline-images/InlineImages.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ const InlineImages = (props: InlineImagesPropType): JSX.Element => {
2626
style={{
2727
left: `${index * (spaceBetweenPics ?? DEFAULT_SPACE_BETWEEN_PICS)}px`
2828
}}
29+
id="inline-images"
2930
>
3031
<Avatar
3132
avatarUrl={user.avatarUrl}
3233
name={user.name}
3334
elivateOnHover={elivateOnHover}
3435
nameOnHover={nameOnHover}
35-
onUserClick={onUserClick && ((): void => {
36-
onUserClick(user);
37-
})}
36+
onUserClick={(): void => {
37+
if (onUserClick) onUserClick(user);
38+
}}
39+
id={`inline-image-${index}`}
3840
styles={styles}
3941
/>
4042
</div>
@@ -47,6 +49,7 @@ const InlineImages = (props: InlineImagesPropType): JSX.Element => {
4749
cursor: onUserClick && 'pointer',
4850
...getStyles(Elements.ExtraValue, styles)
4951
}}
52+
id="inline-images-extra-value"
5053
>
5154
{totalUserCount - data?.length} +
5255
</div>

src/lib/inline-images/types.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ export interface AvatarPropType {
33
name?: string,
44
elivateOnHover?: boolean,
55
nameOnHover?: boolean,
6-
onUserClick: function,
7-
styles?: StyleProp
6+
onUserClick?: function,
7+
styles?: StyleProp,
8+
id?: string
89
}
910

1011
export interface InlineImagesPropType {
11-
data: [AvatarPropType],
12+
data: AvatarPropType[],
1213
totalUserCount?: number,
1314
elivateOnHover?: boolean,
1415
nameOnHover?: boolean,

src/lib/tests/index.test.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import {
3+
render,
4+
fireEvent,
5+
queryByAttribute,
6+
queryAllByAttribute
7+
} from "@testing-library/react";
8+
import { InlineImagesPropType } from '../inline-images/types';
9+
import InlineImages from '../inline-images';
10+
11+
const getById = queryByAttribute.bind(null, 'id');
12+
const getAllById = queryAllByAttribute.bind(null, 'id');
13+
14+
test("If all the users in data is rendered", async () => {
15+
const inlineImagesProp: InlineImagesPropType = {
16+
data: [{}, {}]
17+
};
18+
const dom = render(<InlineImages {...inlineImagesProp} />);
19+
if (dom) {
20+
const images = await getAllById(dom.container, "inline-images");
21+
if (images?.length === 0) throw Error("Images Absent");
22+
expect(images.length).toBe(2)
23+
}
24+
});
25+
26+
test("If the Onclick is triggered on images",async () => {
27+
const inlineImagesProp: InlineImagesPropType = {
28+
data: [{}]
29+
};
30+
const onClick = jest.fn();
31+
const dom = render(
32+
<InlineImages
33+
{...inlineImagesProp}
34+
onUserClick={onClick}
35+
/>
36+
);
37+
38+
if (dom) {
39+
const image = await getById(dom.container, "inline-image-0");
40+
fireEvent.click(image);
41+
expect(onClick).toBeCalled();
42+
}
43+
});
44+
45+
test("If additional count displayed on image stack",async () => {
46+
const inlineImagesProp: InlineImagesPropType = {
47+
data: [{}, {}],
48+
totalUserCount: 10
49+
};
50+
51+
const dom = render(<InlineImages {...inlineImagesProp} />);
52+
53+
if (dom) {
54+
const extraValue = await getById(dom.container, "inline-images-extra-value");
55+
expect(extraValue.innerHTML).toBe("8 +");
56+
}
57+
})

0 commit comments

Comments
 (0)