2021-05-13 11:10:20 -04:00
|
|
|
import * as Pikaday from 'pikaday';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-05-13 11:10:20 -04:00
|
|
|
import initDatePickers from '~/behaviors/date_picker';
|
|
|
|
import * as utils from '~/lib/utils/datetime_utility';
|
|
|
|
|
|
|
|
jest.mock('pikaday');
|
|
|
|
jest.mock('~/lib/utils/datetime_utility');
|
|
|
|
|
|
|
|
describe('date_picker behavior', () => {
|
|
|
|
let pikadayMock;
|
|
|
|
let parseMock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
pikadayMock = jest.spyOn(Pikaday, 'default');
|
|
|
|
parseMock = jest.spyOn(utils, 'parsePikadayDate');
|
2022-05-13 08:08:49 -04:00
|
|
|
setHTMLFixture(`
|
2021-05-13 11:10:20 -04:00
|
|
|
<div>
|
|
|
|
<input class="datepicker" value="2020-10-01" />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input class="datepicker" value="" />
|
|
|
|
</div>`);
|
|
|
|
});
|
|
|
|
|
2022-05-13 08:08:49 -04:00
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2021-05-13 11:10:20 -04:00
|
|
|
it('Instantiates Pickaday for every instance of a .datepicker class', () => {
|
|
|
|
initDatePickers();
|
|
|
|
|
|
|
|
expect(pikadayMock.mock.calls.length).toEqual(2);
|
|
|
|
expect(parseMock.mock.calls).toEqual([['2020-10-01'], ['']]);
|
|
|
|
});
|
|
|
|
});
|