Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3626: Splitter/ScrollPanel Jest tests #3627

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions components/lib/scrollpanel/ScrollPanel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import '@testing-library/jest-dom';
import { act, render } from '@testing-library/react';
import * as React from 'react';
import { snapshot } from '../../test';
import { ScrollPanel } from './ScrollPanel';

describe('ScrollPanel', () => {
snapshot(
<>
<ScrollPanel id="scrollpanel" style={{ width: '100%', height: '200px' }} className="jest">
<div style={{ padding: '1em', lineHeight: '1.5' }}>
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever
anything stands against the good of the family. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not
intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect,
but given to ruthless violence whenever anything stands against the good of the family.
</div>
</ScrollPanel>
</>,
'ScrollPanel full settings'
);
test('refresh method', async () => {
// Arrange
const ref = React.createRef();
const { container } = render(
<ScrollPanel id="scrollpanel" style={{ width: '100%', height: '200px' }} className="jest" ref={ref}>
<div style={{ padding: '1em', lineHeight: '1.5' }}>
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever
anything stands against the good of the family. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not
intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect,
but given to ruthless violence whenever anything stands against the good of the family.
</div>
</ScrollPanel>
);

// Act
act(() => {
ref.current.refresh();
ref.current.getElement();
ref.current.getContent();
ref.current.getXBar();
ref.current.getYBar();
});

// Assert
expect(container).toMatchSnapshot();
});
});
61 changes: 61 additions & 0 deletions components/lib/scrollpanel/__snapshots__/ScrollPanel.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ScrollPanel ScrollPanel full settings 1`] = `
<div>
<div
class="p-scrollpanel p-component jest"
id="scrollpanel"
style="width: 100%; height: 200px;"
>
<div
class="p-scrollpanel-wrapper"
>
<div
class="p-scrollpanel-content"
>
<div
style="padding: 1em; line-height: 1.5;"
>
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
</div>
</div>
</div>
<div
class="p-scrollpanel-bar p-scrollpanel-bar-x"
/>
<div
class="p-scrollpanel-bar p-scrollpanel-bar-y"
/>
</div>
</div>
`;

exports[`ScrollPanel refresh method 1`] = `
<div>
<div
class="p-scrollpanel p-component jest"
id="scrollpanel"
style="width: 100%; height: 200px;"
>
<div
class="p-scrollpanel-wrapper"
>
<div
class="p-scrollpanel-content"
>
<div
style="padding: 1em; line-height: 1.5;"
>
The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
</div>
</div>
</div>
<div
class="p-scrollpanel-bar p-scrollpanel-bar-x"
/>
<div
class="p-scrollpanel-bar p-scrollpanel-bar-y"
/>
</div>
</div>
`;
51 changes: 51 additions & 0 deletions components/lib/splitter/Splitter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import '@testing-library/jest-dom';
import { snapshot } from '../../test';
import { Splitter, SplitterPanel } from './Splitter';

describe('Splitter', () => {
snapshot(
<>
<Splitter style={{ height: '300px' }} className="mb-5">
<SplitterPanel className="flex align-items-center justify-content-center">Panel 1</SplitterPanel>
<SplitterPanel className="flex align-items-center justify-content-center">Panel 2</SplitterPanel>
</Splitter>
</>,
'Splitter requires two SplitterPanel components to wrap.'
);
snapshot(
<>
<Splitter style={{ height: '300px' }} layout="vertical">
<SplitterPanel>Panel 1</SplitterPanel>
<SplitterPanel>Panel 2</SplitterPanel>
</Splitter>
</>,
'Vertical layout'
);
snapshot(
<>
<Splitter style={{ height: '300px' }}>
<SplitterPanel className="flex align-items-center justify-content-center" size={20} minSize={10}>
Panel 1
</SplitterPanel>
<SplitterPanel size={80}>
<Splitter layout="vertical">
<SplitterPanel className="flex align-items-center justify-content-center" size={15}>
Panel 2
</SplitterPanel>
<SplitterPanel size={85}>
<Splitter>
<SplitterPanel className="flex align-items-center justify-content-center" size={20}>
Panel 3
</SplitterPanel>
<SplitterPanel className="flex align-items-center justify-content-center" size={80}>
Panel 4
</SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
</SplitterPanel>
</Splitter>
</>,
'Nested'
);
});
137 changes: 137 additions & 0 deletions components/lib/splitter/__snapshots__/Splitter.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Splitter Nested 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-horizontal"
style="height: 300px;"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(10% - 4px);"
>
Panel 1
</div>
<div
class="p-splitter-gutter"
style="width: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
<div
class="p-splitter-panel p-splitter-panel-nested"
style="flex-basis: calc(40% - 4px);"
>
<div
class="p-splitter p-component p-splitter-vertical"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(7.5% - 4px);"
>
Panel 2
</div>
<div
class="p-splitter-gutter"
style="height: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
<div
class="p-splitter-panel p-splitter-panel-nested"
style="flex-basis: calc(42.5% - 4px);"
>
<div
class="p-splitter p-component p-splitter-horizontal"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(10% - 4px);"
>
Panel 3
</div>
<div
class="p-splitter-gutter"
style="width: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(40% - 4px);"
>
Panel 4
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;

exports[`Splitter Splitter requires two SplitterPanel components to wrap. 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-horizontal mb-5"
style="height: 300px;"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(50% - 4px);"
>
Panel 1
</div>
<div
class="p-splitter-gutter"
style="width: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(50% - 4px);"
>
Panel 2
</div>
</div>
</div>
`;

exports[`Splitter Vertical layout 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-vertical"
style="height: 300px;"
>
<div
class="p-splitter-panel"
style="flex-basis: calc(50% - 4px);"
>
Panel 1
</div>
<div
class="p-splitter-gutter"
style="height: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
<div
class="p-splitter-panel"
style="flex-basis: calc(50% - 4px);"
>
Panel 2
</div>
</div>
</div>
`;
Loading