Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup interaction testing #1895

Merged
merged 102 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
29f3944
upgrade to storybook v7
chaitanyadeorukhkar Jul 21, 2023
c064b01
revert resolutions
chaitanyadeorukhkar Jul 21, 2023
d5cc772
make android & package changes
chaitanyadeorukhkar Jul 27, 2023
f999c7c
make ios changes
chaitanyadeorukhkar Jul 28, 2023
a348073
get ios working
chaitanyadeorukhkar Jul 31, 2023
2aa3d82
make android work
chaitanyadeorukhkar Jul 31, 2023
a1d4124
update lockfile
chaitanyadeorukhkar Jul 31, 2023
55533c3
update to react native 0.72.3
chaitanyadeorukhkar Aug 1, 2023
8a2b164
Merge branch 'master' into build/upgrade-react-native-72.3
kamleshchandnani Aug 1, 2023
eeaff79
Merge branch 'master' into build/upgrade-react-native-72.3
kamleshchandnani Aug 1, 2023
d3ee011
fix some ts errors
chaitanyadeorukhkar Aug 2, 2023
871dcb8
chore: upgrde jest to v29
snitin315 Jul 26, 2023
664534f
fix: create react-native-reanimated patch
snitin315 Jul 26, 2023
5110072
fix: tests
snitin315 Jul 26, 2023
4d1f8cc
chore: fix react-native issues
snitin315 Jul 28, 2023
eb6babf
test: fix react native tests
snitin315 Jul 29, 2023
a21fd86
chore: fix react native tests
snitin315 Jul 29, 2023
93edb94
test: fix ProgressBar test cases
snitin315 Jul 29, 2023
329eedd
test: update snapshots
snitin315 Jul 31, 2023
3fa56a3
test: fix styles in snapshots
snitin315 Aug 2, 2023
fc452a2
ci: enable jest sharding
snitin315 Aug 2, 2023
2b53c42
test: update Tooltip snapshot
snitin315 Aug 3, 2023
71a254b
test: update Tooltip snapshot
snitin315 Aug 3, 2023
ff460bb
fix TS errors
chaitanyadeorukhkar Aug 3, 2023
f5f5f9f
readd editorconfig
chaitanyadeorukhkar Aug 3, 2023
3b0ed78
new line
chaitanyadeorukhkar Aug 3, 2023
c758109
update resolutions
chaitanyadeorukhkar Aug 3, 2023
2642f30
Create proud-roses-buy.md
chaitanyadeorukhkar Aug 3, 2023
8606b4e
fix Sandbox initialization for react 18
chaitanyadeorukhkar Aug 3, 2023
96ab835
Merge remote-tracking branch 'origin/feat/upgrade-jest' into build/up…
chaitanyadeorukhkar Aug 4, 2023
ea42401
fix tests
chaitanyadeorukhkar Aug 4, 2023
91168ac
Update .github/workflows/blade-validate.yml
snitin315 Aug 6, 2023
0d7af06
Merge branch 'master' into feat/upgrade-jest
snitin315 Aug 6, 2023
dd10d9e
chore: update snaps
snitin315 Aug 7, 2023
2465ed8
chore: patch bundlemon
snitin315 Aug 7, 2023
9759702
ci: apply patches when cache-hit
snitin315 Aug 7, 2023
1885bc2
ci: apply patches when cache-hit
snitin315 Aug 7, 2023
9cb4973
fix react native tests
chaitanyadeorukhkar Aug 7, 2023
1969896
Merge remote-tracking branch 'origin/master' into build/upgrade-react…
chaitanyadeorukhkar Aug 7, 2023
bbecde4
Merge remote-tracking branch 'origin/feat/upgrade-jest' into build/up…
chaitanyadeorukhkar Aug 7, 2023
e438c9b
fix typos
chaitanyadeorukhkar Aug 7, 2023
32dea13
Merge remote-tracking branch 'origin/master' into build/upgrade-react…
chaitanyadeorukhkar Aug 7, 2023
cad7dda
resolve TS issue
chaitanyadeorukhkar Aug 7, 2023
3dab290
update snapshots
chaitanyadeorukhkar Aug 7, 2023
79befc0
add extra timeout for BottomSheet test
chaitanyadeorukhkar Aug 7, 2023
e385231
Merge remote-tracking branch 'origin/master' into build/upgrade-react…
chaitanyadeorukhkar Aug 7, 2023
b708e86
Update proud-roses-buy.md
chaitanyadeorukhkar Aug 8, 2023
b675dce
update useMakeFigmaURL
chaitanyadeorukhkar Aug 8, 2023
e94e964
upgrade storybook RN
chaitanyadeorukhkar Aug 8, 2023
486493d
Merge remote-tracking branch 'origin/build/upgrade-react-native-72.3-…
chaitanyadeorukhkar Aug 8, 2023
a342107
resolve babel plugin issue
chaitanyadeorukhkar Aug 8, 2023
6560dbd
get react native storybook working (kinda)
chaitanyadeorukhkar Aug 9, 2023
1ed9332
update yarn.lock & remove sbmodern from metro config
chaitanyadeorukhkar Aug 9, 2023
d8a3dcc
update to alpha 5
chaitanyadeorukhkar Aug 16, 2023
ac724c7
Merge remote-tracking branch 'origin/master' into build/storybook-upg…
chaitanyadeorukhkar Aug 16, 2023
e039efc
fix globals usage
chaitanyadeorukhkar Aug 16, 2023
29cbb03
include internal stories
chaitanyadeorukhkar Aug 16, 2023
7c69a8b
Merge remote-tracking branch 'origin/master' into build/storybook-upg…
chaitanyadeorukhkar Aug 16, 2023
19e6ca1
Delete proud-roses-buy.md
chaitanyadeorukhkar Aug 16, 2023
0862f31
update lock icon
chaitanyadeorukhkar Aug 16, 2023
2fcb3db
Merge remote-tracking branch 'origin/master' into build/storybook-upg…
chaitanyadeorukhkar Aug 21, 2023
a2d154c
fix css on mdx
chaitanyadeorukhkar Aug 24, 2023
5f21851
fix missing docs and Sandbox errors
chaitanyadeorukhkar Aug 24, 2023
1d6cfa8
make internal stories work
chaitanyadeorukhkar Aug 24, 2023
f5e7297
Merge remote-tracking branch 'origin/master' into build/storybook-upg…
chaitanyadeorukhkar Dec 15, 2023
438004f
fix web stories
chaitanyadeorukhkar Dec 19, 2023
4691661
update storybook requires
chaitanyadeorukhkar Dec 19, 2023
680097e
update docs to use tag autodocs
chaitanyadeorukhkar Dec 19, 2023
5715ba1
feat: setup interaction testing
kamleshchandnani Dec 20, 2023
ff3dec6
fix types
chaitanyadeorukhkar Dec 20, 2023
a241fc6
Merge remote-tracking branch 'origin/master' into build/storybook-upg…
chaitanyadeorukhkar Dec 20, 2023
720c354
Merge branch 'build/storybook-upgrade-v7-with-rn-upgrade' of github.c…
kamleshchandnani Dec 20, 2023
975db64
remove unused file
chaitanyadeorukhkar Dec 21, 2023
e7d8a67
revert changes
chaitanyadeorukhkar Dec 21, 2023
b391679
remove overrideTheme story
chaitanyadeorukhkar Dec 21, 2023
c8dabad
replace ComponentStory with StoryFn
chaitanyadeorukhkar Dec 21, 2023
8c5d6a0
update Snapshot
chaitanyadeorukhkar Dec 21, 2023
8261d96
remove overrideTheme storybook
chaitanyadeorukhkar Dec 21, 2023
e4c0a50
update Podfile
chaitanyadeorukhkar Dec 21, 2023
deb9dd3
fix: add carousel fixes and interaction tests
kamleshchandnani Dec 21, 2023
e46d72c
Merge branch 'build/storybook-upgrade-v7-with-rn-upgrade' of github.c…
kamleshchandnani Dec 21, 2023
f8e0fbd
chore: replace ComponentStory type with StoryFn
kamleshchandnani Dec 21, 2023
b2d13f1
Merge branch 'master' of github.com:razorpay/blade into setup-interac…
kamleshchandnani Dec 22, 2023
d5e8478
tests: update snapshots
kamleshchandnani Dec 22, 2023
e2e9ae1
chore: eslint fixes
kamleshchandnani Dec 22, 2023
42e961d
ci: add interaction test in validate workflow
kamleshchandnani Dec 22, 2023
3e78f99
ci: install playwright
kamleshchandnani Dec 22, 2023
01233af
ci: uncomment things
kamleshchandnani Dec 22, 2023
be11304
chore: cleanup
kamleshchandnani Dec 22, 2023
69350e8
chore: cleanup
kamleshchandnani Dec 22, 2023
fea458f
test: run tests on firefox, chromium and webkit
kamleshchandnani Dec 22, 2023
12138f4
test: assert carousel visible items on mobile
kamleshchandnani Dec 22, 2023
41b64dd
ci: move interaction test under tests workflow
kamleshchandnani Dec 26, 2023
112deeb
test: update sleep to 8000ms
kamleshchandnani Dec 26, 2023
86d4e1e
test: increase sleep time
kamleshchandnani Dec 26, 2023
3291bb9
chore: remove unused imports
kamleshchandnani Dec 26, 2023
84b1a66
tests: add more assertions
kamleshchandnani Dec 28, 2023
51fcf4b
fix: firefox scroll multiple fire issue
anuraghazra Jan 2, 2024
5efbb56
ci: add workflow to trigger interaction test
kamleshchandnani Jan 4, 2024
d06801d
fix: carousel onChange getting called multiple times
anuraghazra Jan 4, 2024
16d348a
Merge branch 'setup-interaction-test' of https://github.com/razorpay/…
anuraghazra Jan 4, 2024
01376b5
chore: lint
anuraghazra Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/blade-interaction-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Blade Interaction Tests

