| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- describe('i18n', () => {
- const id = 'testContainer';
- const DEFAULT_LANGUAGE_CODE = 'en-US';
- const NOT_EXISTING_LANGUAGE_CODE = 'bs-GY';
- const NOT_EXISTING_LANGUAGE_CODE2 = 'dd-Da';
- const POLISH_LANGUAGE_CODE = 'pl-PL';
- const INSERT_ROW_ABOVE_IN_DEFAULT_LANGUAGE = 'Insert row above';
- const INSERT_ROW_ABOVE_IN_POLISH_LANGUAGE = 'Wstaw wiersz powyżej';
- beforeEach(function() {
- this.$container = $(`<div id="${id}"></div>`).appendTo('body');
- });
- afterEach(function() {
- if (this.$container) {
- destroy();
- this.$container.remove();
- }
- });
- it('should not propagate `language` key to meta of cells', () => {
- handsontable({
- language: POLISH_LANGUAGE_CODE
- });
- expect(getCellMeta(0, 0).language).toBeUndefined();
- });
- describe('Hook `beforeLanguageChange`', () => {
- it('should not call the `beforeLanguageChange` at start (`language` key have not been set)', () => {
- let beforeLanguageChangeCalled = false;
- handsontable({
- beforeLanguageChange() {
- beforeLanguageChangeCalled = true;
- }
- });
- expect(beforeLanguageChangeCalled).toEqual(false);
- });
- it('should not call the `beforeLanguageChange` at start (`language` key have been set)', () => {
- let beforeLanguageChangeCalled = false;
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- beforeLanguageChange() {
- beforeLanguageChangeCalled = true;
- }
- });
- expect(beforeLanguageChangeCalled).toEqual(false);
- });
- it('should call the `beforeLanguageChange` before updating settings', () => {
- let languageInsideHook;
- handsontable({
- beforeLanguageChange() {
- const settings = this.getSettings();
- languageInsideHook = settings.language;
- }
- });
- updateSettings({
- language: POLISH_LANGUAGE_CODE
- });
- expect(languageInsideHook).toEqual(DEFAULT_LANGUAGE_CODE);
- });
- });
- describe('Hook `afterLanguageChange`', () => {
- it('should not call the `afterLanguageChange` at start (`language` key have not been set)', () => {
- let afterLanguageChangeCalled = false;
- handsontable({
- afterLanguageChange() {
- afterLanguageChangeCalled = true;
- }
- });
- expect(afterLanguageChangeCalled).toEqual(false);
- });
- it('should not call the `afterLanguageChange` at start (`language` key have been set)', () => {
- let afterLanguageChangeCalled = false;
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- afterLanguageChange() {
- afterLanguageChangeCalled = true;
- }
- });
- expect(afterLanguageChangeCalled).toEqual(false);
- });
- it('should call the `afterLanguageChange` after updating settings', () => {
- let languageInsideHook;
- handsontable({
- afterLanguageChange() {
- const settings = this.getSettings();
- languageInsideHook = settings.language;
- }
- });
- updateSettings({
- language: POLISH_LANGUAGE_CODE
- });
- expect(languageInsideHook).toEqual(POLISH_LANGUAGE_CODE);
- });
- });
- describe('translation does not throw exceptions', () => {
- it('should not throw error when setting not existing language code at start', async() => {
- spyOn(console, 'error'); // overriding console.error
- const spy = spyOn(window, 'onerror');
- handsontable({
- language: NOT_EXISTING_LANGUAGE_CODE
- });
- await sleep(100);
- expect(spy).not.toHaveBeenCalled();
- });
- it('should not throw error when setting directly default language code at start', async() => {
- const spy = spyOn(window, 'onerror');
- handsontable({
- language: DEFAULT_LANGUAGE_CODE
- });
- await sleep(100);
- expect(spy).not.toHaveBeenCalled();
- });
- it('should not throw error when trying to set not existing language code by updateSettings', async() => {
- spyOn(console, 'error'); // overriding console.error
- const spy = spyOn(window, 'onerror');
- handsontable();
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- await sleep(100);
- expect(spy).not.toHaveBeenCalled();
- });
- it('should not throw error when trying to set directly default language code by updateSettings', async() => {
- const spy = spyOn(window, 'onerror');
- handsontable();
- updateSettings({ language: DEFAULT_LANGUAGE_CODE });
- await sleep(100);
- expect(spy).not.toHaveBeenCalled();
- });
- });
- describe('translation log error when needed', () => {
- it('should log error when setting not existing language code at start', () => {
- const spy = spyOn(console, 'error');
- handsontable({
- language: NOT_EXISTING_LANGUAGE_CODE
- });
- expect(spy).toHaveBeenCalled();
- });
- it('should log error when trying to set not existing language code by updateSettings', () => {
- const spy = spyOn(console, 'error');
- handsontable();
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- expect(spy).toHaveBeenCalled();
- });
- it('should not log error when setting directly default language code at start', () => {
- const spy = spyOn(console, 'error');
- handsontable({
- language: DEFAULT_LANGUAGE_CODE
- });
- expect(spy).not.toHaveBeenCalled();
- });
- it('should not log error when trying to set directly default language code by updateSettings', () => {
- const spy = spyOn(console, 'error');
- handsontable();
- updateSettings({ language: DEFAULT_LANGUAGE_CODE });
- expect(spy).not.toHaveBeenCalled();
- });
- });
- describe('settings', () => {
- it('should set default language code at start', () => {
- const hot = handsontable();
- expect(hot.getSettings().language).toEqual(DEFAULT_LANGUAGE_CODE);
- });
- it('should not set language code as own property of settings object at start', () => {
- const hot = handsontable();
- // eslint-disable-next-line no-prototype-builtins
- expect(hot.getSettings().hasOwnProperty('language')).toEqual(false);
- });
- it('should not set language code as own property of settings object when using updateSettings', () => {
- const hot = handsontable();
- updateSettings({ language: POLISH_LANGUAGE_CODE });
- // eslint-disable-next-line no-prototype-builtins
- expect(hot.getSettings().hasOwnProperty('language')).toEqual(false);
- });
- it('should set proper `language` key when trying to set not existing language code at start', () => {
- spyOn(console, 'error'); // overriding console.error
- const hot = handsontable({
- language: NOT_EXISTING_LANGUAGE_CODE
- });
- expect(hot.getSettings().language).toEqual(DEFAULT_LANGUAGE_CODE);
- });
- it('should set proper `language` key when trying to set not existing language code by updateSettings #1', () => {
- spyOn(console, 'error'); // overriding console.error
- const hot = handsontable();
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- expect(hot.getSettings().language).toEqual(DEFAULT_LANGUAGE_CODE);
- });
- it('should set proper `language` key when trying to set not existing language code by updateSettings #2', () => {
- spyOn(console, 'error'); // overriding console.error
- const hot = handsontable({
- language: POLISH_LANGUAGE_CODE
- });
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- expect(hot.getSettings().language).toEqual(POLISH_LANGUAGE_CODE);
- });
- it('should accept not normalized language code by default #1', () => {
- const hot = handsontable({
- language: POLISH_LANGUAGE_CODE.toLowerCase()
- });
- expect(hot.getSettings().language).toEqual(POLISH_LANGUAGE_CODE);
- });
- it('should accept not normalized language code by default #2', () => {
- const hot = handsontable();
- updateSettings({
- language: POLISH_LANGUAGE_CODE.toUpperCase()
- });
- expect(hot.getSettings().language).toEqual(POLISH_LANGUAGE_CODE);
- });
- it('should not change language when `language` key passed to `updateSettings` was not set', () => {
- const hot = handsontable({
- language: POLISH_LANGUAGE_CODE
- });
- updateSettings({
- fillHandle: true
- });
- expect(hot.getSettings().language).toEqual(POLISH_LANGUAGE_CODE);
- });
- });
- describe('contextMenu translation', () => {
- it('should translate contextMenu UI when setting existing language code at start', () => {
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['row_above']
- });
- selectCell(0, 0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_POLISH_LANGUAGE);
- });
- it('should not change default contextMenu UI when trying to set not existing language code at start', () => {
- spyOn(console, 'error'); // overriding console.error
- handsontable({
- language: NOT_EXISTING_LANGUAGE_CODE,
- contextMenu: ['row_above']
- });
- selectCell(0, 0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_DEFAULT_LANGUAGE);
- });
- it('should translate contextMenu UI when setting existing language code by updateSettings', async() => {
- handsontable({
- contextMenu: ['row_above']
- });
- updateSettings({ language: POLISH_LANGUAGE_CODE });
- await sleep(0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_POLISH_LANGUAGE);
- });
- it('should not change default contextMenu UI when trying to set not existing language code by updateSettings #1', async() => {
- spyOn(console, 'error'); // overriding console.error
- handsontable({
- contextMenu: ['row_above']
- });
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- await sleep(0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_DEFAULT_LANGUAGE);
- });
- it('should not change default contextMenu UI when trying to set not existing language code by updateSettings #2', async() => {
- spyOn(console, 'error'); // overriding console.error
- handsontable({
- language: NOT_EXISTING_LANGUAGE_CODE,
- contextMenu: ['row_above']
- });
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE2 });
- await sleep(0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_DEFAULT_LANGUAGE);
- });
- it('should not change previously translated contextMenu UI when trying to set not existing language code by updateSettings', async() => {
- spyOn(console, 'error'); // overriding console.error
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['row_above']
- });
- updateSettings({ language: NOT_EXISTING_LANGUAGE_CODE });
- await sleep(0);
- contextMenu();
- const $contextMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($contextMenuItem.text()).toEqual(INSERT_ROW_ABOVE_IN_POLISH_LANGUAGE);
- });
- it('should translate multi-level menu properly', async() => {
- const ALIGN_LEFT_IN_POLISH = 'Do lewej';
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['alignment']
- });
- selectCell(0, 0);
- contextMenu();
- const $menu = $('.htSubmenu');
- $menu.simulate('mouseover');
- await sleep(300);
- const $submenuItem = $('.htContextMenu').eq(1).find('tbody td:not(.htSeparator)').eq(0);
- expect($submenuItem.text()).toEqual(ALIGN_LEFT_IN_POLISH);
- });
- it('should choose proper form of phrase when translating', () => {
- const REMOVE_ROW_PLURAL_IN_DEFAULT_LANGUAGE = 'Remove rows';
- const REMOVE_COLUMN_PLURAL_IN_DEFAULT_LANGUAGE = 'Remove columns';
- handsontable({
- contextMenu: ['remove_row', 'remove_col']
- });
- selectCell(0, 0, 2, 2);
- contextMenu();
- const $removeRowItem = $('.htContextMenu').eq(0).find('tbody td:not(.htSeparator)').eq(0);
- const $removeColumnItem = $('.htContextMenu').eq(0).find('tbody td:not(.htSeparator)').eq(1);
- expect($removeRowItem.text()).toEqual(REMOVE_ROW_PLURAL_IN_DEFAULT_LANGUAGE);
- expect($removeColumnItem.text()).toEqual(REMOVE_COLUMN_PLURAL_IN_DEFAULT_LANGUAGE);
- });
- it('should translate item from enabled `freezeColumn` plugin when setting existing language code at start', () => {
- const FREEZE_COLUMN_IN_POLISH_LANGUAGE = 'Zablokuj kolumnę';
- handsontable({
- contextMenu: ['freeze_column'],
- manualColumnFreeze: true,
- language: POLISH_LANGUAGE_CODE,
- });
- selectCell(0, 0);
- contextMenu();
- const $freezeColumnMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($freezeColumnMenuItem.text()).toEqual(FREEZE_COLUMN_IN_POLISH_LANGUAGE);
- });
- it('should translate item from enabled `comments` plugin when setting existing language code at start', () => {
- const ADD_COMMENT_IN_POLISH_LANGUAGE = 'Dodaj komentarz';
- handsontable({
- contextMenu: ['commentsAddEdit'],
- comments: true,
- language: POLISH_LANGUAGE_CODE,
- });
- selectCell(0, 0);
- contextMenu();
- const $addCommentMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($addCommentMenuItem.text()).toEqual(ADD_COMMENT_IN_POLISH_LANGUAGE);
- });
- it('should translate item from enabled `customBorders` plugin when setting existing language code at start', () => {
- const BORDERS_IN_POLISH = 'Obramowanie';
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['borders'],
- customBorders: true
- });
- selectCell(0, 0);
- contextMenu();
- const $bordersMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($bordersMenuItem.text()).toEqual(BORDERS_IN_POLISH);
- });
- it('should translate item from enabled `mergeCells` plugin when setting existing language code at start', () => {
- const MERGE_CELLS_IN_POLISH = 'Scal komórki';
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['mergeCells'],
- mergeCells: true
- });
- selectCell(0, 0);
- contextMenu();
- const $mergeCellsMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($mergeCellsMenuItem.text()).toEqual(MERGE_CELLS_IN_POLISH);
- });
- it('should translate item from enabled `copyPaste` plugin when setting existing language code at start', () => {
- const COPY_IN_POLISH = 'Kopiuj';
- handsontable({
- language: POLISH_LANGUAGE_CODE,
- contextMenu: ['copy'],
- copyPaste: true
- });
- selectCell(0, 0);
- contextMenu();
- const $copyMenuItem = $('.htContextMenu tbody td:not(.htSeparator)');
- expect($copyMenuItem.text()).toEqual(COPY_IN_POLISH);
- });
- });
- });
|