Files
superset2/superset/assets/spec/javascripts/dashboard/util/findFirstParentContainer_spec.js
Christine Chambers 9029701f24 [refactor] Migrate from Mocha+Chai to Jest (#6079)
* [refactor] Migrate from Mocha+Chai to Jest

This change migrates all the existing unit tests
- to Jest's global expect and matchers from chai's imported expect, asserts and matchers.
- to Jest's describe/test from mocha's describe/it

The majority of the mechanical changes to tests are achieved through running jest-codemods. The only two note-worthy manual tweaks:
1. Setting a testURL of http://localhost in jest config and adjusting a few tests to leverage this value instead of relying on about:blank.
2. Re-enabling ExploreChartPanel_spec which was previously commented out as we cannot have empty tests with nothing in it with Jest. :)

This change also removes dependencies to Mocha and Chai.

* Remove the test:one command as it now does the same thing as test.

* Fixing lint errors. The diff looks large but is large done through `yarn run lint --fix`

The only noteworthy change is the one in eslintrc for tests. The env has been updated from mocha to jest.

* Adding eslint-plugin-jest and further modify tests.

- One small fix in sqllab's Timer Spec for a test that is not using the spy it created for testing.
- Deletion of a duplicated test caught by eslint-plugin-jest.

* - Make istanbul coverage work with Jest.

- Remove dependency on stand-alone istanbul and babel-istanbul as they're built-into jest. Yes!

* Attempt to fix dynamic imports in tests.

* run sequentially and log heap usage

* - tweaking maxworkers for travis and specifying coverageDirectory for codecov

- remove dynamic import in shim.js now that it is set in babelrc for tests only.
2018-10-15 13:10:18 -07:00

109 lines
2.5 KiB
JavaScript

import findFirstParentContainerId from '../../../../src/dashboard/util/findFirstParentContainer';
import {
DASHBOARD_GRID_ID,
DASHBOARD_ROOT_ID,
} from '../../../../src/dashboard/util/constants';
describe('findFirstParentContainer', () => {
const mockGridLayout = {
DASHBOARD_VERSION_KEY: 'v2',
ROOT_ID: {
type: 'ROOT',
id: 'ROOT_ID',
children: ['GRID_ID'],
},
GRID_ID: {
type: 'GRID',
id: 'GRID_ID',
children: ['ROW-Bk45URrlQ'],
},
'ROW-Bk45URrlQ': {
type: 'ROW',
id: 'ROW-Bk45URrlQ',
children: ['CHART-ryxVc8RHlX'],
},
'CHART-ryxVc8RHlX': {
type: 'CHART',
id: 'CHART-ryxVc8RHlX',
children: [],
},
HEADER_ID: {
id: 'HEADER_ID',
type: 'HEADER',
},
};
const mockTabsLayout = {
'CHART-S1gilYABe7': {
children: [],
id: 'CHART-S1gilYABe7',
type: 'CHART',
},
'CHART-SJli5K0HlQ': {
children: [],
id: 'CHART-SJli5K0HlQ',
type: 'CHART',
},
GRID_ID: {
children: [],
id: 'GRID_ID',
type: 'GRID',
},
HEADER_ID: {
id: 'HEADER_ID',
type: 'HEADER',
},
ROOT_ID: {
children: ['TABS-SkgJ5t0Bem'],
id: 'ROOT_ID',
type: 'ROOT',
},
'ROW-S1B8-JLgX': {
children: ['CHART-SJli5K0HlQ'],
id: 'ROW-S1B8-JLgX',
type: 'ROW',
},
'ROW-S1bUb1Ilm': {
children: ['CHART-S1gilYABe7'],
id: 'ROW-S1bUb1Ilm',
type: 'ROW',
},
'TABS-ByeLSWyLe7': {
children: ['TAB-BJbLSZ1UeQ'],
id: 'TABS-ByeLSWyLe7',
type: 'TABS',
},
'TABS-SkgJ5t0Bem': {
children: ['TAB-HkWJcFCHxQ', 'TAB-ByDBbkLlQ'],
id: 'TABS-SkgJ5t0Bem',
meta: {},
type: 'TABS',
},
'TAB-BJbLSZ1UeQ': {
children: ['ROW-S1bUb1Ilm'],
id: 'TAB-BJbLSZ1UeQ',
type: 'TAB',
},
'TAB-ByDBbkLlQ': {
children: ['ROW-S1B8-JLgX'],
id: 'TAB-ByDBbkLlQ',
type: 'TAB',
},
'TAB-HkWJcFCHxQ': {
children: ['TABS-ByeLSWyLe7'],
id: 'TAB-HkWJcFCHxQ',
type: 'TAB',
},
DASHBOARD_VERSION_KEY: 'v2',
};
it('should return grid root', () => {
expect(findFirstParentContainerId(mockGridLayout)).toBe(DASHBOARD_GRID_ID);
});
it('should return first tab', () => {
const tabsId = mockTabsLayout[DASHBOARD_ROOT_ID].children[0];
const firstTabId = mockTabsLayout[tabsId].children[0];
expect(findFirstParentContainerId(mockTabsLayout)).toBe(firstTabId);
});
});