-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
2,699 additions
and
1,410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-env node */ | ||
module.exports = 'test-file-stub'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-env node */ | ||
const dependency = require.requireActual('i18next'); | ||
module.exports = { | ||
...dependency, | ||
default: { | ||
...dependency.default, | ||
use() { | ||
return this; | ||
}, | ||
init: () => Promise.resolve(), | ||
t: (key) => (key?.indexOf('~') !== -1 ? key.substring(key.indexOf('~') + 1) : key), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let _localStorage = {}; | ||
|
||
(window as any).localStorage = (window as any).sessionStorage = { | ||
setItem(key: string, value: string) { | ||
Object.assign(_localStorage, { [key]: value }); | ||
}, | ||
getItem(key: string): string | null { | ||
return _localStorage.hasOwnProperty(key) ? _localStorage[key] : null; | ||
}, | ||
clear() { | ||
_localStorage = {}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
window.matchMedia = () => ({ matches: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable */ | ||
|
||
global.MutationObserver = class { | ||
constructor(callback) {} | ||
disconnect() {} | ||
observe(element, initObject) {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-env node */ | ||
const reactI18next = require.requireActual('react-i18next'); | ||
module.exports = { | ||
...reactI18next, | ||
useTranslation: () => ({ | ||
t: (key) => (key?.indexOf('~') !== -1 ? key.substring(key.indexOf('~') + 1) : key), | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
window.SERVER_FLAGS = { | ||
basePath: '/', | ||
consolePlugins: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-env node */ | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable */ | ||
import { WebSocket } from 'mock-socket'; | ||
|
||
global.WebSocket = WebSocket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-env node */ | ||
|
||
import { configure } from 'enzyme'; | ||
import * as Adapter from 'enzyme-adapter-react-16'; | ||
|
||
import 'url-search-params-polyfill'; | ||
|
||
// http://airbnb.io/enzyme/docs/installation/index.html#working-with-react-16 | ||
configure({ adapter: new Adapter() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const defaultResolver = require('jest-resolve/build/defaultResolver').default; | ||
|
||
// eslint-disable-next-line no-undef | ||
module.exports = (request, options) => { | ||
let packageFilter; | ||
if (request.startsWith('i18next')) { | ||
packageFilter = (pkg) => ({ | ||
...pkg, | ||
main: pkg.module || pkg.main, | ||
}); | ||
} | ||
return defaultResolver(request, { | ||
...options, | ||
packageFilter, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getQuickStartByName, isDisabledQuickStart } from '../utils/quick-start-utils'; | ||
import { allQuickStarts } from '../data/quick-start-test-data'; | ||
|
||
describe('quick-start-utils', () => { | ||
it('should return the quick start corresponding to the id for getQuickStartByName function', () => { | ||
const mockID = allQuickStarts[0].metadata.name; | ||
const quickStart = getQuickStartByName(mockID, allQuickStarts); | ||
expect(quickStart.metadata.name === mockID).toBe(true); | ||
}); | ||
|
||
it('should filter out disabled quick starts', () => { | ||
const disabledQuickStarts = [allQuickStarts[0].metadata.name]; // setting allQuickStart[0] as disabled | ||
expect(isDisabledQuickStart(allQuickStarts[1], disabledQuickStarts)).toBe(false); | ||
expect(isDisabledQuickStart(allQuickStarts[0], disabledQuickStarts)).toBe(true); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/module/src/catalog/__tests__/QuickStartCatalog.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Gallery, GalleryItem } from '@patternfly/react-core'; | ||
import { EmptyBox } from '@console/internal/components/utils'; | ||
import { QuickStartCatalogPage } from '../../QuickStartCatalogPage'; | ||
import QuickStartCatalog from '../QuickStartCatalog'; | ||
import { getQuickStarts } from '../../data/test-utils'; | ||
|
||
jest.mock('react-i18next', () => { | ||
const reactI18next = require.requireActual('react-i18next'); | ||
return { | ||
...reactI18next, | ||
useTranslation: () => ({ t: (key: string) => key }), | ||
}; | ||
}); | ||
|
||
jest.mock('@console/shared', () => { | ||
const ActualShared = require.requireActual('@console/shared'); | ||
return { | ||
...ActualShared, | ||
useQueryParams: () => new Map(), | ||
}; | ||
}); | ||
|
||
describe('QuickStartCatalog', () => { | ||
it('should load an emptybox if no QS exist', () => { | ||
const QuickStartCatalogProps = { quickStarts: [], onClick: jest.fn() }; | ||
const QuickStartCatalogWrapper = shallow(<QuickStartCatalogPage {...QuickStartCatalogProps} />); | ||
expect(QuickStartCatalogWrapper.find(EmptyBox).exists()).toBeTruthy(); | ||
}); | ||
it('should load a gallery if QS exist', () => { | ||
const QuickStartCatalogProps = { quickStarts: getQuickStarts(), onClick: jest.fn() }; | ||
const QuickStartCatalogWrapper = shallow(<QuickStartCatalog {...QuickStartCatalogProps} />); | ||
expect(QuickStartCatalogWrapper.find(Gallery).exists()).toBeTruthy(); | ||
}); | ||
it('should load galleryItems equal to the number of QS', () => { | ||
const QuickStartCatalogProps = { quickStarts: getQuickStarts(), onClick: jest.fn() }; | ||
const QuickStartCatalogWrapper = shallow(<QuickStartCatalog {...QuickStartCatalogProps} />); | ||
const galleryItems = QuickStartCatalogWrapper.find(GalleryItem); | ||
expect(galleryItems.exists()).toBeTruthy(); | ||
expect(galleryItems.length).toEqual(getQuickStarts().length); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/module/src/catalog/__tests__/QuickStartTile.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { CatalogTile } from '@patternfly/react-catalog-view-extension'; | ||
import { getQuickStarts } from '../../data/test-utils'; | ||
import QuickStartTile from '../QuickStartTile'; | ||
import { QuickStartStatus } from '../../utils/quick-start-types'; | ||
|
||
describe('QuickStartTile', () => { | ||
const quickstarts = getQuickStarts(); | ||
|
||
it('should load proper catalog tile without featured property', () => { | ||
const wrapper = shallow( | ||
<QuickStartTile | ||
quickStart={quickstarts[0]} | ||
status={QuickStartStatus.NOT_STARTED} | ||
onClick={jest.fn()} | ||
isActive={false} | ||
/>, | ||
); | ||
const catalogTile = wrapper.find(CatalogTile); | ||
expect(catalogTile.exists()).toBeTruthy(); | ||
expect(catalogTile.prop('featured')).toBe(false); | ||
}); | ||
|
||
it('should load proper catalog tile with featured property', () => { | ||
const wrapper = shallow( | ||
<QuickStartTile | ||
quickStart={quickstarts[1]} | ||
status={QuickStartStatus.IN_PROGRESS} | ||
onClick={jest.fn()} | ||
isActive | ||
/>, | ||
); | ||
const catalogTile = wrapper.find(CatalogTile); | ||
expect(catalogTile.exists()).toBeTruthy(); | ||
expect(catalogTile.prop('featured')).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.