# Runs the action when
# 1. 'Run Interaction Tests' label is added to PR
# 2. Workflow is trigerred manually
# 3. PR is merged to master

on:
workflow_dispatch:
pull_request:
types: [labeled]
push:
branches:
- 'master'

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.CI_BOT_TOKEN }}

jobs:
interaction-tests:
name: Run Interaction Tests
runs-on: ubuntu-latest # nosemgrep: non-self-hosted-runner
if: ${{ github.event_name == 'workflow_dispatch' || github.event.label.name == 'Run Interaction Tests' || github.event_name == 'push' }}
steps:
- name: Checkout Codebase
uses: actions/checkout@v3
- name: Use Node v18
uses: actions/setup-node@v3
with:
node-version: 18.12.1
- name: Setup Cache & Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Run Interaction Tests
run: |
npx playwright install chromium firefox webkit --with-deps
yarn test:react:interaction:ci
working-directory: packages/blade
2 changes: 1 addition & 1 deletion .github/workflows/blade-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
node-version: 18.12.1
- name: Setup Cache & Install Dependencies
uses: ./.github/actions/install-dependencies
- name: Run React & React Native Tests
- name: Run Unit Tests
run: yarn test
working-directory: packages/blade
env:
Expand Down
189 changes: 97 additions & 92 deletions packages/blade/.storybook/react-native/storybook.requires.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/blade/.storybook/react/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config: StorybookConfig = {
'@storybook/addon-docs',
'@storybook/addon-a11y',
'@storybook/preset-create-react-app',
'@storybook/addon-interactions'
],
framework: {
name: '@storybook/react-webpack5',
Expand Down
16 changes: 15 additions & 1 deletion packages/blade/.storybook/react/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { INTERNAL_STORY_ADDON_PARAM } from './constants';
const { GlobalStyle } = global;
import { DocsContainer } from '@storybook/addon-docs';
import React from 'react';
import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport';
import './global.css';

export const parameters = {
Expand All @@ -27,6 +28,19 @@ export const parameters = {
disable: true,
},
},
viewport: {
viewports: {
...MINIMAL_VIEWPORTS,
iPhone6: {
name: 'iPhone 6',
styles: {
height: '667px',
width: '375px',
},
type: 'mobile',
},
Comment on lines +34 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the MINIMAL_VIEWPORTS doesn't have any mobile viewport by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they have weird viewports like iPhone-5 or smaller so i added standard one

},
},
// on development setting it to undefined so that on 'live reload' it won't switch
// to docs panel while developing the component
viewMode: process.env.NODE_ENV === 'development' ? undefined : 'docs',
Expand Down Expand Up @@ -58,7 +72,7 @@ export const parameters = {
'useTheme',
],
'Components',
['*', 'KitchenSink'],
['*', 'Interaction Tests', 'KitchenSink'],
'Recipes',
],
},
Expand Down
15 changes: 13 additions & 2 deletions packages/blade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@
"react-native:storybook:ios": "yarn react-native:get-stories && cross-env FRAMEWORK=REACT_NATIVE react-native run-ios",
"react-native:storybook:start": "yarn react-native:get-stories && cross-env NODE_OPTIONS=--openssl-legacy-provider FRAMEWORK=REACT_NATIVE react-native start --reset-cache",
"react": "yarn run react:storybook",
"react:storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider FRAMEWORK=REACT storybook dev -c ./.storybook/react -p 9009",
"react:storybook:build": "cross-env NODE_OPTIONS=--openssl-legacy-provider FRAMEWORK=REACT storybook build -c ./.storybook/react -o storybook-site",
"react:storybook": "cross-env FRAMEWORK=REACT storybook dev -c ./.storybook/react -p 9009",
"react:storybook:build": "cross-env FRAMEWORK=REACT storybook build -c ./.storybook/react -o storybook-site --quiet",
"react:storybook:serve": "http-server storybook-site --port 9009 --silent",
"react:storybook:serve:test": "wait-on http://127.0.0.1:9009/ && yarn test:react:interaction",
"test:react:interaction": "cross-env FRAMEWORK=REACT test-storybook -c ./.storybook/react --url http://127.0.0.1:9009/",
"test:react:interaction:ci": "yarn react:storybook:build && run-p react:storybook:serve react:storybook:serve:test --race",
"test:react": "cross-env FRAMEWORK=REACT jest -c ./jest.web.config.js --shard=$SHARD --forceExit",
"test:react-native": "cross-env FRAMEWORK=REACT_NATIVE jest -c ./jest.native.config.js --shard=$SHARD --forceExit",
"start:ios": "cross-env NODE_OPTIONS=--openssl-legacy-provider run-p react-native:storybook:start react-native:storybook:ios",
Expand Down Expand Up @@ -135,6 +139,13 @@
"tinycolor2": "1.6.0"
},
"devDependencies": {
"http-server": "14.1.1",
"wait-on": "7.2.0",
"@storybook/addon-interactions": "7.6.6",
"@storybook/testing-library": "0.2.2",
"@storybook/test-runner": "0.16.0",
"@storybook/jest": "0.2.3",
"playwright": "1.40.1",
"chromatic": "6.22.0",
"@babel/cli": "7.23.0",
"@babel/core": "7.20.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const TestimonialCard = ({
);
};

