Skip to content

Commit

Permalink
chore: not add attr (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Sep 20, 2024
1 parent bea7eb4 commit 52f20db
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
4 changes: 0 additions & 4 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
containerProps.dir = 'rtl';
}

if (process.env.NODE_ENV !== 'production') {
containerProps['data-dev-offset-top'] = offsetTop;
}

return (
<div
ref={containerRef}
Expand Down
30 changes: 24 additions & 6 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ function genData(count) {
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
}

// Mock ScrollBar
jest.mock('../src/ScrollBar', () => {
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
const React = jest.requireActual('react');
return React.forwardRef((props, ref) => {
const { scrollOffset } = props;

return (
<div data-dev-offset={scrollOffset}>
<OriScrollBar {...props} ref={ref} />
</div>
);
});
});

describe('List.Scroll', () => {
let mockElement;
let boundingRect = {
Expand Down Expand Up @@ -525,13 +540,16 @@ describe('List.Scroll', () => {
await Promise.resolve();
});

expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
'data-dev-offset-top',
'0',
);
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
'data-dev-offset-top',
// inner
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute(
'data-dev-offset',
'10',
);

// outer
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
'data-dev-offset',
'0',
);
});
});
30 changes: 22 additions & 8 deletions tests/touch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import React from 'react';
import List from '../src';
import { spyElementPrototypes } from './utils/domHook';

// Mock ScrollBar
jest.mock('../src/ScrollBar', () => {
const OriScrollBar = jest.requireActual('../src/ScrollBar').default;
const React = jest.requireActual('react');
return React.forwardRef((props, ref) => {
const { scrollOffset } = props;

return (
<div data-dev-offset={scrollOffset}>
<OriScrollBar {...props} ref={ref} />
</div>
);
});
});

function genData(count) {
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
}
Expand Down Expand Up @@ -161,17 +176,16 @@ describe('List.Touch', () => {
await Promise.resolve();
});

expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute(
'data-dev-offset-top',
// inner not to be 0
expect(container.querySelectorAll('[data-dev-offset]')[0]).toHaveAttribute('data-dev-offset');
expect(container.querySelectorAll('[data-dev-offset]')[0]).not.toHaveAttribute(
'data-dev-offset',
'0',
);

// inner not to be 0
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute(
'data-dev-offset-top',
);
expect(container.querySelectorAll('[data-dev-offset-top]')[1]).not.toHaveAttribute(
'data-dev-offset-top',
// outer
expect(container.querySelectorAll('[data-dev-offset]')[1]).toHaveAttribute(
'data-dev-offset',
'0',
);
});
Expand Down

0 comments on commit 52f20db

Please sign in to comment.