Skip to content

Commit

Permalink
fix(Collapse): Internal elements need to apply the radius configurati…
Browse files Browse the repository at this point in the history
…on of external elements, close #3277
  • Loading branch information
泊淞 committed Dec 5, 2024
1 parent 09bf93a commit 39eba4e
Show file tree
Hide file tree
Showing 9 changed files with 873 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ gemini-report/
*.log
.DS_Store
src/core-temp

# tests snapshots diff
components/**/__tests__/snapshots/__diff__/**
3 changes: 2 additions & 1 deletion components/collapse/__docs__/adaptor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Collapse } from '@alifd/next';
import { Types, parseData, NodeType } from '@alifd/adaptor-helper';
import type { INode } from '@alifd/adaptor-helper/types/parse-data';

interface AdaptorProps {
state: string;
Expand Down Expand Up @@ -34,7 +35,7 @@ export default {
},
}),
adaptor: ({ state, width, data, style = {}, ...others }: AdaptorProps) => {
const list = parseData(data).filter(node => NodeType.node === node.type);
const list = (parseData(data) as INode[]).filter(node => NodeType.node === node.type);
const expandedKeys = [] as string[];
const children = list.map(({ state, value, children }, index) => {
if (state === 'active') {
Expand Down
38 changes: 38 additions & 0 deletions components/collapse/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import React, { type ReactElement } from 'react';
import type { Options } from 'cypress-image-snapshot';
import Collapse from '../index';
import '../style';

const Panel = Collapse.Panel;

class CompareSnapshot {
customSnapshotsDir: string;
customDiffDir: string;
constructor(options: { componentName: string }) {
const { componentName } = options;
this.customSnapshotsDir = `/components/${componentName}/__tests__/snapshots/__base__`;
this.customDiffDir = `/components/${componentName}/__tests__/snapshots/__diff__`;
}
compare(
subject: Cypress.Chainable<JQuery<HTMLElement>>,
nameOrOptions?: string | Options,
options?: Options
) {
const commandOptions = typeof nameOrOptions === 'string' ? options : nameOrOptions;
const targetOptions = Object.assign(
{
customSnapshotsDir: this.customSnapshotsDir,
customDiffDir: this.customDiffDir,
},
commandOptions
);
const target = subject ? subject : cy;
return target.matchImageSnapshot(targetOptions);
}
}
const collapseCompareSnapshot = new CompareSnapshot({ componentName: 'collapse' });

describe('Collapse', () => {
describe('render', () => {
it('[normal] Should render null', () => {
Expand Down Expand Up @@ -60,6 +88,16 @@ describe('Collapse', () => {
cy.get('.next-collapse').should('have.length', 1);
cy.get('.next-collapse-panel').should('have.length', 2);
});

it('should render with proper border-radius and overflow hidden', () => {
cy.mount(
<Collapse style={{ borderRadius: '50px' }}>
<Panel title="Pannel Title">Pannel Content</Panel>
<Panel title="Pannel Title">Pannel Content</Panel>
</Collapse>
);
collapseCompareSnapshot.compare(cy.get('.next-collapse'));
});
});

describe('defaultExpandedKeys', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions components/collapse/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

border: $collapse-border-width solid $collapse-border-color;
border-radius: $collapse-border-corner;
overflow: hidden;
&:focus,
& *:focus {
outline: 0;
Expand Down
8 changes: 5 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { defineConfig } from 'cypress';
import { addMatchImageSnapshotPlugin } from 'cypress-image-snapshot/plugin';

export default defineConfig({
component: {
setupNodeEvents(on) {
setupNodeEvents(on, config) {
on('task', {
'log': (message: string) => {
log: (message: string) => {
// eslint-disable-next-line no-console
console.log(message);
return null;
},
})
});
addMatchImageSnapshotPlugin(on, config);
},
devServer: {
framework: 'react',
Expand Down
6 changes: 4 additions & 2 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cloneElement, type ReactElement } from 'react';
import { mount, type MountReturn } from 'cypress/react';
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
import './commands';

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

Expand All @@ -29,6 +30,7 @@ declare global {
}
}

addMatchImageSnapshotCommand();
Cypress.Commands.add('mount', mount);
Cypress.Commands.add('rerender', rerender);
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange)
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange);
Loading

0 comments on commit 39eba4e

Please sign in to comment.