Skip to content

Commit fe1f2c3

Browse files
泊淞zyliang96
泊淞
authored andcommitted
fix(Collapse): Internal elements need to apply the radius configuration of external elements, close #3277
1 parent 438d47a commit fe1f2c3

File tree

10 files changed

+877
-8
lines changed

10 files changed

+877
-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

+13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React, { type ReactElement } from 'react';
2+
import { CompareSnapshot } from '../../util/__tests__/common/snapshot';
23
import Collapse from '../index';
34
import '../style';
45

56
const Panel = Collapse.Panel;
67

8+
const collapseCompareSnapshot = new CompareSnapshot({ componentName: 'collapse' });
9+
710
describe('Collapse', () => {
811
describe('render', () => {
912
it('[normal] Should render null', () => {
@@ -60,6 +63,16 @@ describe('Collapse', () => {
6063
cy.get('.next-collapse').should('have.length', 1);
6164
cy.get('.next-collapse-panel').should('have.length', 2);
6265
});
66+
67+
it('should render with proper border-radius and overflow hidden', () => {
68+
cy.mount(
69+
<Collapse style={{ borderRadius: '50px' }}>
70+
<Panel title="Pannel Title">Pannel Content</Panel>
71+
<Panel title="Pannel Title">Pannel Content</Panel>
72+
</Collapse>
73+
);
74+
collapseCompareSnapshot.compare(cy.get('.next-collapse'));
75+
});
6376
});
6477

6578
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Options } from 'cypress-image-snapshot';
2+
3+
export class CompareSnapshot {
4+
customSnapshotsDir: string;
5+
customDiffDir: string;
6+
constructor(options: { componentName: string }) {
7+
const { componentName } = options;
8+
this.customSnapshotsDir = `/components/${componentName}/__tests__/snapshots/__base__`;
9+
this.customDiffDir = `/components/${componentName}/__tests__/snapshots/__diff__`;
10+
}
11+
compare(
12+
subject: Cypress.Chainable<JQuery<HTMLElement>>,
13+
nameOrOptions?: string | Options,
14+
options?: Options
15+
) {
16+
const commandOptions = typeof nameOrOptions === 'string' ? options : nameOrOptions;
17+
const targetOptions = Object.assign(
18+
{
19+
customSnapshotsDir: this.customSnapshotsDir,
20+
customDiffDir: this.customDiffDir,
21+
},
22+
commandOptions
23+
);
24+
const target = subject ? subject : cy;
25+
return target.matchImageSnapshot(targetOptions);
26+
}
27+
}

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)