|
| 1 | +import React from "react"; |
| 2 | +import { render, unmountComponentAtNode } from "react-dom"; |
| 3 | +import { Scrollbar } from "react-scrollbars-custom"; |
| 4 | + |
| 5 | +export default function createTests(scrollbarWidth) { |
| 6 | + describe("getset", () => { |
| 7 | + let node; |
| 8 | + beforeEach(() => { |
| 9 | + node = document.createElement("div"); |
| 10 | + document.body.appendChild(node); |
| 11 | + }); |
| 12 | + afterEach(() => { |
| 13 | + unmountComponentAtNode(node); |
| 14 | + document.body.removeChild(node); |
| 15 | + }); |
| 16 | + |
| 17 | + let sbRender = (cb) => render(<Scrollbar style={ {width: 100, height: 100} }> |
| 18 | + <div style={ {width: 200, height: 200} }></div> |
| 19 | + </Scrollbar>, |
| 20 | + node, |
| 21 | + cb); |
| 22 | + |
| 23 | + describe("getters", function () { |
| 24 | + it("should return scrollTop", |
| 25 | + (done) => sbRender(function () { |
| 26 | + this.scrollTop = 50; |
| 27 | + expect(this.scrollTop).to.be.equal(50); |
| 28 | + expect(this.content.scrollTop).to.be.equal(50); |
| 29 | + |
| 30 | + done(); |
| 31 | + })); |
| 32 | + |
| 33 | + it("should return scrollLeft", |
| 34 | + (done) => sbRender(function () { |
| 35 | + this.scrollLeft = 50; |
| 36 | + expect(this.scrollLeft).to.be.equal(50); |
| 37 | + expect(this.content.scrollLeft).to.be.equal(50); |
| 38 | + |
| 39 | + done(); |
| 40 | + })); |
| 41 | + |
| 42 | + it("should return scrollHeight", |
| 43 | + (done) => sbRender(function () { |
| 44 | + expect(this.scrollHeight).to.be.equal(200); |
| 45 | + expect(this.content.scrollHeight).to.be.equal(200); |
| 46 | + |
| 47 | + done(); |
| 48 | + })); |
| 49 | + |
| 50 | + it("should return scrollWidth", |
| 51 | + (done) => sbRender(function () { |
| 52 | + expect(this.scrollWidth).to.be.equal(200); |
| 53 | + expect(this.content.scrollWidth).to.be.equal(200); |
| 54 | + |
| 55 | + done(); |
| 56 | + })); |
| 57 | + |
| 58 | + it("should return clientHeight", |
| 59 | + (done) => sbRender(function () { |
| 60 | + expect(this.clientHeight).to.be.equal(92); |
| 61 | + expect(this.content.clientHeight).to.be.equal(92); |
| 62 | + |
| 63 | + done(); |
| 64 | + })); |
| 65 | + |
| 66 | + it("should return clientWidth", |
| 67 | + (done) => sbRender(function () { |
| 68 | + expect(this.clientWidth).to.be.equal(92); |
| 69 | + expect(this.content.clientWidth).to.be.equal(92); |
| 70 | + |
| 71 | + done(); |
| 72 | + })); |
| 73 | + }); |
| 74 | + |
| 75 | + describe("setters", function () { |
| 76 | + it("scrollTop/scrollToTop/scrollToBottom", |
| 77 | + (done) => sbRender(function () { |
| 78 | + this.scrollTop = 50; |
| 79 | + expect(this.scrollTop).to.be.equal(50); |
| 80 | + expect(this.content.scrollTop).to.be.equal(50); |
| 81 | + this.scrollToTop(); |
| 82 | + expect(this.content.scrollTop).to.be.equal(0); |
| 83 | + this.scrollToBottom(); |
| 84 | + expect(this.content.scrollTop).to.be.equal(this.content.scrollHeight - this.content.clientHeight); |
| 85 | + |
| 86 | + done(); |
| 87 | + })); |
| 88 | + |
| 89 | + it("scrollLeft/scrollToLeft/scrollToRight", |
| 90 | + (done) => sbRender(function () { |
| 91 | + this.scrollLeft = 50; |
| 92 | + expect(this.scrollLeft).to.be.equal(50); |
| 93 | + expect(this.content.scrollLeft).to.be.equal(50); |
| 94 | + this.scrollToLeft(); |
| 95 | + expect(this.content.scrollLeft).to.be.equal(0); |
| 96 | + this.scrollToRight(); |
| 97 | + expect(this.content.scrollLeft).to.be.equal(this.content.scrollWidth - this.content.clientWidth); |
| 98 | + |
| 99 | + done(); |
| 100 | + })); |
| 101 | + |
| 102 | + it("scrollHeight should not be settable", |
| 103 | + (done) => sbRender(function () { |
| 104 | + expect(() => {this.scrollHeight = 0;}).to.throw(TypeError); |
| 105 | + |
| 106 | + done(); |
| 107 | + })); |
| 108 | + |
| 109 | + it("scrollWidth should not be settable", |
| 110 | + (done) => sbRender(function () { |
| 111 | + expect(() => {this.scrollWidth = 0;}).to.throw(TypeError); |
| 112 | + |
| 113 | + done(); |
| 114 | + })); |
| 115 | + |
| 116 | + it("clientHeight should not be settable", |
| 117 | + (done) => sbRender(function () { |
| 118 | + expect(() => {this.clientHeight = 0;}).to.throw(TypeError); |
| 119 | + |
| 120 | + done(); |
| 121 | + })); |
| 122 | + |
| 123 | + it("clientWidth should not be settable", |
| 124 | + (done) => sbRender(function () { |
| 125 | + expect(() => {this.clientWidth = 0;}).to.throw(TypeError); |
| 126 | + |
| 127 | + done(); |
| 128 | + })); |
| 129 | + }); |
| 130 | + }); |
| 131 | +} |
0 commit comments