const CarouselExample = (props: Omit<CarouselProps, 'children'>): React.ReactElement => {
export const CarouselExample = (props: Omit<CarouselProps, 'children'>): React.ReactElement => {
const key = `${props.visibleItems}-${props.shouldAddStartEndSpacing}`;
return (
<Box width="100%" height={isReactNative() ? '350px' : 'auto'}>
Expand Down
41 changes: 34 additions & 7 deletions packages/blade/src/components/Carousel/Carousel.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import type { CarouselContextProps } from './CarouselContext';
import { CarouselContext } from './CarouselContext';
import { getCarouselItemId } from './utils';
import { CAROUSEL_AUTOPLAY_INTERVAL, componentIds } from './constants';
import debounce from '~utils/lodashButBetter/debounce';
import throttle from '~utils/lodashButBetter/throttle';
import getIn from '~utils/lodashButBetter/get';
import throttle from '~utils/lodashButBetter/throttle';
import debounce from '~utils/lodashButBetter/debounce';
import { Box } from '~components/Box';
import BaseBox from '~components/Box/BaseBox';
import { castWebType, makeMotionTime, useInterval } from '~utils';
import { castWebType, makeMotionTime, useInterval, usePrevious } from '~utils';
import { useId } from '~utils/useId';
import { makeAccessible } from '~utils/makeAccessible';
import { metaAttribute, MetaConstants } from '~utils/metaAttribute';
import { useDidUpdate } from '~utils/useDidUpdate';
import { useVerifyAllowedChildren } from '~utils/useVerifyAllowedChildren/useVerifyAllowedChildren';
import { useTheme } from '~components/BladeProvider';
import { useFirstRender } from '~utils/useFirstRender';

type ControlsProp = Required<
Pick<
Expand Down Expand Up @@ -223,6 +223,29 @@ const CarouselBody = React.forwardRef<HTMLDivElement, CarouselBodyProps>(
},
);

/**
* A custom hook which syncs an effect with a state
* While ignoring the first render & only running the effect when the state changes
*/
function useSyncUpdateEffect<T>(
effect: React.EffectCallback,
stateToSyncWith: T,
deps: React.DependencyList,
) {
const isFirst = useFirstRender();
const prevState = usePrevious<T>(stateToSyncWith);

React.useEffect(() => {
if (!isFirst) {
// if the state is the same as the previous state
// we don't want to run the effect
if (prevState === stateToSyncWith) return;
return effect();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stateToSyncWith, ...deps]);
}

const Carousel = ({
autoPlay,
visibleItems = 1,
Expand Down Expand Up @@ -450,9 +473,13 @@ const Carousel = ({
shouldAddStartEndSpacing,
]);

useDidUpdate(() => {
onChange?.(activeSlide);
}, [activeSlide, onChange]);
useSyncUpdateEffect(
() => {
onChange?.(activeSlide);
},
activeSlide,
[onChange],
);

return (
<CarouselContext.Provider value={carouselContext}>
Expand Down
Loading
Loading