Skip to content
Permalink
Browse files

1.0.0

  • Loading branch information...
piotrzdziarski committed May 18, 2019
1 parent c27c0eb commit 256b0a6f3a433d810fee30a1c8e6f9d70ee4b6e8
@@ -1,9 +1,7 @@
# React Fullscreen Lightbox Basic
## Version - 0.9.2
## Version - 1.0.0
## Description

In development

Fullscreen Lightbox is plugin for displaying images and videos in clean overlaying box.

Website: https://fslightbox.com
@@ -56,6 +54,9 @@ export default App;
```

## Demo
Available at: https://fslightbox.com/react

## Browser Compatibility

| Browser | Works? |

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more.

@@ -1,7 +1,7 @@
{
"name": "fslightbox-react",
"version": "0.9.2",
"description": "React version of Fullscreen Lightbox",
"version": "1.0.0",
"description": "React version of Fullscreen Lightbox.",
"main": "index.js",
"scripts": {
"test": "jest",
@@ -51,6 +51,7 @@
"@babel/preset-react": "^7.0.0",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.5",
"babel-polyfill": "^6.26.0",
"copy-webpack-plugin": "^5.0.3",
"core-js": "^3.0.1",
"css-loader": "^2.1.0",
@@ -73,5 +74,6 @@
"webpack": "^4.30.0",
"webpack-cli": "^3.3.1",
"webpack-dev-server": "^3.3.1"
}
},
"dependencies": {}
}
@@ -1,4 +1,5 @@
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'babel-polyfill';

configure({ adapter: new Adapter() });
@@ -46,7 +46,7 @@ class FsLightbox extends Component {
videosPosters: (this.props.videosPosters) ? this.props.videosPosters : [],
maxSourceWidth: 0,
maxSourceHeight: 0,
slideDistance: (this.props.slideDistance) ? this.props.slideDistance : 1.3,
slideDistance: (this.props.slideDistance) ? this.props.slideDistance : 0.3,
};
}

@@ -59,6 +59,7 @@ export function SourceTypeGetter(
return;
}
if (xhr.status !== 200 && xhr.status !== 206) {
// we are setting isResolved to true so readyState 4 won't be called before forwarding logic
isResolved = true;
resolveInvalidType();
return;
@@ -1,6 +1,5 @@
/**
* @class SourceHolderTransformer
* @param { FsLightbox.sourcesData.slideDistance } slideDistance
* @constructor
*/
export function SourceHolderTransformer({ sourcesData: { slideDistance } }) {
let sourceHolderStyle;
@@ -29,6 +28,6 @@ export function SourceHolderTransformer({ sourcesData: { slideDistance } }) {
sourceHolderStyle.transform = getTransformStringForValue(getDefaultTransformDistance());
};

const getDefaultTransformDistance = () => slideDistance * window.innerWidth;
const getDefaultTransformDistance = () => (1 + slideDistance) * window.innerWidth;
const getTransformStringForValue = (value) => `translate(${ value + transformValue }px,0)`;
}
@@ -125,7 +125,7 @@ describe('sourcesData', () => {
});

it('should be equal 1.3', () => {
expect(fsLightbox.sourcesData.slideDistance).toBe(1.3);
expect(fsLightbox.sourcesData.slideDistance).toBe(0.3);
});
});

@@ -0,0 +1,136 @@
import React from 'react';
import { mount } from "enzyme";
import FsLightbox from "../../src/FsLightbox";
import { CONTAINER_FADE_OUT_TIME } from "../../src/constants/coreConstants";

describe('onInit', () => {
let fsLightbox;
let onInit;

beforeAll(() => {
onInit = jest.fn();
fsLightbox = mount(<FsLightbox
toggler={ false }
onInit={ onInit }
urls={ ['images/1.jpg'] }
/>);
fsLightbox.setProps({
toggler: true
})
});

it('should call onInit', () => {
expect(onInit).toBeCalledTimes(1);
});
});

describe('onOpen - called on every open', () => {
let fsLightbox;
let onOpen;

beforeAll(() => {
onOpen = jest.fn();
jest.useFakeTimers();
fsLightbox = mount(<FsLightbox
toggler={ false }
onOpen={ onOpen }
urls={ ['images/1.jpg'] }
/>);
});

it('should call onOpen', () => {
fsLightbox.setProps({
toggler: true
});
expect(onOpen).toBeCalledTimes(1);
});

it('should still call onOpen one time after close', () => {
fsLightbox.setProps({
toggler: false
});
jest.runTimersToTime(CONTAINER_FADE_OUT_TIME);
expect(onOpen).toBeCalledTimes(1);
});

it('should call onOpen twice after reopening', () => {
fsLightbox.setProps({
toggler: true
});
expect(onOpen).toBeCalledTimes(2);
});
});

describe('onClose - called on every close', () => {
let fsLightbox;
let onClose;

beforeAll(() => {
onClose = jest.fn();
jest.useFakeTimers();
fsLightbox = mount(<FsLightbox
toggler={ false }
onClose={ onClose }
urls={ ['images/1.jpg'] }
/>);
});

it('should not onClose after open', () => {
fsLightbox.setProps({
toggler: true
});
expect(onClose).toBeCalledTimes(0);
});

it('should call onClose after close', () => {
fsLightbox.setProps({
toggler: false
});
jest.runTimersToTime(CONTAINER_FADE_OUT_TIME);
expect(onClose).toBeCalledTimes(1);
});

it('should not call onCloseafter reopening', () => {
fsLightbox.setProps({
toggler: true
});
expect(onClose).toBeCalledTimes(1);
});
});

describe('onShow - called on every open except init', () => {
let fsLightbox;
let onShow;

beforeAll(() => {
onShow = jest.fn();
jest.useFakeTimers();
fsLightbox = mount(<FsLightbox
toggler={ false }
onShow={ onShow }
urls={ ['images/1.jpg'] }
/>);
});

it('should not call onShow after open (first open is initialize)', () => {
fsLightbox.setProps({
toggler: true
});
expect(onShow).not.toBeCalled();
});

it('should not call onShow after close', () => {
fsLightbox.setProps({
toggler: false
});
jest.runTimersToTime(CONTAINER_FADE_OUT_TIME);
expect(onShow).not.toBeCalled();
});

it('should call onShow after reopen', () => {
fsLightbox.setProps({
toggler: true
});
expect(onShow).toBeCalledTimes(1);
});
});
@@ -82,7 +82,7 @@ describe('calling callback with right sources types', () => {

describe('invalid type', () => {
beforeEach(() => {
sourceTypeGetter.setUrlToCheck('ima invalid');
sourceTypeGetter.setUrlToCheck('https://cors-anywhere.herokuapp.com/');
});

it('should call callback with invalid type', testDone => {
@@ -1,18 +1,23 @@
import { FsLightboxMock } from "../../__mocks__/components/fsLightboxMock";
import { SourceHolderTransformer } from "../../../src/core/transforms/SourceHolderTransformer";

const fsLightboxMock = new FsLightboxMock();
const fsLightbox = fsLightboxMock.getFsLightbox();
const fsLightbox = {
sourcesData: {
slideDistance: 0
},
elements: {
sourceHolders: [{
current: document.createElement('div')
}]
}
};
// window width for all tests is 1000
window.innerWidth = 1000;
// slide distance for all tests is 1
fsLightbox.sourcesData.slideDistance = 1;
// slide distance for all tests is .4
fsLightbox.sourcesData.slideDistance = .4;
const sourceHolderTransformer = new SourceHolderTransformer(fsLightbox);
let mockSourceHolderStyle;

beforeEach(() => {
// resetting all sources holders
fsLightboxMock.setAllSourceHoldersToDivs();
sourceHolderTransformer.setSourceHolder(fsLightbox.elements.sourceHolders[0]);
mockSourceHolderStyle = fsLightbox.elements.sourceHolders[0].current.style;
});
@@ -24,7 +29,7 @@ describe('default transforming (depends on window width and slide distance)', ()
});

it('should add correct negative transform', () => {
expect(mockSourceHolderStyle.transform).toEqual('translate(-1000px,0)');
expect(mockSourceHolderStyle.transform).toEqual('translate(-1400px,0)');
});
});

@@ -44,7 +49,7 @@ describe('default transforming (depends on window width and slide distance)', ()
});

it('should add correct negative transform', () => {
expect(mockSourceHolderStyle.transform).toEqual('translate(1000px,0)');
expect(mockSourceHolderStyle.transform).toEqual('translate(1400px,0)');
});
});
});
@@ -56,7 +61,7 @@ describe('transforming by value (depends on give value, window width, and slide
});

it('should add correct negative transform', () => {
expect(mockSourceHolderStyle.transform).toEqual('translate(-900px,0)');
expect(mockSourceHolderStyle.transform).toEqual('translate(-1300px,0)');
});
});

@@ -77,7 +82,7 @@ describe('transforming by value (depends on give value, window width, and slide
});

it('should add correct positive transform', () => {
expect(mockSourceHolderStyle.transform).toEqual('translate(1100px,0)');
expect(mockSourceHolderStyle.transform).toEqual('translate(1500px,0)');
});
});
});

0 comments on commit 256b0a6

Please sign in to comment.
You can’t perform that action at this time.