diff --git a/ember-flatpickr/package.json b/ember-flatpickr/package.json index 6cb85a3b..c123197f 100644 --- a/ember-flatpickr/package.json +++ b/ember-flatpickr/package.json @@ -41,7 +41,8 @@ }, "dependencies": { "@ember/render-modifiers": "^2.0.3", - "@ember/test-helpers": "~3.3.0", + "@ember/test-helpers": "^3.3.0", + "@ember/test-waiters": "^3.1.0", "@embroider/addon-shim": "^1.8.7" }, "devDependencies": { diff --git a/ember-flatpickr/src/components/ember-flatpickr.ts b/ember-flatpickr/src/components/ember-flatpickr.ts index ed9baa20..75c7b604 100644 --- a/ember-flatpickr/src/components/ember-flatpickr.ts +++ b/ember-flatpickr/src/components/ember-flatpickr.ts @@ -4,6 +4,7 @@ import Component from '@glimmer/component'; import { action } from '@ember/object'; import { assert } from '@ember/debug'; import { scheduleOnce } from '@ember/runloop'; +import { waitForPromise } from '@ember/test-waiters'; import type { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance'; import type { BaseOptions as FlatpickrOptions } from 'flatpickr/dist/types/options'; import flatpickr from 'flatpickr'; @@ -133,8 +134,10 @@ export default class EmberFlatpickr extends Component { Object.entries(rest).filter((entry) => entry[1] !== undefined), ); - if (typeof this.args.locale === 'string' && this.args.locale !== "en") { - await import(`flatpickr/dist/l10n/${this.args.locale}.js`); + if (typeof this.args.locale === 'string' && this.args.locale !== 'en') { + await waitForPromise( + import(`flatpickr/dist/l10n/${this.args.locale}.js`), + ); } this.flatpickrRef = flatpickr(element, { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e41496c..76e44849 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,11 @@ importers: specifier: ^2.0.3 version: 2.1.0(@babel/core@7.24.0)(ember-source@5.7.0) '@ember/test-helpers': - specifier: ~3.3.0 + specifier: ^3.3.0 version: 3.3.0(ember-source@5.7.0)(webpack@5.90.3) + '@ember/test-waiters': + specifier: ^3.1.0 + version: 3.1.0 '@embroider/addon-shim': specifier: ^1.8.7 version: 1.8.7 diff --git a/test-app/tests/integration/components/ember-flatpickr-test.js b/test-app/tests/integration/components/ember-flatpickr-test.js index 35d97b05..2b0e9631 100644 --- a/test-app/tests/integration/components/ember-flatpickr-test.js +++ b/test-app/tests/integration/components/ember-flatpickr-test.js @@ -6,8 +6,8 @@ import { render, find, findAll, + settled, triggerEvent, - waitFor, } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; import { @@ -431,7 +431,7 @@ module('Integration | Component | ember flatpickr', function (hooks) { assert.strictEqual(enabledDays[1].textContent, '25'); }); - test('locale works correctly', async function (assert) { + test('locale as object works correctly', async function (assert) { assert.expect(1); this.set('dateValue', '2080-12-01T16:16:22.585Z'); @@ -463,7 +463,6 @@ module('Integration | Component | ember flatpickr', function (hooks) { this.set('dateValue', '2080-12-01T16:16:22.585Z'); this.set('maxDate', '2080-12-31T16:16:22.585Z'); this.set('minDate', '2080-12-01T16:16:22.585Z'); - this.set('locale', 'fr'); await render(hbs``); - await waitFor('.flatpickr-current-month .flatpickr-monthDropdown-month'); - assert.strictEqual( find( '.flatpickr-current-month .flatpickr-monthDropdown-month', @@ -486,7 +483,7 @@ module('Integration | Component | ember flatpickr', function (hooks) { ); }); - test('onLocaleUpdated fired', async function (assert) { + test('onLocaleUpdated (locale as object)', async function (assert) { assert.expect(1); this.set('dateValue', '2080-12-01T16:16:22.585Z'); @@ -504,6 +501,38 @@ module('Integration | Component | ember flatpickr', function (hooks) { />`); this.set('locale', langs.ru); + await settled(); + + await openFlatpickr(); + + assert.strictEqual( + find( + '.flatpickr-current-month .flatpickr-monthDropdown-month', + ).textContent.trim(), + 'Декабрь', + 'Russian locale applied successfully', + ); + }); + + test('onLocaleUpdated (locale as string)', async function (assert) { + assert.expect(1); + + this.set('dateValue', '2080-12-01T16:16:22.585Z'); + this.set('maxDate', '2080-12-31T16:16:22.585Z'); + this.set('minDate', '2080-12-01T16:16:22.585Z'); + this.set('locale', 'fr'); + + await render(hbs``); + + this.set('locale', 'ru'); + await settled(); await openFlatpickr();