Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 7, 2024
1 parent 206d039 commit 0666187
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import * as ScrollArea from '@base_ui/react/ScrollArea';
import { expect } from 'chai';
import { screen } from '@mui/internal-test-utils';
import { createRenderer } from '#test-utils';
import { describeConformance } from '../../../test/describeConformance';

Expand All @@ -21,17 +22,19 @@ describe('<ScrollArea.Corner />', () => {
this.skip();
}

const { getByTestId } = await render(
<ScrollArea.Root>
<ScrollArea.Viewport data-testid="viewport" />
await render(
<ScrollArea.Root type="inlay" style={{ width: 200, height: 200 }}>
<ScrollArea.Viewport data-testid="viewport" style={{ width: '100%', height: '100%' }}>
<div style={{ width: 1000, height: 1000 }} />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar orientation="vertical" style={{ width: 10 }} />
<ScrollArea.Scrollbar orientation="horizontal" style={{ height: 10 }} />
<ScrollArea.Corner data-testid="corner" />
</ScrollArea.Root>,
);

const corner = getByTestId('corner');
const style = window.getComputedStyle(corner);
const corner = screen.getByTestId('corner');
const style = getComputedStyle(corner);

expect(style.getPropertyValue('--scroll-area-corner-width')).to.equal('10px');
expect(style.getPropertyValue('--scroll-area-corner-height')).to.equal('10px');
Expand Down
29 changes: 25 additions & 4 deletions packages/mui-base/src/ScrollArea/Root/ScrollAreaRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ const SCROLLBAR_HEIGHT = 15;
describe('<ScrollArea.Root />', () => {
const { render } = createRenderer();

beforeEach(() => {
const style = document.createElement('style');
style.innerHTML = `
*,
*::before,
*::after {
box-sizing: border-box;
}
`;
document.head.appendChild(style);
});

afterEach(() => {
document.head.innerHTML = '';
});

describeConformance(<ScrollArea.Root />, () => ({
refInstanceof: window.HTMLDivElement,
render,
Expand All @@ -25,7 +41,7 @@ describe('<ScrollArea.Root />', () => {
this.skip();
}

const { getByTestId } = await render(
await render(
<ScrollArea.Root style={{ width: VIEWPORT_SIZE, height: VIEWPORT_SIZE }}>
<ScrollArea.Viewport data-testid="viewport" style={{ width: '100%', height: '100%' }}>
<div style={{ width: SCROLLABLE_CONTENT_SIZE, height: SCROLLABLE_CONTENT_SIZE }} />
Expand All @@ -39,8 +55,8 @@ describe('<ScrollArea.Root />', () => {
</ScrollArea.Root>,
);

const verticalThumb = getByTestId('vertical-thumb');
const horizontalThumb = getByTestId('horizontal-thumb');
const verticalThumb = screen.getByTestId('vertical-thumb');
const horizontalThumb = screen.getByTestId('horizontal-thumb');

expect(getComputedStyle(verticalThumb).getPropertyValue('--scroll-area-thumb-height')).to.equal(
`${(VIEWPORT_SIZE / SCROLLABLE_CONTENT_SIZE) * VIEWPORT_SIZE}px`,
Expand Down Expand Up @@ -151,6 +167,7 @@ describe('<ScrollArea.Root />', () => {

await render(
<ScrollArea.Root
type="inlay"
gutter="both-edges"
style={{ width: VIEWPORT_SIZE, height: VIEWPORT_SIZE }}
>
Expand Down Expand Up @@ -180,7 +197,11 @@ describe('<ScrollArea.Root />', () => {
}

await render(
<ScrollArea.Root gutter="none" style={{ width: VIEWPORT_SIZE, height: VIEWPORT_SIZE }}>
<ScrollArea.Root
type="inlay"
gutter="none"
style={{ width: VIEWPORT_SIZE, height: VIEWPORT_SIZE }}
>
<ScrollArea.Viewport data-testid="viewport" style={{ width: '100%', height: '100%' }} />
<ScrollArea.Scrollbar
orientation="vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export function useScrollAreaViewport(params: useScrollAreaViewport.Parameters)
setCornerSize({ width: 0, height: 0 });
} else if (!scrollbarXHidden && !scrollbarYHidden) {
cornerEl.removeAttribute('hidden');
setCornerSize({ width: cornerEl.offsetWidth, height: cornerEl.offsetHeight });
const width = scrollbarYRef.current?.offsetWidth || 0;
const height = scrollbarXRef.current?.offsetHeight || 0;
setCornerSize({ width, height });
}
}
});
Expand Down

0 comments on commit 0666187

Please sign in to comment.