/**
* @jest-environment jsdom
*/
import React, { useState } from 'react';
import TestRenderer from 'react-test-renderer';
import { screen, render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import Github, { GithubPlacement } from '../packages/color-github/src';
it('Github', async () => {
const MyComponent = () => {
return ;
};
const component = TestRenderer.create();
let tree = component.toJSON();
if (tree && !Array.isArray(tree)) {
expect(tree.type).toEqual('div');
expect(tree.props.className).toEqual('w-color-swatch w-color-github');
expect(tree.props.style).toMatchObject({
width: 200,
borderRadius: 4,
background: 'var(--github-background-color)',
boxShadow: 'var(--github-box-shadow)',
border: 'var(--github-border)',
position: 'relative',
padding: 5,
});
if (tree.children) {
expect(tree.children.length).toEqual(18);
tree.children.forEach((child) => {
if (typeof child === 'object') {
expect(child.type).toEqual('div');
}
});
}
}
});
it('Github mouseOut', async () => {
const handleChange = jest.fn((color) => color.hex);
const MyComponent = () => {
return ;
};
const { getByTitle } = render();
const elm = getByTitle('#F44E3B');
fireEvent.click(elm);
expect(handleChange).toHaveReturnedWith('#f44e3b');
});
it('Github mouseEnter/mouseLeave checked', async () => {
const handleChange = jest.fn((color) => color.hex);
const { getByTitle } = render(
,
);
const elm = getByTitle('#F44E3B');
fireEvent.mouseEnter(elm);
expect(elm.style.outline).toEqual('#fff solid 2px');
fireEvent.mouseLeave(elm);
expect(elm.style.outline).toEqual('#fff solid 2px');
expect(handleChange).not.toHaveReturned();
});
it('Github rectRender props', async () => {
const { getByTitle } = render(
}
/>,
);
const elm = getByTitle('#F44E3B');
expect(elm.dataset.uiw).toEqual('title');
});
it('Github mouseEnter/mouseLeave color = undefined', async () => {
const handleChange = jest.fn((color) => color.hex);
const { getByTitle } = render();
const elm = getByTitle('#F44E3B');
fireEvent.mouseEnter(elm);
expect(elm.style.outline).toEqual('#fff solid 2px');
fireEvent.mouseLeave(elm);
expect(elm.style.outline).toEqual('initial');
expect(handleChange).not.toHaveReturned();
});
it('Github GithubPlacement.Left', async () => {
const handleChange = jest.fn((color) => color.hex);
const { getByTitle, getByTestId } = render(
,
);
// const arr = getByTitle('#F44E3B').previousSibling;
expect(getByTitle('#F44E3B').title).toEqual('#F44E3B');
const elm = getByTestId('test-element');
expect(elm.firstElementChild?.getAttribute('style')).toEqual(
'border-style: solid; position: absolute; border-width: 8px 8px 8px 0px; left: -8px; top: 50%; margin-top: -8px;',
);
expect(elm.firstElementChild).toHaveProperty(['style', 'left'], '-8px');
expect(elm.firstElementChild).toHaveProperty(['style', 'top'], '50%');
expect(elm.firstElementChild).toHaveProperty(['style', 'borderStyle'], 'solid');
expect(elm.firstElementChild).toHaveProperty(['style', 'position'], 'absolute');
expect(elm.firstElementChild).toHaveProperty(['style', 'borderWidth'], '8px 8px 8px 0px');
expect(elm.firstElementChild).toHaveProperty(['style', 'marginTop'], '-8px');
// expect(elm.firstElementChild).toHaveProperty(['style', 'borderColor'], 'transparent var(--github-arrow-border-color) transparent transparent')
expect(handleChange).not.toHaveReturned();
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 8px 0',
borderColor: 'transparent var(--github-arrow-border-color) transparent transparent',
left: -8,
top: '50%',
marginTop: -8,
});
}
});
it('Github GithubPlacement.LeftTop', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 8px 0',
borderColor: 'transparent var(--github-arrow-border-color) transparent transparent',
left: -8,
top: 5,
});
}
});
it('Github GithubPlacement.LeftBottom', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 8px 0',
borderColor: 'transparent var(--github-arrow-border-color) transparent transparent',
left: -8,
top: '100%',
});
}
});
it('Github GithubPlacement.Right', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 0 8px 8px',
borderColor: 'transparent transparent transparent var(--github-arrow-border-color)',
right: -8,
top: '50%',
marginTop: -8,
});
}
});
it('Github GithubPlacement.RightTop', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 0 8px 8px',
borderColor: 'transparent transparent transparent var(--github-arrow-border-color)',
right: -8,
top: 5,
});
}
});
it('Github GithubPlacement.RightBottom', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 0 8px 8px',
borderColor: 'transparent transparent transparent var(--github-arrow-border-color)',
top: '100%',
marginTop: -21,
right: -8,
});
}
});
it('Github GithubPlacement.Top', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '0 8px 8px',
borderColor: 'transparent transparent var(--github-arrow-border-color)',
left: '50%',
top: -8,
marginLeft: -8,
});
}
});
it('Github GithubPlacement.TopLeft', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '0 8px 8px',
borderColor: 'transparent transparent var(--github-arrow-border-color)',
left: 7,
top: -8,
});
}
});
it('Github GithubPlacement.TopRight', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '0 8px 8px',
borderColor: 'transparent transparent var(--github-arrow-border-color)',
right: 10,
top: -8,
});
}
});
it('Github GithubPlacement.Bottom', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 0',
borderColor: 'var(--github-arrow-border-color) transparent transparent',
left: '50%',
top: '100%',
marginLeft: -8,
});
}
});
it('Github GithubPlacement.BottomLeft', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 0',
borderColor: 'var(--github-arrow-border-color) transparent transparent',
top: '100%',
left: 7,
});
}
});
it('Github GithubPlacement.BottomRight', async () => {
const component = TestRenderer.create(
,
);
const tree = component.toJSON();
if (tree && !Array.isArray(tree) && tree.children && tree.children[0]) {
const child = (tree.children[0] as any)?.props.style;
expect(child).toMatchObject({
borderStyle: 'solid',
position: 'absolute',
borderWidth: '8px 8px 0',
borderColor: 'var(--github-arrow-border-color) transparent transparent',
top: '100%',
right: 10,
});
}
});