|
| 1 | +/* eslint-disable i18n/no-russian-character */ |
| 2 | +/* eslint-disable spellcheck/spell-checker */ |
| 3 | +import { |
| 4 | + afterEach, describe, expect, it, |
| 5 | +} from '@jest/globals'; |
| 6 | +import type { dxElementWrapper } from '@js/core/renderer'; |
| 7 | +import $ from '@js/core/renderer'; |
| 8 | +import { loadMessages, locale } from '@js/localization'; |
| 9 | + |
| 10 | +import type { Properties as SchedulerProperties } from '../../../ui/scheduler'; |
| 11 | +import Scheduler from '../../../ui/scheduler'; |
| 12 | + |
| 13 | +const SCHEDULER_CONTAINER_ID = 'schedulerContainer'; |
| 14 | + |
| 15 | +const SELECTORS = { |
| 16 | + schedulerContainer: '#schedulerContainer', |
| 17 | + invisibleState: '.dx-state-invisible', |
| 18 | + viewSwitcher: '.dx-scheduler-view-switcher', |
| 19 | + viewSwitcherButton: '.dx-scheduler-view-switcher .dx-button', |
| 20 | +}; |
| 21 | + |
| 22 | +const createScheduler = (options: SchedulerProperties): Promise<{ |
| 23 | + $container: dxElementWrapper; instance: Scheduler; |
| 24 | +}> => new Promise((resolve) => { |
| 25 | + const $container = $('<div>') |
| 26 | + .attr('id', SCHEDULER_CONTAINER_ID) |
| 27 | + .appendTo(document.body); |
| 28 | + |
| 29 | + const instance = new Scheduler($container.get(0) as HTMLDivElement, { |
| 30 | + ...options, |
| 31 | + onContentReady: (): void => { |
| 32 | + resolve({ $container, instance }); |
| 33 | + }, |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('ViewSwitcher', () => { |
| 38 | + afterEach(() => { |
| 39 | + const $container = $(SELECTORS.schedulerContainer); |
| 40 | + |
| 41 | + const scheduler = ($container as any).dxScheduler('instance') as Scheduler; |
| 42 | + |
| 43 | + scheduler.dispose(); |
| 44 | + $container.remove(); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('Localization', () => { |
| 48 | + it('should display Russian view names when locale is set to Russian', async () => { |
| 49 | + loadMessages({ |
| 50 | + ru: { |
| 51 | + 'dxScheduler-switcherDay': 'День', |
| 52 | + 'dxScheduler-switcherWeek': 'Неделя', |
| 53 | + 'dxScheduler-switcherMonth': 'Месяц', |
| 54 | + }, |
| 55 | + }); |
| 56 | + locale('ru'); |
| 57 | + |
| 58 | + const { $container } = await createScheduler({ |
| 59 | + useDropDownViewSwitcher: false, |
| 60 | + currentView: 'day', |
| 61 | + views: ['day', 'week', 'month'], |
| 62 | + }); |
| 63 | + |
| 64 | + const buttons = $container.find(SELECTORS.viewSwitcherButton); |
| 65 | + const buttonTexts: string[] = []; |
| 66 | + buttons.each((_, button) => { |
| 67 | + buttonTexts.push($(button).text()); |
| 68 | + return true; |
| 69 | + }); |
| 70 | + |
| 71 | + expect(buttonTexts).toContain('День'); |
| 72 | + expect(buttonTexts).toContain('Неделя'); |
| 73 | + expect(buttonTexts).toContain('Месяц'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should display Russian view names in dropdown switcher when locale is set to Russian', async () => { |
| 77 | + loadMessages({ |
| 78 | + ru: { |
| 79 | + 'dxScheduler-switcherDay': 'День', |
| 80 | + 'dxScheduler-switcherWeek': 'Неделя', |
| 81 | + 'dxScheduler-switcherMonth': 'Месяц', |
| 82 | + }, |
| 83 | + }); |
| 84 | + locale('ru'); |
| 85 | + |
| 86 | + const { $container } = await createScheduler({ |
| 87 | + useDropDownViewSwitcher: true, |
| 88 | + currentView: 'day', |
| 89 | + views: ['day', 'week', 'month'], |
| 90 | + }); |
| 91 | + |
| 92 | + const viewSwitcher = $container.find(SELECTORS.viewSwitcher); |
| 93 | + const dropdown = viewSwitcher.find('.dx-dropdownbutton'); |
| 94 | + const buttonText = dropdown.find('.dx-button-text'); |
| 95 | + |
| 96 | + expect(buttonText.text()).toBe('День'); |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments