From b9100fe0bdbf6a8e033465b075036beca5dd78d8 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 9 Dec 2021 12:14:05 +0800 Subject: [PATCH 01/12] change coverage of core to 100% --- .codecov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codecov.yml b/.codecov.yml index 4d86439e9969d..149042367ab18 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -16,7 +16,7 @@ coverage: target: auto threshold: 0% core-packages-ts: - target: 95% + target: 100% paths: - 'superset-frontend/packages' - '!superset-frontend/packages/**/*.jsx' From 3ed00269d575b2b395106f46ac41879ac62213e8 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 9 Dec 2021 12:25:50 +0800 Subject: [PATCH 02/12] wip --- .../src/color/CategoricalColorNamespace.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/color/CategoricalColorNamespace.ts b/superset-frontend/packages/superset-ui-core/src/color/CategoricalColorNamespace.ts index 7e28cae6babac..9c56d5114b9d9 100644 --- a/superset-frontend/packages/superset-ui-core/src/color/CategoricalColorNamespace.ts +++ b/superset-frontend/packages/superset-ui-core/src/color/CategoricalColorNamespace.ts @@ -40,12 +40,7 @@ export default class CategoricalColorNamespace { getScale(schemeId?: string) { const id = schemeId ?? getCategoricalSchemeRegistry().getDefaultKey() ?? ''; const scheme = getCategoricalSchemeRegistry().get(id); - const newScale = new CategoricalColorScale( - scheme?.colors ?? [], - this.forcedItems, - ); - - return newScale; + return new CategoricalColorScale(scheme?.colors ?? [], this.forcedItems); } /** From af2695c16bb7363daea919cd0815f0340ca1dc9c Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 9 Dec 2021 15:45:22 +0800 Subject: [PATCH 03/12] wip --- .../packages/superset-ui-core/src/utils/random.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/utils/random.ts b/superset-frontend/packages/superset-ui-core/src/utils/random.ts index 38dbdbd10bba2..0edddfd178a31 100644 --- a/superset-frontend/packages/superset-ui-core/src/utils/random.ts +++ b/superset-frontend/packages/superset-ui-core/src/utils/random.ts @@ -16,15 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -import seedrandom from 'seedrandom'; - -let random = seedrandom('superset-ui'); +import _seedrandom from 'seedrandom'; export function seed(seed: string) { - random = seedrandom(seed); - return random; + return _seedrandom(seed); } export function seedRandom() { - return random(); + return _seedrandom('superset-ui')(); } From 1f03c67dbfcc1c573bf8c60c58e15156b4ccf4e2 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 9 Dec 2021 21:22:54 +0800 Subject: [PATCH 04/12] fix import in translation dir --- .../superset-ui-core/test/translation/Translator.test.ts | 6 +++--- .../test/translation/TranslatorSingleton.test.ts | 9 ++------- .../superset-ui-core/test/translation/index.test.ts | 2 +- .../test/translation/languagePacks/en.ts | 2 +- .../test/translation/languagePacks/zh.ts | 2 +- .../packages/superset-ui-core/test/utils/logging.test.ts | 3 ++- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts index bab9081a7cdb0..703d9a5d309c0 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts @@ -17,16 +17,16 @@ * under the License. */ -import { logging } from '@superset-ui/core'; -import Translator from '@superset-ui/core/src/translation/Translator'; import { + logging, configure, t, tn, addLocaleData, addTranslation, addTranslations, -} from '@superset-ui/core/src/translation/TranslatorSingleton'; +} from '@superset-ui/core'; +import Translator from '../../src/translation/Translator'; import languagePackZh from './languagePacks/zh'; import languagePackEn from './languagePacks/en'; diff --git a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts index 24ccd260d4fa1..b5bf32496bd60 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts @@ -19,13 +19,8 @@ /* eslint no-console: 0 */ import mockConsole from 'jest-mock-console'; -import Translator from '@superset-ui/core/src/translation/Translator'; -import { - configure, - resetTranslation, - t, - tn, -} from '@superset-ui/core/src/translation/TranslatorSingleton'; +import { configure, resetTranslation, t, tn } from '@superset-ui/core'; +import Translator from '../../src/translation/Translator'; import languagePackEn from './languagePacks/en'; import languagePackZh from './languagePacks/zh'; diff --git a/superset-frontend/packages/superset-ui-core/test/translation/index.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/index.test.ts index aecc3e6fafcfb..2c0f0d6f92d5b 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/index.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/index.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { configure, t, tn } from '@superset-ui/core/src/translation'; +import { configure, t, tn } from '@superset-ui/core'; describe('index', () => { it('exports configure()', () => { diff --git a/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/en.ts b/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/en.ts index 0efcc12645bcd..00d52be8a2728 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/en.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/en.ts @@ -17,7 +17,7 @@ * under the License. */ -import { LanguagePack } from '@superset-ui/core/src/translation'; +import { LanguagePack } from '@superset-ui/core'; const languagePack: LanguagePack = { domain: 'superset', diff --git a/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/zh.ts b/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/zh.ts index 105a65431e564..420a2bda1e417 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/zh.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/languagePacks/zh.ts @@ -17,7 +17,7 @@ * under the License. */ -import { LanguagePack } from '@superset-ui/core/src/translation'; +import { LanguagePack } from '@superset-ui/core'; const languagePack: LanguagePack = { domain: 'superset', diff --git a/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts b/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts index c5e158c946355..51af3cd657b06 100644 --- a/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts @@ -22,7 +22,8 @@ describe('logging', () => { beforeEach(() => { jest.resetModules(); // Explicit is better than implicit - console.warn = console.error = function mockedConsole(message) { + // eslint-disable-next-line no-console + console.warn = console.error = function mockedConsole(message: string) { throw new Error(message); }; }); From 9403c68c8b15f74475d8d0c4de5bae93b4a4c17a Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Fri, 10 Dec 2021 18:32:44 +0800 Subject: [PATCH 05/12] wip --- superset-frontend/jest.config.js | 5 ++++- .../test/translation/TranslatorSingleton.test.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index bc961ad3d16ce..63b81660935df 100644 --- a/superset-frontend/jest.config.js +++ b/superset-frontend/jest.config.js @@ -58,7 +58,10 @@ module.exports = { '^.+\\.jsx?$': 'babel-jest', // ts-jest can't load plugin 'babel-plugin-typescript-to-proptypes' 'reactify\\.tsx$': 'babel-jest', - '^.+\\.tsx?$': 'ts-jest', + // ts-jest doesn't work with `--coverage`. @superset-ui/core should + // 100% coverage, so we use babel-jest in packages and plugins. + '(plugins|packages)\\/.+\\.[jt]sx?$': 'babel-jest', + '((?!(plugins|packages)).)\\/.+\\.tsx?$': 'ts-jest', }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], snapshotSerializers: ['@emotion/jest/enzyme-serializer'], diff --git a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts index b5bf32496bd60..5fc29c04610a4 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts @@ -19,7 +19,7 @@ /* eslint no-console: 0 */ import mockConsole from 'jest-mock-console'; -import { configure, resetTranslation, t, tn } from '@superset-ui/core'; +import { configure, resetTranslation, t, tn } from '../../src'; import Translator from '../../src/translation/Translator'; import languagePackEn from './languagePacks/en'; From 8fb761c0b9e7a660e5439792e22fc970e024727a Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Fri, 10 Dec 2021 21:34:58 +0800 Subject: [PATCH 06/12] refactor logging --- .../test/utils/logging.test.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts b/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts index 51af3cd657b06..cdf4df89cf377 100644 --- a/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts @@ -21,41 +21,41 @@ describe('logging', () => { beforeEach(() => { jest.resetModules(); - // Explicit is better than implicit - // eslint-disable-next-line no-console - console.warn = console.error = function mockedConsole(message: string) { - throw new Error(message); - }; + jest.resetAllMocks(); }); + it('should pipe to `console` methods', () => { - const { logging } = require('@superset-ui/core/src'); + const { logging } = require('@superset-ui/core'); + jest.spyOn(logging, 'debug').mockImplementation(); + jest.spyOn(logging, 'log').mockImplementation(); + jest.spyOn(logging, 'info').mockImplementation(); expect(() => { logging.debug(); logging.log(); logging.info(); }).not.toThrow(); - expect(() => { - logging.warn('warn'); - }).toThrow('warn'); - expect(() => { - logging.error('error'); - }).toThrow('error'); - // to support: npx jest --silent - const spy = jest.spyOn(logging, 'trace'); - spy.mockImplementation(() => { + jest.spyOn(logging, 'warn').mockImplementation(() => { + throw new Error('warn'); + }); + expect(() => logging.warn()).toThrow('warn'); + + jest.spyOn(logging, 'error').mockImplementation(() => { + throw new Error('error'); + }); + expect(() => logging.error()).toThrow('error'); + + jest.spyOn(logging, 'trace').mockImplementation(() => { throw new Error('Trace:'); }); - expect(() => { - logging.trace(); - }).toThrow('Trace:'); - spy.mockRestore(); + expect(() => logging.trace()).toThrow('Trace:'); }); + it('should use noop functions when console unavailable', () => { const { console } = window; Object.assign(window, { console: undefined }); - const { logging } = require('@superset-ui/core/src'); + const { logging } = require('@superset-ui/core'); afterAll(() => { Object.assign(window, { console }); From bf94383eab048c032395ca87f99d07b31d81f007 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Sat, 11 Dec 2021 11:49:15 +0800 Subject: [PATCH 07/12] update regesx --- superset-frontend/jest.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index 63b81660935df..9b89421d488a3 100644 --- a/superset-frontend/jest.config.js +++ b/superset-frontend/jest.config.js @@ -60,8 +60,8 @@ module.exports = { 'reactify\\.tsx$': 'babel-jest', // ts-jest doesn't work with `--coverage`. @superset-ui/core should // 100% coverage, so we use babel-jest in packages and plugins. - '(plugins|packages)\\/.+\\.[jt]sx?$': 'babel-jest', - '((?!(plugins|packages)).)\\/.+\\.tsx?$': 'ts-jest', + '^(plugins|packages)\\/.+\\.tsx?$': 'babel-jest', + '^(((?!(plugins|packages)).)*)\\/.+\\.tsx?$': 'ts-jest', }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], snapshotSerializers: ['@emotion/jest/enzyme-serializer'], From e0f198dd1454ecad32d180852f3895b8afb11db8 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Sat, 11 Dec 2021 13:13:35 +0800 Subject: [PATCH 08/12] fix transform --- superset-frontend/jest.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index 9b89421d488a3..650e7215d85c6 100644 --- a/superset-frontend/jest.config.js +++ b/superset-frontend/jest.config.js @@ -60,8 +60,8 @@ module.exports = { 'reactify\\.tsx$': 'babel-jest', // ts-jest doesn't work with `--coverage`. @superset-ui/core should // 100% coverage, so we use babel-jest in packages and plugins. - '^(plugins|packages)\\/.+\\.tsx?$': 'babel-jest', - '^(((?!(plugins|packages)).)*)\\/.+\\.tsx?$': 'ts-jest', + '(plugins|packages)\\/.+\\.tsx?$': 'babel-jest', + '(((?!(plugins|packages)).)*)\\/.+\\.tsx?$': 'ts-jest', }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], snapshotSerializers: ['@emotion/jest/enzyme-serializer'], From cc78560d5f06f8396615985883042eb703fefd1a Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Mon, 13 Dec 2021 16:34:27 +0800 Subject: [PATCH 09/12] remove reactity.tsx seting --- superset-frontend/jest.config.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index 650e7215d85c6..90af1ee6cd343 100644 --- a/superset-frontend/jest.config.js +++ b/superset-frontend/jest.config.js @@ -56,8 +56,6 @@ module.exports = { coverageReporters: ['lcov', 'json-summary', 'html'], transform: { '^.+\\.jsx?$': 'babel-jest', - // ts-jest can't load plugin 'babel-plugin-typescript-to-proptypes' - 'reactify\\.tsx$': 'babel-jest', // ts-jest doesn't work with `--coverage`. @superset-ui/core should // 100% coverage, so we use babel-jest in packages and plugins. '(plugins|packages)\\/.+\\.tsx?$': 'babel-jest', From 980ea40f5d1242df2ba80d35dd465967eee22981 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Tue, 14 Dec 2021 00:33:26 +0800 Subject: [PATCH 10/12] connection UT --- .../src/connection/SupersetClientClass.ts | 15 +++--- .../connection/SupersetClientClass.test.ts | 49 +++++++++++++++---- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts b/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts index 4959fb1bf2d5b..ef52134f31376 100644 --- a/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts +++ b/superset-frontend/packages/superset-ui-core/src/connection/SupersetClientClass.ts @@ -33,13 +33,6 @@ import { } from './types'; import { DEFAULT_FETCH_RETRY_OPTIONS, DEFAULT_BASE_URL } from './constants'; -function redirectUnauthorized() { - // the next param will be picked by flask to redirect the user after the login - setTimeout(() => { - window.location.href = `/login?next=${window.location.href}`; - }); -} - export default class SupersetClientClass { credentials: Credentials; @@ -159,8 +152,8 @@ export default class SupersetClientClass { timeout: timeout ?? this.timeout, fetchRetryOptions: fetchRetryOptions ?? this.fetchRetryOptions, }).catch(res => { - if (res && res.status === 401) { - redirectUnauthorized(); + if (res?.status === 401) { + this.redirectUnauthorized(); } return Promise.reject(res); }); @@ -226,4 +219,8 @@ export default class SupersetClientClass { endpoint[0] === '/' ? endpoint.slice(1) : endpoint }`; } + + redirectUnauthorized() { + window.location.href = `/login?next=${window.location.href}`; + } } diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts index 2edb0f46df83f..63772f4e6cc21 100644 --- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts @@ -17,10 +17,7 @@ * under the License. */ import fetchMock from 'fetch-mock'; -import { - SupersetClientClass, - ClientConfig, -} from '@superset-ui/core/src/connection'; +import { SupersetClientClass, ClientConfig, CallApi } from '@superset-ui/core'; import { LOGIN_GLOB } from './fixtures/constants'; describe('SupersetClientClass', () => { @@ -321,7 +318,7 @@ describe('SupersetClientClass', () => { await client.init(); await client.get({ url: mockGetUrl }); - const fetchRequest = fetchMock.calls(mockGetUrl)[0][1]; + const fetchRequest = fetchMock.calls(mockGetUrl)[0][1] as CallApi; expect(fetchRequest.mode).toBe(clientConfig.mode); expect(fetchRequest.credentials).toBe(clientConfig.credentials); expect(fetchRequest.headers).toEqual( @@ -378,7 +375,7 @@ describe('SupersetClientClass', () => { await client.init(); await client.get({ url: mockGetUrl, ...overrideConfig }); - const fetchRequest = fetchMock.calls(mockGetUrl)[0][1]; + const fetchRequest = fetchMock.calls(mockGetUrl)[0][1] as CallApi; expect(fetchRequest.mode).toBe(overrideConfig.mode); expect(fetchRequest.credentials).toBe(overrideConfig.credentials); expect(fetchRequest.headers).toEqual( @@ -423,7 +420,7 @@ describe('SupersetClientClass', () => { await client.init(); await client.post({ url: mockPostUrl, ...overrideConfig }); - const fetchRequest = fetchMock.calls(mockPostUrl)[0][1]; + const fetchRequest = fetchMock.calls(mockPostUrl)[0][1] as CallApi; expect(fetchRequest.mode).toBe(overrideConfig.mode); expect(fetchRequest.credentials).toBe(overrideConfig.credentials); @@ -454,7 +451,8 @@ describe('SupersetClientClass', () => { await client.init(); await client.post({ url: mockPostUrl, postPayload }); - const formData = fetchMock.calls(mockPostUrl)[0][1].body as FormData; + const fetchRequest = fetchMock.calls(mockPostUrl)[0][1] as CallApi; + const formData = fetchRequest.body as FormData; expect(fetchMock.calls(mockPostUrl)).toHaveLength(1); Object.entries(postPayload).forEach(([key, value]) => { @@ -470,7 +468,8 @@ describe('SupersetClientClass', () => { await client.init(); await client.post({ url: mockPostUrl, postPayload, stringify: false }); - const formData = fetchMock.calls(mockPostUrl)[0][1].body as FormData; + const fetchRequest = fetchMock.calls(mockPostUrl)[0][1] as CallApi; + const formData = fetchRequest.body as FormData; expect(fetchMock.calls(mockPostUrl)).toHaveLength(1); Object.entries(postPayload).forEach(([key, value]) => { @@ -479,4 +478,36 @@ describe('SupersetClientClass', () => { }); }); }); + + it('should redirect Unauthorized', async () => { + const mockRequestUrl = 'https://host//get/url'; + const { location } = window; + // @ts-ignore + delete window.location; + // @ts-ignore + window.location = { href: mockRequestUrl }; + const authSpy = jest + .spyOn(SupersetClientClass.prototype, 'ensureAuth') + .mockImplementation(); + const rejectValue = { status: 401 }; + fetchMock.get(mockRequestUrl, () => Promise.reject(rejectValue), { + overwriteRoutes: true, + }); + + const client = new SupersetClientClass({}); + + let error; + try { + await client.request({ url: mockRequestUrl, method: 'GET' }); + } catch (err) { + error = err; + } finally { + const redirectURL = window.location.href; + expect(redirectURL).toBe(`/login?next=${mockRequestUrl}`); + expect(error.status).toBe(401); + } + + authSpy.mockReset(); + window.location = location; + }); }); From 0463ee69da6a0c546a209695cf4d9931ed562074 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Tue, 14 Dec 2021 00:37:40 +0800 Subject: [PATCH 11/12] update --- .../test/connection/SupersetClientClass.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts index 63772f4e6cc21..4b2307c9d4f26 100644 --- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts @@ -480,7 +480,7 @@ describe('SupersetClientClass', () => { }); it('should redirect Unauthorized', async () => { - const mockRequestUrl = 'https://host//get/url'; + const mockRequestUrl = 'https://host/get/url'; const { location } = window; // @ts-ignore delete window.location; From fda8acf262921633c856bfe1a5cb962d94be0adc Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Tue, 14 Dec 2021 11:37:13 +0800 Subject: [PATCH 12/12] fix partial test --- .../test/translation/TranslatorSingleton.test.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts index 5fc29c04610a4..af0d6f5915524 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/TranslatorSingleton.test.ts @@ -19,7 +19,7 @@ /* eslint no-console: 0 */ import mockConsole from 'jest-mock-console'; -import { configure, resetTranslation, t, tn } from '../../src'; +import { configure, resetTranslation, t, tn } from '@superset-ui/core'; import Translator from '../../src/translation/Translator'; import languagePackEn from './languagePacks/en'; @@ -71,4 +71,16 @@ describe('TranslatorSingleton', () => { }); }); }); + it('should be reset translation setting', () => { + configure(); + expect(t('second')).toEqual('second'); + + resetTranslation(); + const restoreConsole = mockConsole(); + expect(t('second')).toEqual('second'); + resetTranslation(); + expect(t('second')).toEqual('second'); + expect(console.warn).toBeCalledTimes(2); + restoreConsole(); + }); });