|
| 1 | +import React from "react"; |
| 2 | +import { mount } from "enzyme"; |
| 3 | + |
| 4 | +import VerticalMode from "../VerticalMode"; |
| 5 | +import VerticalModeWhenUnslick from "../VerticalModeWhenUnslick"; |
| 6 | +import Slider from "../../src/slider"; |
| 7 | + |
| 8 | +describe("Vertical Mode", function () { |
| 9 | + it("should have 15 slides (3(preclone) + 6(actual) + 6(postclone))", function () { |
| 10 | + const wrapper = mount(<VerticalMode />); |
| 11 | + expect(wrapper.find(".slick-slide").length).toEqual(15); |
| 12 | + }); |
| 13 | + it("should have 9 clone slides", function () { |
| 14 | + const wrapper = mount(<VerticalMode />); |
| 15 | + expect(wrapper.find(".slick-cloned").length).toEqual(9); |
| 16 | + }); |
| 17 | + it("should have 3 active slide", function () { |
| 18 | + const wrapper = mount(<VerticalMode />); |
| 19 | + expect(wrapper.find(".slick-slide.slick-active").length).toEqual(3); |
| 20 | + }); |
| 21 | + it("should have 6 dots", function () { |
| 22 | + const wrapper = mount(<VerticalMode />); |
| 23 | + expect(wrapper.find(".slick-dots").children().length).toEqual(6); |
| 24 | + }); |
| 25 | + it("should have 1 active dot", function () { |
| 26 | + const wrapper = mount(<VerticalMode />); |
| 27 | + expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); |
| 28 | + }); |
| 29 | + it("should have a prev arrow", function () { |
| 30 | + const wrapper = mount(<VerticalMode />); |
| 31 | + expect(wrapper.find(".slick-prev").length).toEqual(1); |
| 32 | + }); |
| 33 | + it("should have a next arrow", function () { |
| 34 | + const wrapper = mount(<VerticalMode />); |
| 35 | + expect(wrapper.find(".slick-next").length).toEqual(1); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +describe("Vertical Mode when Unslick", function () { |
| 40 | + // ref: https://github.com/enzymejs/enzyme/issues/1940 |
| 41 | + // fix the 'offsetHeight' to 100px |
| 42 | + const originalOffsetHeight = Object.getOwnPropertyDescriptor( |
| 43 | + HTMLElement.prototype, |
| 44 | + "offsetHeight" |
| 45 | + ); |
| 46 | + beforeAll(() => { |
| 47 | + Object.defineProperty(HTMLElement.prototype, "offsetHeight", { |
| 48 | + configurable: true, |
| 49 | + value: 100, |
| 50 | + }); |
| 51 | + }); |
| 52 | + afterAll(() => { |
| 53 | + Object.defineProperty( |
| 54 | + HTMLElement.prototype, |
| 55 | + "offsetHeight", |
| 56 | + originalOffsetHeight |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should render correct height when only child", function () { |
| 61 | + const wrapper = mount( |
| 62 | + <Slider vertical> |
| 63 | + <div> |
| 64 | + <h3>1</h3> |
| 65 | + </div> |
| 66 | + </Slider> |
| 67 | + ); |
| 68 | + |
| 69 | + const slides = wrapper.find(".slick-slide"); |
| 70 | + const firstSlideHeight = slides.first().getDOMNode().offsetHeight; |
| 71 | + const totalHeight = parseInt(firstSlideHeight) * slides.length; |
| 72 | + const sliderTrackHeight = getComputedStyle( |
| 73 | + wrapper.find(".slick-track").getDOMNode() |
| 74 | + ).height; |
| 75 | + |
| 76 | + expect(totalHeight).toEqual(parseInt(sliderTrackHeight)); |
| 77 | + }); |
| 78 | + |
| 79 | + it("should render correct height when unslick", function () { |
| 80 | + const wrapper = mount(<VerticalModeWhenUnslick />); |
| 81 | + |
| 82 | + const slides = wrapper.find(".slick-slide"); |
| 83 | + const firstSlideHeight = slides.first().getDOMNode().offsetHeight; |
| 84 | + const totalHeight = parseInt(firstSlideHeight) * slides.length; |
| 85 | + const sliderTrackHeight = getComputedStyle( |
| 86 | + wrapper.find(".slick-track").getDOMNode() |
| 87 | + ).height; |
| 88 | + |
| 89 | + expect(totalHeight).toEqual(parseInt(sliderTrackHeight)); |
| 90 | + }); |
| 91 | + |
| 92 | + it("should have 2 slides (0(preclone) + 2(actual) + 0(postclone))", function () { |
| 93 | + const wrapper = mount(<VerticalModeWhenUnslick />); |
| 94 | + expect(wrapper.find(".slick-slide").length).toEqual(2); |
| 95 | + }); |
| 96 | + it("should have 0 clone slides", function () { |
| 97 | + const wrapper = mount(<VerticalModeWhenUnslick />); |
| 98 | + expect(wrapper.find(".slick-cloned").length).toEqual(0); |
| 99 | + }); |
| 100 | + it("should have 2 active slide", function () { |
| 101 | + const wrapper = mount(<VerticalModeWhenUnslick />); |
| 102 | + expect(wrapper.find(".slick-slide.slick-active").length).toEqual(2); |
| 103 | + }); |
| 104 | +}); |
0 commit comments