-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4df727
commit 2b0069d
Showing
6 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/react-components/react-carousel/library/cypress.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { baseConfig } from '@fluentui/scripts-cypress'; | ||
|
||
export default baseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/react-components/react-carousel/library/src/components/Carousel/Carousel.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as React from 'react'; | ||
import { mount as mountBase } from '@cypress/react'; | ||
import { FluentProvider } from '@fluentui/react-provider'; | ||
import { teamsLightTheme } from '@fluentui/react-theme'; | ||
import type { CarouselProps } from './Carousel.types'; | ||
import { CarouselNav } from '../CarouselNav/CarouselNav'; | ||
import { CarouselNavButton } from '../CarouselNavButton/CarouselNavButton'; | ||
import { CarouselNavContainer } from '../CarouselNavContainer/CarouselNavContainer'; | ||
import { CarouselSlider } from '../CarouselSlider/CarouselSlider'; | ||
import { CarouselViewport } from '../CarouselViewport/CarouselViewport'; | ||
import { Carousel } from './Carousel'; | ||
import { CarouselCard } from '../CarouselCard/CarouselCard'; | ||
|
||
const mount = (element: JSX.Element) => { | ||
mountBase(<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>); | ||
}; | ||
|
||
const CarouselControlledIndexTest: React.FC<CarouselProps> = props => { | ||
const [isVisible, setVisibility] = React.useState(false); | ||
const [controlledIndex, setControlledIndex] = React.useState<number | undefined>(props.activeIndex); | ||
|
||
return ( | ||
<Carousel | ||
{...props} | ||
activeIndex={controlledIndex} | ||
onActiveIndexChange={(ev, data) => { | ||
setControlledIndex(data.index); | ||
}} | ||
> | ||
<CarouselViewport> | ||
<CarouselSlider> | ||
<CarouselCard>Card 1</CarouselCard> | ||
<CarouselCard>Card 2</CarouselCard> | ||
<CarouselCard>Card 3</CarouselCard> | ||
{isVisible && <CarouselCard>Card 4</CarouselCard>} | ||
{isVisible && <CarouselCard>Card 5</CarouselCard>} | ||
</CarouselSlider> | ||
</CarouselViewport> | ||
<CarouselNavContainer> | ||
<CarouselNav>{index => <CarouselNavButton aria-label={`Carousel Nav Button ${index}`} />}</CarouselNav> | ||
</CarouselNavContainer> | ||
<button | ||
className="addNewCardsButton" | ||
onClick={() => { | ||
// Add and set to new card | ||
setVisibility(true); | ||
setControlledIndex(4); | ||
}} | ||
> | ||
{'Add cards'} | ||
</button> | ||
</Carousel> | ||
); | ||
}; | ||
CarouselControlledIndexTest.displayName = 'CarouselTest'; | ||
|
||
describe('CarouselControlledIndexTest', () => { | ||
it('Should render to initial value', () => { | ||
const defaultActiveIndex = 1; | ||
mount(<CarouselControlledIndexTest defaultActiveIndex={defaultActiveIndex} />); | ||
const activeIndexNavButton = cy.get<HTMLElement>('.fui-CarouselNavButton').eq(defaultActiveIndex); | ||
activeIndexNavButton.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
it('Should handle controlled index set to newly appended card', () => { | ||
mount(<CarouselControlledIndexTest activeIndex={1} />); | ||
|
||
const activeIndexNavButton = cy.get<HTMLElement>('.fui-CarouselNavButton').eq(1); | ||
activeIndexNavButton.should('have.attr', 'aria-selected', 'true'); | ||
cy.then(() => { | ||
const addNewCardsButton = cy.get<HTMLElement>('.addNewCardsButton'); | ||
addNewCardsButton.click(); | ||
}).then(() => { | ||
const newCardIndexNavButton = cy.get<HTMLElement>('.fui-CarouselNavButton').eq(4); | ||
newCardIndexNavButton.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/react-components/react-carousel/library/tsconfig.cy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"isolatedModules": false, | ||
"types": ["node", "cypress", "cypress-real-events"], | ||
"typeRoots": ["../../../../../node_modules", "../../../../../node_modules/@types"], | ||
"lib": ["ES2019", "dom"] | ||
}, | ||
"include": ["**/*.cy.ts", "**/*.cy.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.cy.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters