mirror of
https://github.com/apache/superset.git
synced 2026-07-23 23:25:45 +00:00
Compare commits
15 Commits
dependabot
...
enxdev/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbe994d337 | ||
|
|
00e4f90cac | ||
|
|
a9f3f9e0aa | ||
|
|
d9f42088ea | ||
|
|
ebc3b3efa7 | ||
|
|
76f33221ac | ||
|
|
a3057488cf | ||
|
|
a3c5d0356d | ||
|
|
60ef1ed246 | ||
|
|
624b5ec260 | ||
|
|
c288f3ffd6 | ||
|
|
e21fb5659a | ||
|
|
f80c46005e | ||
|
|
b5e76ccf35 | ||
|
|
ad53a4c744 |
@@ -48,10 +48,50 @@ const mockProps: TabsRendererProps = {
|
||||
tabBarPaddingLeft: 16,
|
||||
};
|
||||
|
||||
// Mirrors the tab label markup of Tab.tsx: the title lives in a
|
||||
// .dragdroppable-tab container and renders as a textarea via EditableTitle
|
||||
const draggableTabProps: TabsRendererProps = {
|
||||
...mockProps,
|
||||
editMode: true,
|
||||
tabItems: [
|
||||
{
|
||||
...mockTabItems[0],
|
||||
label: (
|
||||
<div className="dragdroppable-tab">
|
||||
<span className="editable-title">
|
||||
<textarea defaultValue="Tab 1" />
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
mockTabItems[1],
|
||||
],
|
||||
};
|
||||
|
||||
// jsdom implements no PointerEvent, so @dnd-kit's PointerSensor never activates
|
||||
class MockPointerEvent extends MouseEvent {
|
||||
isPrimary: boolean;
|
||||
|
||||
pointerId: number;
|
||||
|
||||
constructor(type: string, init: PointerEventInit = {}) {
|
||||
super(type, init);
|
||||
this.isPrimary = init.isPrimary ?? true;
|
||||
this.pointerId = init.pointerId ?? 1;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('TabsRenderer', () => {
|
||||
const { PointerEvent: OriginalPointerEvent } = globalThis;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
globalThis.PointerEvent = MockPointerEvent as typeof PointerEvent;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.PointerEvent = OriginalPointerEvent;
|
||||
});
|
||||
|
||||
test('renders tabs container with correct test attributes', () => {
|
||||
@@ -199,4 +239,29 @@ describe('TabsRenderer', () => {
|
||||
expect(screen.getByText('Tab 1 Content')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Tab 2 Content')).not.toBeInTheDocument(); // Not active
|
||||
});
|
||||
|
||||
test('drags from the tab title and shows the drag indicator only then', () => {
|
||||
render(<TabsRenderer {...draggableTabProps} />);
|
||||
const container = screen.getByTestId('dashboard-component-tabs');
|
||||
const title = container.querySelector('textarea') as HTMLTextAreaElement;
|
||||
|
||||
// At rest the title keeps the text cursor it sets on itself
|
||||
expect(container).not.toHaveStyleRule('cursor', 'move', {
|
||||
target: '.dragdroppable-tab *',
|
||||
});
|
||||
|
||||
// Pressing on the title and moving past the sensor's distance constraint
|
||||
// has to start a drag: the title covers most of the tab, so a tab that
|
||||
// cannot be dragged from there cannot really be dragged at all
|
||||
fireEvent.pointerDown(title, { button: 0, isPrimary: true, clientX: 0 });
|
||||
fireEvent.pointerMove(document, {
|
||||
button: 0,
|
||||
isPrimary: true,
|
||||
clientX: 50,
|
||||
});
|
||||
|
||||
expect(container).toHaveStyleRule('cursor', 'move', {
|
||||
target: '.dragdroppable-tab *',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,10 +72,16 @@ const StyledTabsContainer = styled.div<{ isDragging?: boolean }>`
|
||||
}
|
||||
}
|
||||
|
||||
/* Hide ink-bar during drag */
|
||||
${({ isDragging }) =>
|
||||
isDragging &&
|
||||
`
|
||||
/* Show the drag indicator during drag, over the tab title textarea too.
|
||||
The doubled parent outranks the title's own cursor; a single & loses. */
|
||||
&& .dragdroppable-tab * {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
/* Hide ink-bar during drag */
|
||||
.ant-tabs-card > .ant-tabs-nav .ant-tabs-ink-bar,
|
||||
.ant-tabs > .ant-tabs-nav .ant-tabs-ink-bar {
|
||||
display: none !important;
|
||||
|
||||
Reference in New Issue
Block a user