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 alibaba-fusion#3277

fix(Collapse): Internal elements need to apply the radius configuration of external elements, close alibaba-fusion#3277
  • Loading branch information
泊淞 committed Dec 5, 2024
1 parent 09bf93a commit cb6c9ce
Show file tree
Hide file tree
Showing 9 changed files with 871 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__/**
11 changes: 10 additions & 1 deletion components/collapse/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { type ReactElement } from 'react';
import Collapse from '../index';
import '../style';

const Panel = Collapse.Panel;

describe('Collapse', () => {
Expand Down Expand Up @@ -60,6 +59,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>
);
cy.compareSnapshot('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
33 changes: 31 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,21 +15,49 @@ 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 }));
}

function compareSnapshot(
subject: Cypress.PrevSubjectMap<void>[Cypress.PrevSubject],
componentName: string,
commandOptions?: object
) {
const customSnapshotsDir = `/components/${componentName}/__tests__/snapshots/__base__`;
const customDiffDir = `/components/${componentName}/__tests__/snapshots/__diff__`;
const targetOptions = Object.assign(
{
customSnapshotsDir,
customDiffDir,
},
commandOptions
);
const target = subject ? cy.wrap(subject) : cy;
return target.matchImageSnapshot(targetOptions);
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount;
rerender: typeof rerender;
triggerInputChange: (value: string) => void;
matchImageSnapshot: (name?: string | object, options?: object) => void;
compareSnapshot: (componentName: string, commandOptions?: object) => void;
}
}
}

Cypress.Commands.add('mount', mount);
Cypress.Commands.add('rerender', rerender);
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange)
Cypress.Commands.add('triggerInputChange', { prevSubject: 'element' }, triggerInputChange);
addMatchImageSnapshotCommand();
Cypress.Commands.add(
'compareSnapshot',
{
prevSubject: ['optional', 'element', 'window', 'document'],
},
compareSnapshot
);
13 changes: 13 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ declare module 'react-lifecycles-compat' {

export function polyfill<C extends ComponentType>(Component: C): C;
}

declare module 'cypress-image-snapshot/plugin' {
export function addMatchImageSnapshotPlugin(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
): void;
}
declare module 'cypress-image-snapshot/command' {
export function addMatchImageSnapshotCommand(
maybeName?: string | object,
maybeOptions?: object
): void;
}
Loading

0 comments on commit cb6c9ce

Please sign in to comment.