Skip to content

Commit 7fa70f2

Browse files
author
泊淞
committed
fix(Collapse): Internal elements need to apply the radius configuration of external elements, close #3277
1 parent 09bf93a commit 7fa70f2

File tree

9 files changed

+875
-8
lines changed

9 files changed

+875
-8
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ gemini-report/
8787
*.log
8888
.DS_Store
8989
src/core-temp
90+
91+
# tests snapshots diff
92+
components/**/__tests__/snapshots/__diff__/**

components/collapse/__docs__/adaptor/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Collapse } from '@alifd/next';
33
import { Types, parseData, NodeType } from '@alifd/adaptor-helper';
4+
import type { INode } from '@alifd/adaptor-helper/types/parse-data';
45

56
interface AdaptorProps {
67
state: string;
@@ -34,7 +35,7 @@ export default {
3435
},
3536
}),
3637
adaptor: ({ state, width, data, style = {}, ...others }: AdaptorProps) => {
37-
const list = parseData(data).filter(node => NodeType.node === node.type);
38+
const list = (parseData(data) as INode[]).filter(node => NodeType.node === node.type);
3839
const expandedKeys = [] as string[];
3940
const children = list.map(({ state, value, children }, index) => {
4041
if (state === 'active') {

components/collapse/__tests__/index-spec.tsx

+38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
import React, { type ReactElement } from 'react';
2+
import type { Options } from 'cypress-image-snapshot';
23
import Collapse from '../index';
34
import '../style';
45

56
const Panel = Collapse.Panel;
67

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+
735
describe('Collapse', () => {
836
describe('render', () => {
937
it('[normal] Should render null', () => {
@@ -60,6 +88,16 @@ describe('Collapse', () => {
6088
cy.get('.next-collapse').should('have.length', 1);
6189
cy.get('.next-collapse-panel').should('have.length', 2);
6290
});
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+
});
63101
});
64102

65103
describe('defaultExpandedKeys', () => {

components/collapse/main.scss

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
border: $collapse-border-width solid $collapse-border-color;
1212
border-radius: $collapse-border-corner;
13+
overflow: hidden;
1314
&:focus,
1415
& *:focus {
1516
outline: 0;

cypress.config.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { defineConfig } from 'cypress';
2+
import { addMatchImageSnapshotPlugin } from 'cypress-image-snapshot/plugin';
23

34
export default defineConfig({
45
component: {
5-
setupNodeEvents(on) {
6+
setupNodeEvents(on, config) {
67
on('task', {
7-
'log': (message: string) => {
8+
log: (message: string) => {
89
// eslint-disable-next-line no-console
910
console.log(message);
1011
return null;
1112
},
12-
})
13+
});
14+
addMatchImageSnapshotPlugin(on, config);
1315
},
1416
devServer: {
1517
framework: 'react',

cypress/support/component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { cloneElement, type ReactElement } from 'react';
22
import { mount, type MountReturn } from 'cypress/react';
3+
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
34
import './commands';
45

56
function rerender<Props extends object>(tag: string, nextProps: Props) {
@@ -14,7 +15,7 @@ function triggerInputChange(subject: JQuery<HTMLElement>, value: string) {
1415
window.HTMLInputElement.prototype,
1516
'value'
1617
)?.set;
17-
nativeInputValueSetter?.call(element, value)
18+
nativeInputValueSetter?.call(element, value);
1819
element.dispatchEvent(new Event('input', { bubbles: true }));
1920
}
2021

@@ -29,6 +30,7 @@ declare global {
2930
}
3031
}
3132

33+
addMatchImageSnapshotCommand();
3234
Cypress.Commands.add('mount', mount);
3335
Cypress.Commands.add('rerender', rerender);
34-
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange)
36+
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange);

0 commit comments

Comments
 (0)