/* eslint-disable */
import * as React from "react"
import { mount } from "enzyme"
import TestRenderer from "react-test-renderer"
import sinon from "sinon"
import Table from ".."
window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}))
const dataSource = [
{
one: "阿萨德",
two: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
four: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
three: "阿萨德阿萨德阿萨德阿萨德阿萨德",
},
{
one: "阿萨德",
two: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
four: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
three: "阿萨德阿萨德阿萨德阿萨德阿萨德",
},
{
one: "阿萨德",
two: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
four: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
three: "阿萨德阿萨德阿萨德阿萨德阿萨德",
},
{
one: "阿萨德",
two: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
four: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
three: "阿萨德阿萨德阿萨德阿萨德阿萨德",
},
{
one: "阿萨德",
two: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
four: "阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德阿萨德",
three: "阿萨德阿萨德阿萨德阿萨德阿萨德",
},
]
export interface IBaseObject {
[key: string]: any
}
describe("Table", () => {
beforeAll(() => {
/**
* https://stackoverflow.com/a/40006663
* 通过 mock `getBoundingClientRect`,之后运行的所有 `getBoundingClientRect` 都会返回这同一个值。
*/
Element.prototype.getBoundingClientRect = jest.fn(() => {
return {
width: 500,
height: 600,
top: 0,
left: 0,
bottom: 0,
right: 0,
x: 0,
y: 0,
toJSON: () => {},
}
})
})
it("headerAffixed 检测", () => {
const wrapper = mount(
)
// @ts-ignore
global.innerWidth = 500
// @ts-ignore
global.dispatchEvent(new Event("resize"))
// @ts-ignore
global.dispatchEvent(new Event("scroll"))
wrapper.instance().handleMainTableScroll()
wrapper.instance().componentWillUnmount()
})
// it("height prop 验证", () => {
// const stub = sinon.stub(console, 'error')
// const wrapper = mount(
//
// )
// expect(stub.calledOnce).toBe(true)
// stub.restore()
// })
it("height 与 headerAffixed 不能同时使用 验证", () => {
const stub = sinon.stub(console, "error")
mount(
)
expect(stub.calledOnce).toBe(true)
stub.restore()
})
it("height 检测", () => {
const wrapper = mount(
)
// @ts-ignore
global.innerWidth = 500
// @ts-ignore
global.innerHeight = 500
// @ts-ignore
global.dispatchEvent(new Event("resize"))
// @ts-ignore
global.dispatchEvent(new Event("scroll"))
wrapper.instance().handleMainTableScroll()
})
// it("Column width prop 验证", () => {
// const stub = sinon.stub(console, 'error')
// const wrapper = mount(
//
// )
// expect(stub.calledOnce).toBe(true)
// stub.restore()
// })
it("Column width 在 fixed 时必须设置 验证", () => {
const stub = sinon.stub(console, "error")
mount(
)
expect(stub.calledOnce).toBe(true)
stub.restore()
})
it("loading 快照", () => {
const wrapper = TestRenderer.create(
)
expect(wrapper).toMatchSnapshot()
})
it("合并单元格快照", () => {
const wrapper = TestRenderer.create(
{
if (rowIndex === 0 && colIndex === 0) {
return {
rowSpan: 2,
colSpan: 2,
}
}
if (rowIndex === 3 && colIndex === 2) {
return {
rowSpan: 2,
colSpan: 1,
}
}
if (rowIndex === 3 && colIndex === 3) {
return {
rowSpan: 2,
colSpan: 1,
}
}
if (rowIndex === 2 && colIndex === 0) {
return {
rowSpan: 1,
colSpan: 1,
}
}
return {}
}}
>
)
expect(wrapper).toMatchSnapshot()
})
})