|
1 | 1 | import React, { type ReactElement } from 'react';
|
| 2 | +import type { Options } from 'cypress-image-snapshot'; |
2 | 3 | import Collapse from '../index';
|
3 | 4 | import '../style';
|
4 | 5 |
|
5 | 6 | const Panel = Collapse.Panel;
|
6 | 7 |
|
| 8 | +class CompareSnapshot { |
| 9 | + customSnapshotsDir: string; |
| 10 | + customDiffDir: string; |
| 11 | + constructor(options: { componentName: string }) { |
| 12 | + const { componentName } = options; |
| 13 | + this.customSnapshotsDir = `/components/${componentName}/__tests__/snapshots/__base__`; |
| 14 | + this.customDiffDir = `/components/${componentName}/__tests__/snapshots/__diff__`; |
| 15 | + } |
| 16 | + compare( |
| 17 | + subject: Cypress.Chainable<JQuery<HTMLElement>>, |
| 18 | + nameOrOptions?: string | Options, |
| 19 | + options?: Options |
| 20 | + ) { |
| 21 | + const commandOptions = typeof nameOrOptions === 'string' ? options : nameOrOptions; |
| 22 | + const targetOptions = Object.assign( |
| 23 | + { |
| 24 | + customSnapshotsDir: this.customSnapshotsDir, |
| 25 | + customDiffDir: this.customDiffDir, |
| 26 | + }, |
| 27 | + commandOptions |
| 28 | + ); |
| 29 | + const target = subject ? subject : cy; |
| 30 | + return target.matchImageSnapshot(targetOptions); |
| 31 | + } |
| 32 | +} |
| 33 | +const collapseCompareSnapshot = new CompareSnapshot({ componentName: 'collapse' }); |
| 34 | + |
7 | 35 | describe('Collapse', () => {
|
8 | 36 | describe('render', () => {
|
9 | 37 | it('[normal] Should render null', () => {
|
@@ -60,6 +88,16 @@ describe('Collapse', () => {
|
60 | 88 | cy.get('.next-collapse').should('have.length', 1);
|
61 | 89 | cy.get('.next-collapse-panel').should('have.length', 2);
|
62 | 90 | });
|
| 91 | + |
| 92 | + it('should render with proper border-radius and overflow hidden', () => { |
| 93 | + cy.mount( |
| 94 | + <Collapse style={{ borderRadius: '50px' }}> |
| 95 | + <Panel title="Pannel Title">Pannel Content</Panel> |
| 96 | + <Panel title="Pannel Title">Pannel Content</Panel> |
| 97 | + </Collapse> |
| 98 | + ); |
| 99 | + collapseCompareSnapshot.compare(cy.get('.next-collapse')); |
| 100 | + }); |
63 | 101 | });
|
64 | 102 |
|
65 | 103 | describe('defaultExpandedKeys', () => {
|
|
0 commit comments