stimulus-flatpickr
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -7,15 +7,14 @@ // Karma configuration | ||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: "", | ||
basePath: '', | ||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ["mocha", "sinon-chai", "fixture"], | ||
frameworks: ['mocha', 'sinon-chai', 'fixture'], | ||
// list of files / patterns to load in the browser | ||
files: [ | ||
"spec/*.js", | ||
"src/**/*.js", | ||
"spec/fixtures/*.html", | ||
'spec/*.js', | ||
'spec/fixtures/*.html', | ||
{ | ||
pattern: "**/*.js.map", | ||
pattern: '**/*.js.map', | ||
included: false | ||
@@ -31,9 +30,9 @@ } | ||
preprocessors: { | ||
"spec/**/*.js": ["webpack", "sourcemap"], | ||
"src/**/*.js": ["webpack", "sourcemap"], | ||
"spec/fixtures/*.html": ["html2js"] | ||
'spec/**/*.js': ['webpack', 'sourcemap'], | ||
'src/**/*.js': ['webpack', 'sourcemap'], | ||
'spec/fixtures/*.html': ['html2js'] | ||
}, | ||
webpack: { | ||
mode: "development", | ||
mode: 'development', | ||
module: { | ||
@@ -44,7 +43,7 @@ rules: [ | ||
exclude: [/node_modules/], | ||
use: ["babel-loader"] | ||
use: ['babel-loader'] | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: ["style-loader", "css-loader"] | ||
use: ['style-loader', 'css-loader'] | ||
} | ||
@@ -66,3 +65,3 @@ ] | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ["mocha", "coverage"], | ||
reporters: ['mocha', 'coverage'], | ||
@@ -72,9 +71,9 @@ coverageReporter: { | ||
{ | ||
type: "lcov" | ||
type: 'lcov' | ||
}, | ||
{ | ||
type: "text-summary" | ||
type: 'text-summary' | ||
}, | ||
{ | ||
type: "text" | ||
type: 'text' | ||
} | ||
@@ -98,3 +97,4 @@ ] | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ["Chrome"], | ||
browsers: ['ChromeHeadless'], | ||
// browsers: ['Chrome'], | ||
@@ -108,3 +108,3 @@ // Continuous Integration mode | ||
concurrency: 5 | ||
}); | ||
}; | ||
}) | ||
} |
{ | ||
"name": "stimulus-flatpickr", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A Stimulus Wrapper for Flatpickr library", | ||
"main": "dist/stimulus-flatpickr.js", | ||
"umd:main": "dist/stimulus-flatpickr.umd.js", | ||
"module": "dist/stimulus-flatpickr.m.js", | ||
"source": "src/stimulus-flatpickr.js", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"module": "dist/index.m.js", | ||
"source": "src/index.js", | ||
"author": "@adrienpoly", | ||
@@ -15,32 +15,33 @@ "license": "MIT", | ||
"dev": "rollup -wc", | ||
"test": "karma start", | ||
"test": "NODE_ENV=test karma start", | ||
"test:watch": "yarn test --auto-watch --no-single-run", | ||
"test:headless": "yarn test --auto-watch --no-single-run --browsers ChromeHeadless", | ||
"codecov": "codecov", | ||
"publish": "np" | ||
"release": "np" | ||
}, | ||
"dependencies": { | ||
"flatpickr": "^4.6.2", | ||
"flatpickr": ">=4.6.0", | ||
"stimulus": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.4", | ||
"babel-plugin-istanbul": "^5.2.0", | ||
"babel-plugin-syntax-async-functions": "^6.13.0", | ||
"babel-plugin-transform-async-functions": "^6.22.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-runtime": "^6.26.0", | ||
"chai": "^4.1.2", | ||
"chai-dom": "^1.8.0", | ||
"codecov": "^3.5.0", | ||
"@babel/core": "^7.6.0", | ||
"@babel/plugin-proposal-class-properties": "^7.3.4", | ||
"@babel/plugin-transform-classes": "^7.3.4", | ||
"@babel/preset-env": "^7.6.0", | ||
"babel-loader": "^8.0.5", | ||
"babel-plugin-istanbul": "^5.1.1", | ||
"chai": "^4.2.0", | ||
"chai-dom": "^1.8.1", | ||
"codecov": "^3.1.0", | ||
"css-loader": "^1.0.0", | ||
"karma": "^3.1.4", | ||
"karma-babel-preprocessor": "6", | ||
"eslint": "^6.3.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-mocha": "^6.1.0", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"karma": "^4.0.1", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage": "^1.1.2", | ||
"karma-coverage": "^2.0.1", | ||
"karma-fixture": "^0.2.6", | ||
@@ -50,19 +51,22 @@ "karma-html2js-preprocessor": "^1.1.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-rollup-preprocessor": "^6.1.2", | ||
"karma-rollup-preprocessor": "^7.0.2", | ||
"karma-sinon-chai": "^2.0.2", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^3.0.0", | ||
"karma-webpack": "^4.0.2", | ||
"mocha": "^5.2.0", | ||
"np": "^5.0.3", | ||
"rollup": "^0.64.1", | ||
"rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-filesize": "^4.0.1", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"npm-run-all": "^4.1.3", | ||
"rollup": "^1.20.3", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-filesize": "^6.0.1", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-uglify": "^6.0.2", | ||
"sinon": "^6.1.4", | ||
"sinon-chai": "^3.3.0", | ||
"size-plugin": "^1.2.0", | ||
"sinon-chai": "^3.2.0", | ||
"size-plugin": "^1.0.1", | ||
"style-loader": "^0.23.0", | ||
"webpack": "^4.39.3", | ||
"webpack-cli": "^2.0.14", | ||
"webpack-dev-middleware": "^3.7.1" | ||
"webpack-cli": "^3.2.3", | ||
"webpack-dev-middleware": "^3.6.1", | ||
"webpack-dev-server": "^3.2.1" | ||
}, | ||
@@ -69,0 +73,0 @@ "repository": { |
@@ -6,2 +6,8 @@ <h1 align="center">📆 Stimulus-Flatpickr Wrapper</h1> | ||
</a> | ||
<a href="https://circleci.com/gh/adrienpoly/stimulus-flatpickr" rel="nofollow"> | ||
<img src="https://circleci.com/gh/adrienpoly/stimulus-flatpickr/tree/master.svg?style=svg" alt="CircleCi build status"> | ||
</a> | ||
<a href="https://codecov.io/gh/adrienpoly/stimulus-flatpickr"> | ||
<img src="https://codecov.io/gh/adrienpoly/stimulus-flatpickr/branch/master/graph/badge.svg" alt="Coverage"/> | ||
</a> | ||
</p> | ||
@@ -8,0 +14,0 @@ |
@@ -1,29 +0,31 @@ | ||
import buble from "rollup-plugin-buble"; | ||
import filesize from "rollup-plugin-filesize"; | ||
import resolve from "rollup-plugin-node-resolve"; | ||
import filesize from 'rollup-plugin-filesize' | ||
import resolve from 'rollup-plugin-node-resolve' | ||
import babel from 'rollup-plugin-babel' | ||
const pkg = require('./package.json') | ||
const name = pkg.name | ||
export default { | ||
input: "src/stimulus-flatpickr.js", | ||
external: ["stimulus", "flatpickr"], | ||
input: 'src/index.js', | ||
external: ['stimulus', 'flatpickr'], | ||
output: [ | ||
{ | ||
file: "dist/stimulus-flatpickr.js", | ||
format: "cjs", | ||
name: "StimulusFlatpickr", | ||
file: 'dist/index.js', | ||
format: 'cjs', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: "dist/stimulus-flatpickr.m.js", | ||
format: "es", | ||
name: "StimulusFlatpickr", | ||
file: 'dist/index.m.js', | ||
format: 'es', | ||
sourcemap: true | ||
}, | ||
{ | ||
file: "dist/stimulus-flatpickr.umd.js", | ||
format: "umd", | ||
name: "StimulusFlatpickr", | ||
file: 'dist/index.umd.js', | ||
format: 'umd', | ||
name, | ||
sourcemap: true, | ||
globals: { | ||
stimulus: "Stimulus", | ||
flatpickr: "Flatpickr" | ||
stimulus: 'Stimulus', | ||
flatpickr: 'Flatpickr' | ||
} | ||
@@ -34,10 +36,7 @@ } | ||
resolve(), | ||
buble({ | ||
transforms: { | ||
classes: true | ||
}, | ||
objectAssign: "Object.assign" | ||
babel({ | ||
exclude: 'node_modules/**' | ||
}), | ||
filesize() | ||
] | ||
}; | ||
} |
@@ -1,3 +0,3 @@ | ||
import Flatpickr from "../../src/stimulus-flatpickr"; | ||
import Flatpickr from '../../src/index' | ||
export default class extends Flatpickr {} |
@@ -1,2 +0,2 @@ | ||
import Flatpickr from "../../src/stimulus-flatpickr"; | ||
import Flatpickr from '../../src/index' | ||
@@ -3,0 +3,0 @@ export default class extends Flatpickr { |
@@ -1,78 +0,79 @@ | ||
import Flatpickr from "./controllers/flatpickr_hook_controller"; | ||
import "flatpickr/dist/flatpickr.css"; | ||
import { | ||
registerController, | ||
fixtureQuerySelector, | ||
addFlatpickrOption | ||
} from "./helpers"; | ||
import chai, { expect } from "chai"; | ||
import chaiDom from "chai-dom"; | ||
import sinon from "sinon"; | ||
import sinonChai from "sinon-chai"; | ||
var controller, spy; | ||
// import Flatpickr from './controllers/flatpickr_hook_controller' | ||
import { Application } from 'stimulus' | ||
import StimulusFlatpickr from './controllers/flatpickr_hook_controller' | ||
import 'flatpickr/dist/flatpickr.css' | ||
import { registerController, nextFrame, fixtureQuerySelector, addFlatpickrOption } from './helpers' | ||
import chai, { expect } from 'chai' | ||
import chaiDom from 'chai-dom' | ||
import sinon from 'sinon' | ||
import sinonChai from 'sinon-chai' | ||
var controller, spy | ||
const application = Application.start() | ||
chai.use(chaiDom); | ||
chai.use(sinonChai); | ||
chai.use(chaiDom) | ||
chai.use(sinonChai) | ||
describe("Flatpickr Controller EVENTS tests", function() { | ||
before("initialize controller", async function() { | ||
fixture.load("index.html"); | ||
this.sandbox = sinon.createSandbox(); | ||
this.sandbox.stub(Flatpickr.prototype, "open"); | ||
this.sandbox.stub(Flatpickr.prototype, "close"); | ||
this.sandbox.stub(Flatpickr.prototype, "ready"); | ||
this.sandbox.stub(Flatpickr.prototype, "monthChange"); | ||
this.sandbox.stub(Flatpickr.prototype, "yearChange"); | ||
this.spyDayCreate = this.sandbox.stub(Flatpickr.prototype, "dayCreate"); | ||
this.spyValueUpdate = this.sandbox.stub(Flatpickr.prototype, "valueUpdate"); | ||
this.spyChange = this.sandbox.stub(Flatpickr.prototype, "change"); | ||
controller = await registerController("flatpickr", Flatpickr); | ||
}); | ||
describe('Flatpickr Controller EVENTS tests', function() { | ||
before('initialize controller', async function() { | ||
fixture.load('index.html') | ||
this.sandbox = sinon.createSandbox() | ||
this.sandbox.stub(StimulusFlatpickr.prototype, 'open') | ||
this.sandbox.stub(StimulusFlatpickr.prototype, 'close') | ||
this.sandbox.stub(StimulusFlatpickr.prototype, 'ready') | ||
this.sandbox.stub(StimulusFlatpickr.prototype, 'monthChange') | ||
this.sandbox.stub(StimulusFlatpickr.prototype, 'yearChange') | ||
this.spyDayCreate = this.sandbox.stub(StimulusFlatpickr.prototype, 'dayCreate') | ||
this.spyValueUpdate = this.sandbox.stub(StimulusFlatpickr.prototype, 'valueUpdate') | ||
this.spyChange = this.sandbox.stub(StimulusFlatpickr.prototype, 'change') | ||
application.register('datepicker', StimulusFlatpickr) | ||
await nextFrame() | ||
controller = application.controllers[0] | ||
}) | ||
describe("Initial state", function() { | ||
it("Stimulus Flatpickr controller READY function is called", function() { | ||
expect(controller.ready).has.been.calledOnce; | ||
expect(this.spyDayCreate.getCalls().length).to.be.at.least(28); | ||
}); | ||
}); | ||
describe('Initial state', function() { | ||
it('Stimulus Flatpickr controller READY function is called', function() { | ||
expect(controller.ready).has.been.calledOnce | ||
// expect(this.spyDayCreate.getCalls().length).to.be.at.least(28) | ||
}) | ||
}) | ||
describe("When focus", function() { | ||
it("Stimulus Flatpickr controller OPEN function is called", function() { | ||
const input = fixtureQuerySelector(".flatpickr-input"); | ||
input.dispatchEvent(new Event("focus")); | ||
expect(controller.open).has.been.calledOnce; | ||
}); | ||
}); | ||
describe('When focus', function() { | ||
it('Stimulus Flatpickr controller OPEN function is called', function() { | ||
const input = fixtureQuerySelector('.flatpickr-input') | ||
input.dispatchEvent(new Event('focus')) | ||
expect(controller.open).has.been.calledOnce | ||
}) | ||
}) | ||
describe("When set a new date", function() { | ||
it("Stimulus Flatpickr controller valueUpdate & change functions are called once", function() { | ||
controller.fp.setDate("2018-10-15", true, "Y-m-d"); | ||
expect(controller.valueUpdate).has.been.calledOnce; | ||
expect(this.spyValueUpdate.getCall(0).args[1]).to.be.equal("2018-10-15"); | ||
expect(controller.change).has.been.calledOnce; | ||
expect(this.spyChange.getCall(0).args[1]).to.be.equal("2018-10-15"); | ||
}); | ||
}); | ||
describe('When set a new date', function() { | ||
it('Stimulus Flatpickr controller valueUpdate & change functions are called once', function() { | ||
controller.fp.setDate('2018-10-15', true, 'Y-m-d') | ||
expect(controller.valueUpdate).has.been.calledOnce | ||
expect(this.spyValueUpdate.getCall(0).args[1]).to.match(/2018-10-15/) | ||
expect(controller.change).has.been.calledOnce | ||
expect(this.spyChange.getCall(0).args[1]).to.match(/2018-10-15/) | ||
}) | ||
}) | ||
describe("When input focus out", function() { | ||
it("Stimulus Flatpickr controller CLOSE function is called once", function() { | ||
const otherInput = fixtureQuerySelector("#other-input"); | ||
otherInput.dispatchEvent(new Event("focus")); | ||
expect(controller.close).has.been.calledOnce; | ||
}); | ||
}); | ||
describe('When input focus out', function() { | ||
it('Stimulus Flatpickr controller CLOSE function is called once', function() { | ||
const otherInput = fixtureQuerySelector('#other-input') | ||
otherInput.dispatchEvent(new Event('focus')) | ||
expect(controller.close).has.been.calledOnce | ||
}) | ||
}) | ||
describe("When change month", function() { | ||
it("Stimulus Flatpickr controller monthChange() function is called once", function() { | ||
controller.fp.changeMonth(1); | ||
expect(controller.monthChange).has.been.calledOnce; | ||
}); | ||
}); | ||
describe('When change month', function() { | ||
it('Stimulus Flatpickr controller monthChange() function is called once', function() { | ||
controller.fp.changeMonth(1) | ||
expect(controller.monthChange).has.been.calledOnce | ||
}) | ||
}) | ||
describe("When change year", function() { | ||
it("Stimulus Flatpickr controller yearChange() function is called once", function() { | ||
controller.fp.changeYear(1); | ||
expect(controller.yearChange).has.been.calledOnce; | ||
}); | ||
}); | ||
}); | ||
describe('When change year', function() { | ||
it('Stimulus Flatpickr controller yearChange() function is called once', function() { | ||
controller.fp.changeYear(1) | ||
expect(controller.yearChange).has.been.calledOnce | ||
}) | ||
}) | ||
}) |
@@ -1,285 +0,294 @@ | ||
import Flatpickr from "./controllers/flatpickr_controller"; | ||
import "flatpickr/dist/flatpickr.css"; | ||
import { | ||
registerController, | ||
fixtureQuerySelector, | ||
calendarQuerySelector, | ||
flatpickrCalendar, | ||
addFlatpickrOption, | ||
beforeEachSuite | ||
} from "./helpers"; | ||
import chai, { expect } from "chai"; | ||
import chaiDom from "chai-dom"; | ||
var controller; | ||
import { Application } from 'stimulus' | ||
import chai, { expect } from 'chai' | ||
import chaiDom from 'chai-dom' | ||
chai.use(chaiDom); | ||
import StimulusFlatpickr from './controllers/flatpickr_controller' | ||
import { nextFrame, fixtureQuerySelector, flatpickrCalendar, addFlatpickrOption, beforeEachSuite } from './helpers' | ||
describe("Flatpickr Controller tests", function() { | ||
beforeEachSuite("initialize controller", async function() { | ||
fixture.load("index.html"); | ||
controller = await registerController("flatpickr", Flatpickr); | ||
}); | ||
import 'flatpickr/dist/flatpickr.css' | ||
describe("Initial state", function() { | ||
var controller | ||
const application = Application.start() | ||
chai.use(chaiDom) | ||
describe('Flatpickr Controller tests', function() { | ||
beforeEachSuite('initialize controller', async function() { | ||
fixture.load('index.html') | ||
application.register('datepicker', StimulusFlatpickr) | ||
await nextFrame() | ||
controller = application.controllers[0] | ||
}) | ||
describe('Initial state', function() { | ||
it('Stimulus flatpickr controller is initialized', function() { | ||
expect(controller).to.exist | ||
}) | ||
it('can find an input with the class "flatpickr-input"', function() { | ||
expect(fixtureQuerySelector(".flatpickr-input")).to.exist; | ||
}); | ||
expect(fixtureQuerySelector('.flatpickr-input')).to.exist | ||
}) | ||
it('can find a div in the document with the class "flatpickr-calendar"', function() { | ||
expect(flatpickrCalendar()).to.exist; | ||
}); | ||
expect(flatpickrCalendar()).to.exist | ||
}) | ||
it("does not have the class open", function() { | ||
expect(flatpickrCalendar()).not.to.have.class("open"); | ||
}); | ||
}); | ||
it('does not have the class open', function() { | ||
expect(flatpickrCalendar()).not.to.have.class('open') | ||
}) | ||
}) | ||
describe("When input focus", function() { | ||
it("Flatpickr has the open class", function() { | ||
const input = fixtureQuerySelector(".flatpickr-input"); | ||
input.dispatchEvent(new Event("focus")); | ||
describe('When input focus', function() { | ||
it('Flatpickr has the open class', async function() { | ||
const input = fixtureQuerySelector('.flatpickr-input') | ||
input.dispatchEvent(new Event('focus')) | ||
await nextFrame() | ||
expect(flatpickrCalendar()).to.have.class("open"); | ||
}); | ||
}); | ||
expect(flatpickrCalendar()).to.have.class('open') | ||
}) | ||
}) | ||
describe("When input focus out", function() { | ||
it("Flatpickr does not have open class", function() { | ||
controller.fp.open(); | ||
const otherInput = fixtureQuerySelector("#other-input"); | ||
otherInput.dispatchEvent(new Event("focus")); | ||
describe('When input focus out', function() { | ||
it('Flatpickr does not have open class', function() { | ||
controller.fp.open() | ||
const otherInput = fixtureQuerySelector('#other-input') | ||
otherInput.dispatchEvent(new Event('focus')) | ||
expect(flatpickrCalendar()).not.to.have.class("open"); | ||
}); | ||
}); | ||
expect(flatpickrCalendar()).not.to.have.class('open') | ||
}) | ||
}) | ||
describe("Flatpickr options with time enabled", function() { | ||
context("set enableTime false option", function() { | ||
it("cannot set time", async function() { | ||
await addFlatpickrOption("EnableTime", "false", controller); | ||
describe('Flatpickr options with time enabled', function() { | ||
context('set enableTime false option', function() { | ||
it('cannot set time', async function() { | ||
addFlatpickrOption('EnableTime', 'false', controller) | ||
await nextFrame() | ||
expect(flatpickrCalendar()).not.to.have.class("hasTime"); | ||
expect(flatpickrCalendar()).not.to.contain(".flatpickr-time"); | ||
}); | ||
}); | ||
expect(flatpickrCalendar()).not.to.have.class('hasTime') | ||
expect(flatpickrCalendar()).not.to.contain('.flatpickr-time') | ||
}) | ||
}) | ||
context("set enableTime true option", function() { | ||
it("can set time", async function() { | ||
await addFlatpickrOption("EnableTime", "true", controller); | ||
expect(flatpickrCalendar()).to.have.class("hasTime"); | ||
expect(flatpickrCalendar()).to.contain(".flatpickr-time"); | ||
}); | ||
}); | ||
context('set enableTime true option', function() { | ||
it('can set time', async function() { | ||
addFlatpickrOption('EnableTime', 'true', controller) | ||
await nextFrame() | ||
context("add time_24hr true option", function() { | ||
it("am pm are not visible", async function() { | ||
await addFlatpickrOption("Time-24hr", "true", controller); | ||
expect(flatpickrCalendar()).to.have.class('hasTime') | ||
expect(flatpickrCalendar()).to.contain('.flatpickr-time') | ||
}) | ||
}) | ||
expect(flatpickrCalendar()).to.have.class("hasTime"); | ||
expect(flatpickrCalendar()).not.to.contain(".flatpickr-am-pm"); | ||
}); | ||
}); | ||
context('add time_24hr true option', function() { | ||
it('am pm are not visible', async function() { | ||
addFlatpickrOption('Time-24hr', 'true', controller) | ||
await nextFrame() | ||
context("add enableSeconds false option", function() { | ||
it("cannot set seconds", async function() { | ||
await addFlatpickrOption("EnableSeconds", "false", controller); | ||
expect(flatpickrCalendar()).to.have.class('hasTime') | ||
expect(flatpickrCalendar()).not.to.contain('.flatpickr-am-pm') | ||
}) | ||
}) | ||
expect(flatpickrCalendar()).not.to.contain(".flatpickr-second"); | ||
}); | ||
}); | ||
context('add enableSeconds false option', function() { | ||
it('cannot set seconds', async function() { | ||
addFlatpickrOption('EnableSeconds', 'false', controller) | ||
await nextFrame() | ||
context("add enableSeconds true option", function() { | ||
it("can set seconds", async function() { | ||
await addFlatpickrOption("EnableSeconds", "true", controller); | ||
expect(flatpickrCalendar()).not.to.contain('.flatpickr-second') | ||
}) | ||
}) | ||
expect(flatpickrCalendar()).to.contain(".flatpickr-time"); | ||
expect(flatpickrCalendar()).to.contain(".flatpickr-second"); | ||
}); | ||
}); | ||
}); | ||
context('add enableSeconds true option', function() { | ||
it('can set seconds', async function() { | ||
addFlatpickrOption('EnableSeconds', 'true', controller) | ||
await nextFrame() | ||
describe("Flatpickr options with time Disabled", function() { | ||
context("add multiMonth 2 option", function() { | ||
it("can see two months", async function() { | ||
await addFlatpickrOption("EnableTime", "false", controller); | ||
await addFlatpickrOption("ShowMonths", 2, controller); | ||
expect(flatpickrCalendar()).to.have.class("multiMonth"); | ||
}); | ||
}); | ||
expect(flatpickrCalendar()).to.contain('.flatpickr-time') | ||
expect(flatpickrCalendar()).to.contain('.flatpickr-second') | ||
}) | ||
}) | ||
}) | ||
context("add AltInput true option", function() { | ||
it("can see new input field", async function() { | ||
expect(fixture.el).not.to.contain("input[type=hidden].flatpickr-input"); | ||
await addFlatpickrOption("AltInput", "true", controller); | ||
describe('Flatpickr options with time Disabled', function() { | ||
context('add multiMonth 2 option', function() { | ||
it('can see two months', async function() { | ||
addFlatpickrOption('EnableTime', 'false', controller) | ||
addFlatpickrOption('ShowMonths', 2, controller) | ||
await nextFrame() | ||
expect(fixture.el).to.contain("input[type=hidden].flatpickr-input"); | ||
expect(fixture.el).to.contain("input[readonly].flatpickr-input"); | ||
}); | ||
}); | ||
expect(flatpickrCalendar()).to.have.class('multiMonth') | ||
}) | ||
}) | ||
context("add AltFormat %Y-%m-%d option", function() { | ||
it("can see new input field", async function() { | ||
await addFlatpickrOption("AltFormat", "%B %d, %Y", controller); | ||
await addFlatpickrOption("DefaultDate", "2018-10-15", controller); | ||
expect(controller.selectedDateElemTarget).to.have.attribute( | ||
"aria-label", | ||
"October 15, 2018" | ||
); | ||
context('add AltFormat %Y-%m-%d option', function() { | ||
it('can see new input field', async function() { | ||
addFlatpickrOption('AltFormat', '%B %d, %Y', controller) | ||
addFlatpickrOption('DefaultDate', '2018-10-15', controller) | ||
await nextFrame() | ||
expect(controller.inputTarget).to.have.value("2018-10-15"); | ||
}); | ||
expect(controller.selectedDateElemTarget).to.have.attribute('aria-label', 'October 15, 2018') | ||
expect(controller.inputTarget).to.have.value('2018-10-15') | ||
}) | ||
it("base dateFormat remains the same", function() { | ||
expect(controller.fp.config.dateFormat).to.equal("Y-m-d"); | ||
}); | ||
}); | ||
it('base dateFormat remains the same', function() { | ||
expect(controller.fp.config.dateFormat).to.equal('Y-m-d') | ||
}) | ||
}) | ||
context("add range mode", function() { | ||
it("calendar has the range class", async function() { | ||
await addFlatpickrOption("Mode", "range", controller); | ||
expect(flatpickrCalendar()).to.have.class("rangeMode"); | ||
}); | ||
}); | ||
}); | ||
context('add range mode', function() { | ||
it('calendar has the range class', function() { | ||
addFlatpickrOption('Mode', 'range', controller) | ||
expect(flatpickrCalendar()).to.have.class('rangeMode') | ||
}) | ||
}) | ||
}) | ||
describe("Flatpickr disable dates options", function() { | ||
describe('Flatpickr disable dates options', function() { | ||
before(async function() { | ||
controller.fp.setDate("2018-10-15"); | ||
await addFlatpickrOption("DateFormat", "Y-m-d", controller); | ||
await addFlatpickrOption("DefaultDate", "2018-10-15", controller); | ||
}); | ||
controller.fp.setDate('2018-10-15') | ||
addFlatpickrOption('DateFormat', 'Y-m-d', controller) | ||
addFlatpickrOption('DefaultDate', '2018-10-15', controller) | ||
await nextFrame() | ||
}) | ||
context("set min date", function() { | ||
it("dates before min date are disabled", async function() { | ||
await addFlatpickrOption("MinDate", "2018-10-03", controller); | ||
expect( | ||
document.querySelector('span[aria-label="October 2, 2018"]') | ||
).to.have.class("disabled"); | ||
}); | ||
}); | ||
context('set min date', function() { | ||
it('dates before min date are disabled', async function() { | ||
addFlatpickrOption('MinDate', '2018-10-03', controller) | ||
await nextFrame() | ||
context("disable dates", function() { | ||
it("disabled individual dates are disabled", async function() { | ||
await addFlatpickrOption( | ||
"Disable", | ||
["2018-10-14", "2018-10-17"], | ||
controller | ||
); | ||
expect(document.querySelector('span[aria-label="October 2, 2018"]')).to.have.class('flatpickr-disabled') | ||
}) | ||
}) | ||
expect( | ||
document.querySelector('span[aria-label="October 14, 2018"]') | ||
).to.have.class("disabled"); | ||
}); | ||
context('disable dates', function() { | ||
it('disabled individual dates are disabled', async function() { | ||
addFlatpickrOption('Disable', ['2018-10-14', '2018-10-17'], controller) | ||
await nextFrame() | ||
it("add disable days of week all sundays are disabled", async function() { | ||
await addFlatpickrOption("DisableDaysOfWeek", [6], controller); | ||
expect(document.querySelector('span[aria-label="October 14, 2018"]')).to.have.class('flatpickr-disabled') | ||
}) | ||
expect( | ||
document.querySelector('span[aria-label="October 6, 2018"]') | ||
).to.have.class("disabled"); | ||
it('add disable days of week all sundays are disabled', async function() { | ||
addFlatpickrOption('DisableDaysOfWeek', [6], controller) | ||
await nextFrame() | ||
expect( | ||
document.querySelector('span[aria-label="October 13, 2018"]') | ||
).to.have.class("disabled"); | ||
}); | ||
}); | ||
}); | ||
expect(document.querySelector('span[aria-label="October 6, 2018"]')).to.have.class('flatpickr-disabled') | ||
expect(document.querySelector('span[aria-label="October 13, 2018"]')).to.have.class('flatpickr-disabled') | ||
}) | ||
}) | ||
}) | ||
describe("Flatpickr enable dates options", function() { | ||
describe('Flatpickr enable dates options', function() { | ||
before(async function() { | ||
await addFlatpickrOption("DateFormat", "Y-m-d", controller); | ||
controller.fp.setDate("2018-10-15"); | ||
await addFlatpickrOption("DefaultDate", "2018-10-15", controller); | ||
}); | ||
controller.fp.setDate('2018-10-15') | ||
addFlatpickrOption('DateFormat', 'Y-m-d', controller) | ||
addFlatpickrOption('DefaultDate', '2018-10-15', controller) | ||
await nextFrame() | ||
}) | ||
it("enable individual dates are enabled", async function() { | ||
await addFlatpickrOption( | ||
"Enable", | ||
["2018-10-14", "2018-10-17"], | ||
controller | ||
); | ||
await addFlatpickrOption("DefaultDate", "2018-10-14", controller); | ||
it('enable individual dates are enabled', async function() { | ||
addFlatpickrOption('Enable', ['2018-10-14', '2018-10-17'], controller) | ||
addFlatpickrOption('DefaultDate', '2018-10-14', controller) | ||
await nextFrame() | ||
expect( | ||
document.querySelector('span[aria-label="October 14, 2018"]') | ||
).not.to.have.class("disabled"); | ||
}); | ||
expect(document.querySelector('span[aria-label="October 14, 2018"]')).not.to.have.class('flatpickr-disabled') | ||
}) | ||
it("add enable days of week only mondays are enabled", async function() { | ||
await addFlatpickrOption("EnableDaysOfWeek", [1], controller); | ||
it('add enable days of week only mondays are enabled', async function() { | ||
addFlatpickrOption('EnableDaysOfWeek', [1], controller) | ||
await nextFrame() | ||
expect( | ||
document.querySelector('span[aria-label="October 8, 2018"]') | ||
).not.to.have.class("disabled"); | ||
expect(document.querySelector('span[aria-label="October 8, 2018"]')).not.to.have.class('flatpickr-disabled') | ||
expect(document.querySelector('span[aria-label="October 15, 2018"]')).not.to.have.class('flatpickr-disabled') | ||
expect(document.querySelector('span[aria-label="October 14, 2018"]')).not.to.have.class('flatpickr-disabled') | ||
}) | ||
}) | ||
expect( | ||
document.querySelector('span[aria-label="October 15, 2018"]') | ||
).not.to.have.class("disabled"); | ||
describe('Flatpickr enable days of week only', function() { | ||
it('add enable days of week', async function() { | ||
addFlatpickrOption('EnableDaysOfWeek', [1], controller) | ||
await nextFrame() | ||
expect( | ||
document.querySelector('span[aria-label="October 14, 2018"]') | ||
).not.to.have.class("disabled"); | ||
}); | ||
}); | ||
const enabledDays = controller.daysTarget.querySelectorAll('span.flatpickr-day:not(.flatpickr-disabled)') | ||
expect(enabledDays.length).to.be.within(4, 6) | ||
}) | ||
}) | ||
describe("Flatpickr enable days of week only", function() { | ||
it("add enable days of week", async function() { | ||
await addFlatpickrOption("EnableDaysOfWeek", [1], controller); | ||
const enabledDays = controller.daysTarget.querySelectorAll( | ||
"span.flatpickr-day:not(.disabled)" | ||
); | ||
expect(enabledDays.length).to.be.within(4, 6); | ||
}); | ||
}); | ||
describe('Flatpickr disable days of week only', function() { | ||
it('add disable days of week', async function() { | ||
addFlatpickrOption('DisableDaysOfWeek', [1], controller) | ||
await nextFrame() | ||
describe("Flatpickr disable days of week only", function() { | ||
it("add disable days of week", async function() { | ||
await addFlatpickrOption("DisableDaysOfWeek", [1], controller); | ||
const disabledDays = controller.daysTarget.querySelectorAll('span.flatpickr-day.flatpickr-disabled') | ||
expect(disabledDays.length).to.be.within(4, 6) | ||
}) | ||
}) | ||
const disabledDays = controller.daysTarget.querySelectorAll( | ||
"span.flatpickr-day.disabled" | ||
); | ||
expect(disabledDays.length).to.be.within(4, 6); | ||
}); | ||
}); | ||
describe("Flatpickr disable days test with invalid entries", function() { | ||
describe('Flatpickr disable days test with invalid entries', function() { | ||
context("don't provide an array", function() { | ||
it("it still work and no days are disabled", async function() { | ||
await addFlatpickrOption("DisableDaysOfWeek", 1, controller); | ||
it('it still work and no days are disabled', async function() { | ||
addFlatpickrOption('DisableDaysOfWeek', 1, controller) | ||
await nextFrame() | ||
const disabledDays = controller.daysTarget.querySelectorAll( | ||
"span.flatpickr-day.disabled" | ||
); | ||
expect(controller).to.exist; | ||
expect(disabledDays.length).to.equal(0); | ||
}); | ||
}); | ||
const disabledDays = controller.daysTarget.querySelectorAll('span.flatpickr-day.flatpickr-disabled') | ||
expect(controller).to.exist | ||
expect(disabledDays.length).to.equal(0) | ||
}) | ||
}) | ||
context("provide an array of string", function() { | ||
it("it is the same as an array of integer", async function() { | ||
await addFlatpickrOption("DisableDaysOfWeek", ["1"], controller); | ||
context('provide an array of string', function() { | ||
it('it is the same as an array of integer', async function() { | ||
addFlatpickrOption('DisableDaysOfWeek', ['1'], controller) | ||
await nextFrame() | ||
const disabledDays = controller.daysTarget.querySelectorAll( | ||
"span.flatpickr-day.disabled" | ||
); | ||
expect(controller).to.exist; | ||
expect(disabledDays.length).to.be.within(4, 6); | ||
}); | ||
}); | ||
}); | ||
const disabledDays = controller.daysTarget.querySelectorAll('span.flatpickr-day.flatpickr-disabled') | ||
expect(controller).to.exist | ||
expect(disabledDays.length).to.be.within(4, 6) | ||
}) | ||
}) | ||
}) | ||
describe("Flatpickr enable days test with invalid entries", function() { | ||
describe('Flatpickr enable days test with invalid entries', function() { | ||
context("don't provide an array", function() { | ||
it("it still work and all days are disabled", async function() { | ||
await addFlatpickrOption("EnableDaysOfWeek", 1, controller); | ||
it('it still work and all days are disabled', async function() { | ||
addFlatpickrOption('EnableDaysOfWeek', 1, controller) | ||
await nextFrame() | ||
const disabledDays = controller.daysTarget.querySelectorAll( | ||
"span.flatpickr-day.disabled" | ||
); | ||
expect(controller).to.exist; | ||
expect(disabledDays.length).to.be.at.least(30); | ||
}); | ||
}); | ||
}); | ||
}); | ||
const disabledDays = controller.daysTarget.querySelectorAll('span.flatpickr-day.flatpickr-disabled') | ||
expect(controller).to.exist | ||
expect(disabledDays.length).to.be.at.least(30) | ||
}) | ||
}) | ||
}) | ||
describe('Boolean options can be true/false or 1/0', function() { | ||
it('accpet 1 as a true value', async function() { | ||
addFlatpickrOption('EnableTime', 1, controller) | ||
await nextFrame() | ||
expect(controller._boolean('enable-time')).to.be.true | ||
}) | ||
it('accept "true" as a true value', async function() { | ||
addFlatpickrOption('EnableTime', 'true', controller) | ||
await nextFrame() | ||
expect(controller._boolean('enable-time')).to.be.true | ||
}) | ||
it('accept 0 as a false value', async function() { | ||
addFlatpickrOption('EnableTime', 0, controller) | ||
await nextFrame() | ||
expect(controller._boolean('enable-time')).to.be.false | ||
}) | ||
it('accept "false" as a false value', async function() { | ||
addFlatpickrOption('EnableTime', 'false', controller) | ||
await nextFrame() | ||
expect(controller._boolean('enable-time')).to.be.false | ||
}) | ||
}) | ||
}) |
@@ -1,40 +0,44 @@ | ||
import Flatpickr from "./controllers/flatpickr_controller"; | ||
import "flatpickr/dist/flatpickr.css"; | ||
import { registerController, addFlatpickrOption } from "./helpers"; | ||
import chai, { expect } from "chai"; | ||
import chaiDom from "chai-dom"; | ||
var controller; | ||
import StimulusFlatpickr from './controllers/flatpickr_controller' | ||
import { Application } from 'stimulus' | ||
import 'flatpickr/dist/flatpickr.css' | ||
import { nextFrame } from './helpers' | ||
import chai, { expect } from 'chai' | ||
import chaiDom from 'chai-dom' | ||
var controller | ||
const application = Application.start() | ||
const elementsSelectors = { | ||
calendarContainer: ".flatpickr-calendar", | ||
currentYearElement: ".cur-year", | ||
days: ".dayContainer", | ||
daysContainer: ".flatpickr-days", | ||
input: ".flatpickr-input", | ||
monthNav: ".flatpickr-months", | ||
nextMonthNav: ".flatpickr-next-month", | ||
prevMonthNav: ".flatpickr-prev-month", | ||
selectedDateElem: ".flatpickr-day.selected", | ||
rContainer: ".flatpickr-rContainer", | ||
todayDateElem: ".flatpickr-day.today", | ||
weekdayContainer: ".flatpickr-weekdays" | ||
}; | ||
calendarContainer: '.flatpickr-calendar', | ||
currentYearElement: '.cur-year', | ||
days: '.dayContainer', | ||
daysContainer: '.flatpickr-days', | ||
input: '.flatpickr-input', | ||
monthNav: '.flatpickr-months', | ||
nextMonthNav: '.flatpickr-next-month', | ||
prevMonthNav: '.flatpickr-prev-month', | ||
rContainer: '.flatpickr-rContainer', | ||
todayDateElem: '.flatpickr-day.today', | ||
weekdayContainer: '.flatpickr-weekdays' | ||
} | ||
chai.use(chaiDom); | ||
chai.use(chaiDom) | ||
describe("Flatpickr Controller Target tests", function() { | ||
before("initialize controller", async function() { | ||
fixture.load("index.html"); | ||
controller = await registerController("flatpickr", Flatpickr); | ||
await addFlatpickrOption("DefaultDate", new Date(), controller); | ||
await Promise.resolve(); | ||
}); | ||
describe('Flatpickr Controller Target tests', function() { | ||
before('initialize controller', async function() { | ||
fixture.load('index.html') | ||
application.register('datepicker', StimulusFlatpickr) | ||
await nextFrame() | ||
controller = application.controllers[0] | ||
// controller = await registerController('flatpickr', Flatpickr) | ||
// await addFlatpickrOption('DefaultDate', new Date(), controller) | ||
// await Promise.resolve() | ||
}) | ||
Object.keys(elementsSelectors).forEach(element => { | ||
const selector = elementsSelectors[element]; | ||
Object.keys(elementsSelectors).forEach((element) => { | ||
const selector = elementsSelectors[element] | ||
it(`${element}Target`, async function() { | ||
expect(controller[`${element}Target`]).to.exist; | ||
expect(controller[`${element}Target`]).to.match(selector); | ||
}); | ||
}); | ||
}); | ||
expect(controller[`${element}Target`]).to.match(selector) | ||
expect(controller[`${element}Target`]).to.exist | ||
}) | ||
}) | ||
}) |
@@ -1,46 +0,44 @@ | ||
import { Application } from "stimulus"; | ||
import { Application } from 'stimulus' | ||
const nextFrame = async () => { | ||
return new Promise((resolve) => requestAnimationFrame(resolve)) | ||
} | ||
async function registerController(element, controllerType) { | ||
const stimulusApp = Application.start(); | ||
stimulusApp.register(element, controllerType); | ||
const stimulusApp = Application.start() | ||
stimulusApp.register(element, controllerType) | ||
return new Promise(resolve => | ||
return new Promise((resolve) => | ||
setTimeout(() => { | ||
resolve(stimulusApp.controllers[0]); | ||
resolve(stimulusApp.controllers[0]) | ||
}) | ||
); | ||
) | ||
} | ||
function flatpickrCalendar() { | ||
return document.querySelector(".flatpickr-calendar"); | ||
return document.querySelector('.flatpickr-calendar') | ||
} | ||
async function addFlatpickrOption(option, value, controller) { | ||
const flatpickr = fixture.el.querySelector("#datepicker"); | ||
flatpickr.dataset[`flatpickr${option}`] = | ||
(typeof value === "object") ? JSON.stringify(value) : value; | ||
controller.connect(); | ||
return new Promise(resolve => | ||
setTimeout(() => { | ||
resolve(flatpickr); | ||
}) | ||
); | ||
function addFlatpickrOption(option, value, controller) { | ||
const flatpickr = fixture.el.querySelector('#datepicker') | ||
flatpickr.dataset[`datepicker${option}`] = typeof value === 'object' ? JSON.stringify(value) : value | ||
controller.connect() | ||
// await nextFrame() | ||
} | ||
function fixtureQuerySelector(selector) { | ||
return fixture.el.querySelector(selector); | ||
return fixture.el.querySelector(selector) | ||
} | ||
function calendarQuerySelector(selector) { | ||
return document.querySelector(`.flatpickr-calendar ${selector}`); | ||
return document.querySelector(`.flatpickr-calendar ${selector}`) | ||
} | ||
function resetDataAttributes(controller) { | ||
const attributes = controller.element.dataset; | ||
Object.keys(attributes).forEach(attribute => { | ||
delete controller.element.dataset[attribute]; | ||
}); | ||
controller.element.dataset.controller = "flatpickr"; | ||
controller.connect(); | ||
const attributes = controller.element.dataset | ||
Object.keys(attributes).forEach((attribute) => { | ||
delete controller.element.dataset[attribute] | ||
}) | ||
controller.element.dataset.controller = 'flatpickr' | ||
controller.connect() | ||
} | ||
@@ -50,9 +48,9 @@ | ||
before(title, function() { | ||
const suites = this.test.parent.suites || []; | ||
suites.forEach(s => { | ||
s.beforeAll(fn); | ||
const hook = s._beforeAll.pop(); | ||
s._beforeAll.unshift(hook); | ||
}); | ||
}); | ||
const suites = this.test.parent.suites || [] | ||
suites.forEach((s) => { | ||
s.beforeAll(fn) | ||
const hook = s._beforeAll.pop() | ||
s._beforeAll.unshift(hook) | ||
}) | ||
}) | ||
} | ||
@@ -67,3 +65,4 @@ | ||
resetDataAttributes, | ||
beforeEachSuite | ||
}; | ||
beforeEachSuite, | ||
nextFrame | ||
} |
@@ -1,67 +0,63 @@ | ||
import { expect } from "chai"; | ||
import { convertDateFormat } from "../src/strftime_mapping"; | ||
import { convertDateFormat } from '../src/strftime_mapping' | ||
import { expect } from 'chai' | ||
const testDateFormats = { | ||
"%Y-%m-%d": "Y-m-d", | ||
"%B %d, %Y": "F d, Y", | ||
"%b %d": "M d", | ||
"%d/%m/%Y": "d/m/Y", | ||
"%e %b": "j M", | ||
"%e %B %Y": "j F Y" | ||
}; | ||
'%Y-%m-%d': 'Y-m-d', | ||
'%B %d, %Y': 'F d, Y', | ||
'%b %d': 'M d', | ||
'%d/%m/%Y': 'd/m/Y', | ||
'%e %b': 'j M', | ||
'%e %B %Y': 'j F Y' | ||
} | ||
const mapping = { | ||
"%Y": "Y", | ||
"%y": "y", | ||
"%C": "Y", | ||
"%m": "m", | ||
"%-m": "n", | ||
"%_m": "n", | ||
"%B": "F", | ||
"%^B": "F", | ||
"%b": "M", | ||
"%^b": "M", | ||
"%h": "M", | ||
"%^h": "M", | ||
"%d": "d", | ||
"%-d": "j", | ||
"%e": "j", | ||
"%H": "H", | ||
"%k": "H", | ||
"%I": "h", | ||
"%l": "h", | ||
"%P": "K", | ||
"%p": "K", | ||
"%M": "i", | ||
"%S": "S", | ||
"%A": "l", | ||
"%a": "D", | ||
"%w": "w" | ||
}; | ||
'%Y': 'Y', | ||
'%y': 'y', | ||
'%C': 'Y', | ||
'%m': 'm', | ||
'%-m': 'n', | ||
'%_m': 'n', | ||
'%B': 'F', | ||
'%^B': 'F', | ||
'%b': 'M', | ||
'%^b': 'M', | ||
'%h': 'M', | ||
'%^h': 'M', | ||
'%d': 'd', | ||
'%-d': 'j', | ||
'%e': 'j', | ||
'%H': 'H', | ||
'%k': 'H', | ||
'%I': 'h', | ||
'%l': 'h', | ||
'%P': 'K', | ||
'%p': 'K', | ||
'%M': 'i', | ||
'%S': 'S', | ||
'%A': 'l', | ||
'%a': 'D', | ||
'%w': 'w' | ||
} | ||
describe("strftime date conversion to Flatpickr tokens", function() { | ||
describe("convertDateFormat", function() { | ||
it("random string without % should not be changed", function() { | ||
const testString = "eznlen =:=:;:::; =:;fzlefnlzief &é&ééçà(!345345345)"; | ||
expect(convertDateFormat(testString)).to.equal(testString); | ||
}); | ||
describe('strftime date conversion to Flatpickr tokens', function() { | ||
context('convertDateFormat', function() { | ||
it('random string without % should not be changed', function() { | ||
const testString = 'eznlen =:=:;:::; =:;fzlefnlzief &é&ééçà(!345345345)' | ||
expect(convertDateFormat(testString)).to.equal(testString) | ||
}) | ||
Object.keys(testDateFormats).forEach(strftimeDateFormat => { | ||
const flatpickrDateFormat = testDateFormats[strftimeDateFormat]; | ||
Object.keys(testDateFormats).forEach((strftimeDateFormat) => { | ||
const flatpickrDateFormat = testDateFormats[strftimeDateFormat] | ||
it(`strftime format ${strftimeDateFormat} to be converted to ${flatpickrDateFormat}`, function() { | ||
expect(convertDateFormat(strftimeDateFormat)).to.equal( | ||
flatpickrDateFormat | ||
); | ||
}); | ||
}); | ||
expect(convertDateFormat(strftimeDateFormat)).to.equal(flatpickrDateFormat) | ||
}) | ||
}) | ||
it(`strftime format to be converted to `, function() { | ||
Object.keys(mapping).forEach(strftimeDateFormat => { | ||
const flatpickrDateFormat = mapping[strftimeDateFormat]; | ||
expect(convertDateFormat(strftimeDateFormat)).to.equal( | ||
flatpickrDateFormat | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('strftime format to be converted to', function() { | ||
Object.keys(mapping).forEach((strftimeDateFormat) => { | ||
const flatpickrDateFormat = mapping[strftimeDateFormat] | ||
expect(convertDateFormat(strftimeDateFormat)).to.equal(flatpickrDateFormat) | ||
}) | ||
}) | ||
}) | ||
}) |
const booleanOptions = [ | ||
"allowInput", | ||
"altInput", | ||
"animate", | ||
"clickOpens", | ||
"closeOnSelect", | ||
"disableMobile", | ||
"enableSeconds", | ||
"enableTime", | ||
"inline", | ||
"noCalendar", | ||
"shorthandCurrentMonth", | ||
"static", | ||
"time_24hr", | ||
"weekNumbers", | ||
"wrap" | ||
]; | ||
'allowInput', | ||
'altInput', | ||
'animate', | ||
'clickOpens', | ||
'closeOnSelect', | ||
'disableMobile', | ||
'enableSeconds', | ||
'enableTime', | ||
'inline', | ||
'noCalendar', | ||
'shorthandCurrentMonth', | ||
'static', | ||
'time_24hr', | ||
'weekNumbers', | ||
'wrap' | ||
] | ||
const stringOptions = [ | ||
"altInputClass", | ||
"conjunction", | ||
"defaultDate", | ||
"mode", | ||
"nextArrow", | ||
"position", | ||
"prevArrow" | ||
]; | ||
const stringOptions = ['altInputClass', 'conjunction', 'defaultDate', 'mode', 'nextArrow', 'position', 'prevArrow'] | ||
const numberOptions = [ | ||
"defaultHour", | ||
"defaultMinute", | ||
"defaultSeconds", | ||
"hourIncrement", | ||
"minuteIncrement", | ||
"showMonths" | ||
]; | ||
'defaultHour', | ||
'defaultMinute', | ||
'defaultSeconds', | ||
'hourIncrement', | ||
'minuteIncrement', | ||
'showMonths' | ||
] | ||
const arrayOptions = [ | ||
"disable", | ||
"enable", | ||
"disableDaysOfWeek", | ||
"enableDaysOfWeek" | ||
]; | ||
const arrayOptions = ['disable', 'enable', 'disableDaysOfWeek', 'enableDaysOfWeek'] | ||
const dateOptions = ["maxDate", "minDate", "maxTime", "minTime", "now"]; | ||
const dateOptions = ['maxDate', 'minDate', 'maxTime', 'minTime', 'now'] | ||
export const dateFormats = ["altFormat", "ariaDateFormat", "dateFormat"]; | ||
export const dateFormats = ['altFormat', 'ariaDateFormat', 'dateFormat'] | ||
@@ -55,2 +42,2 @@ export const options = { | ||
number: numberOptions | ||
}; | ||
} |
export const elements = [ | ||
"calendarContainer", | ||
"currentYearElement", | ||
"days", | ||
"daysContainer", | ||
"input", | ||
"nextMonthNav", | ||
"monthNav", | ||
"prevMonthNav", | ||
"rContainer", | ||
"selectedDateElem", | ||
"todayDateElem", | ||
"weekdayContainer" | ||
]; | ||
'calendarContainer', | ||
'currentYearElement', | ||
'days', | ||
'daysContainer', | ||
'input', | ||
'nextMonthNav', | ||
'monthNav', | ||
'prevMonthNav', | ||
'rContainer', | ||
'selectedDateElem', | ||
'todayDateElem', | ||
'weekdayContainer' | ||
] |
@@ -1,10 +0,1 @@ | ||
export const events = [ | ||
"change", | ||
"open", | ||
"close", | ||
"monthChange", | ||
"yearChange", | ||
"ready", | ||
"valueUpdate", | ||
"dayCreate" | ||
]; | ||
export const events = ['change', 'open', 'close', 'monthChange', 'yearChange', 'ready', 'valueUpdate', 'dayCreate'] |
export const mapping = { | ||
"%Y": "Y", | ||
"%y": "y", | ||
"%C": "Y", | ||
"%m": "m", | ||
"%-m": "n", | ||
"%_m": "n", | ||
"%B": "F", | ||
"%^B": "F", | ||
"%b": "M", | ||
"%^b": "M", | ||
"%h": "M", | ||
"%^h": "M", | ||
"%d": "d", | ||
"%-d": "j", | ||
"%e": "j", | ||
"%H": "H", | ||
"%k": "H", | ||
"%I": "h", | ||
"%l": "h", | ||
"%P": "K", | ||
"%p": "K", | ||
"%M": "i", | ||
"%S": "S", | ||
"%A": "l", | ||
"%a": "D", | ||
"%w": "w" | ||
}; | ||
'%Y': 'Y', | ||
'%y': 'y', | ||
'%C': 'Y', | ||
'%m': 'm', | ||
'%-m': 'n', | ||
'%_m': 'n', | ||
'%B': 'F', | ||
'%^B': 'F', | ||
'%b': 'M', | ||
'%^b': 'M', | ||
'%h': 'M', | ||
'%^h': 'M', | ||
'%d': 'd', | ||
'%-d': 'j', | ||
'%e': 'j', | ||
'%H': 'H', | ||
'%k': 'H', | ||
'%I': 'h', | ||
'%l': 'h', | ||
'%P': 'K', | ||
'%p': 'K', | ||
'%M': 'i', | ||
'%S': 'S', | ||
'%A': 'l', | ||
'%a': 'D', | ||
'%w': 'w' | ||
} | ||
const strftimeRegex = new RegExp( | ||
Object.keys(mapping) | ||
.join("|") | ||
.replace(new RegExp("\\^", "g"), "\\^"), | ||
"g" | ||
); | ||
.join('|') | ||
.replace(new RegExp('\\^', 'g'), '\\^'), | ||
'g' | ||
) | ||
export const convertDateFormat = format => { | ||
return format.replace(strftimeRegex, match => { | ||
return mapping[match]; | ||
}); | ||
}; | ||
export const convertDateFormat = (format) => { | ||
return format.replace(strftimeRegex, (match) => { | ||
return mapping[match] | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
320210
49
2134
420
44
1
Updatedflatpickr@>=4.6.0