Unverified Commit 4794dfb3 authored by Dorian Johnson's avatar Dorian Johnson Committed by GitHub

chore: Various typing fixes (#754)

Signed-off-by: 's avatarMarcos Iglesias Valle <golodhros@gmail.com>
parent 37ee7640
...@@ -97,10 +97,12 @@ describe('NavBar', () => { ...@@ -97,10 +97,12 @@ describe('NavBar', () => {
describe('renderSearchBar', () => { describe('renderSearchBar', () => {
it('returns small SearchBar when not on home page', () => { it('returns small SearchBar when not on home page', () => {
const { props, wrapper } = setup(null, { pathname: '/search' }); const { props, wrapper } = setup(undefined, { pathname: '/search' });
const searchBar = shallow(wrapper.instance().renderSearchBar()).find( const rendered = wrapper.instance().renderSearchBar();
SearchBar if (rendered === null) {
); throw Error('rendering search bar returned null');
}
const searchBar = shallow(rendered).find(SearchBar);
expect(searchBar.exists()).toBe(true); expect(searchBar.exists()).toBe(true);
expect(searchBar.props()).toMatchObject({ expect(searchBar.props()).toMatchObject({
size: 'small', size: 'small',
...@@ -108,7 +110,7 @@ describe('NavBar', () => { ...@@ -108,7 +110,7 @@ describe('NavBar', () => {
}); });
it('returns null if conditions to render search bar are not met', () => { it('returns null if conditions to render search bar are not met', () => {
const { props, wrapper } = setup(null, { pathname: '/' }); const { props, wrapper } = setup(undefined, { pathname: '/' });
expect(wrapper.instance().renderSearchBar()).toBe(null); expect(wrapper.instance().renderSearchBar()).toBe(null);
}); });
}); });
......
...@@ -19,10 +19,10 @@ describe('OwnerEditor', () => { ...@@ -19,10 +19,10 @@ describe('OwnerEditor', () => {
errorText: null, errorText: null,
isLoading: false, isLoading: false,
itemProps: {}, itemProps: {},
isEditing: null, isEditing: undefined,
setEditMode: jest.fn(), setEditMode: jest.fn(),
onUpdateList: jest.fn(), onUpdateList: jest.fn(),
readOnly: null, readOnly: undefined,
resourceType: ResourceType.table, resourceType: ResourceType.table,
...propOverrides, ...propOverrides,
}; };
......
...@@ -145,9 +145,10 @@ export class OwnerEditor extends React.Component< ...@@ -145,9 +145,10 @@ export class OwnerEditor extends React.Component<
recordAddItem = (event: React.FormEvent<HTMLFormElement>) => { recordAddItem = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault(); event.preventDefault();
if (this.inputRef.current) {
const { value } = this.inputRef.current; const { value } = this.inputRef.current;
if (this.inputRef.current && value) { if (value) {
this.inputRef.current.value = ''; this.inputRef.current.value = '';
const newTempItemProps = { const newTempItemProps = {
...@@ -156,6 +157,7 @@ export class OwnerEditor extends React.Component< ...@@ -156,6 +157,7 @@ export class OwnerEditor extends React.Component<
}; };
this.setState({ tempItemProps: newTempItemProps }); this.setState({ tempItemProps: newTempItemProps });
} }
}
}; };
recordDeleteItem = (deletedKey: string) => { recordDeleteItem = (deletedKey: string) => {
......
...@@ -60,8 +60,11 @@ describe('SearchItem', () => { ...@@ -60,8 +60,11 @@ describe('SearchItem', () => {
it('renders correct text if !props.hasResults', () => { it('renders correct text if !props.hasResults', () => {
const { wrapper } = setup({ hasResults: false }); const { wrapper } = setup({ hasResults: false });
const content = shallow(wrapper.instance().renderIndicator()); const rendered = wrapper.instance().renderIndicator();
expect(content.text()).toBe(SEARCH_ITEM_NO_RESULTS); if (rendered === null) {
throw Error('renderIndicator returned null');
}
expect(shallow(rendered).text()).toBe(SEARCH_ITEM_NO_RESULTS);
}); });
it('renders nothing if !props.Loading and props.hasResults', () => { it('renders nothing if !props.Loading and props.hasResults', () => {
......
...@@ -121,12 +121,17 @@ export default function reducer( ...@@ -121,12 +121,17 @@ export default function reducer(
): BookmarkReducerState { ): BookmarkReducerState {
switch (action.type) { switch (action.type) {
case AddBookmark.SUCCESS: case AddBookmark.SUCCESS:
case GetBookmarks.SUCCESS: case GetBookmarks.SUCCESS: {
const { payload } = <GetBookmarksResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetBookmarks.SUCCESS');
}
return { return {
...state, ...state,
myBookmarks: (<GetBookmarksResponse>action).payload.bookmarks, myBookmarks: payload.bookmarks,
myBookmarksIsLoaded: true, myBookmarksIsLoaded: true,
}; };
}
case GetBookmarksForUser.REQUEST: case GetBookmarksForUser.REQUEST:
return { return {
...state, ...state,
...@@ -134,16 +139,23 @@ export default function reducer( ...@@ -134,16 +139,23 @@ export default function reducer(
...initialBookmarkState, ...initialBookmarkState,
}, },
}; };
case GetBookmarksForUser.SUCCESS: case GetBookmarksForUser.SUCCESS: {
const { payload } = <GetBookmarksForUserResponse>action;
if (payload === undefined) {
throw Error('payload must be set for GetBookmarksForUser.SUCCESS');
}
return { return {
...state, ...state,
bookmarksForUser: (<GetBookmarksForUserResponse>action).payload bookmarksForUser: payload.bookmarks,
.bookmarks,
}; };
case RemoveBookmark.SUCCESS: }
const { resourceKey, resourceType } = (<RemoveBookmarkResponse>( case RemoveBookmark.SUCCESS: {
action const { payload } = <RemoveBookmarkResponse>action;
)).payload; if (payload === undefined) {
throw Error('payload must be set for RemoveBookmark.SUCCESS');
}
const { resourceKey, resourceType } = payload;
return { return {
...state, ...state,
myBookmarks: { myBookmarks: {
...@@ -153,6 +165,7 @@ export default function reducer( ...@@ -153,6 +165,7 @@ export default function reducer(
), ),
}, },
}; };
}
case AddBookmark.FAILURE: case AddBookmark.FAILURE:
case GetBookmarks.FAILURE: case GetBookmarks.FAILURE:
case GetBookmarksForUser.FAILURE: case GetBookmarksForUser.FAILURE:
......
...@@ -61,8 +61,8 @@ export interface SearchReducerState { ...@@ -61,8 +61,8 @@ export interface SearchReducerState {
export function searchAll( export function searchAll(
searchType: SearchType, searchType: SearchType,
term: string, term: string,
resource?: ResourceType, resource: ResourceType,
pageIndex?: number, pageIndex: number,
useFilters: boolean = false useFilters: boolean = false
): SearchAllRequest { ): SearchAllRequest {
return { return {
...@@ -314,6 +314,11 @@ export default function reducer( ...@@ -314,6 +314,11 @@ export default function reducer(
case SearchAll.SUCCESS: case SearchAll.SUCCESS:
// resets all resources with initial state then applies search results // resets all resources with initial state then applies search results
const newState = (<SearchAllResponse>action).payload; const newState = (<SearchAllResponse>action).payload;
if (newState === undefined) {
throw Error(
'SearchAllResponse.payload must be specified for SUCCESS type'
);
}
return { return {
...initialState, ...initialState,
...newState, ...newState,
...@@ -354,6 +359,11 @@ export default function reducer( ...@@ -354,6 +359,11 @@ export default function reducer(
}; };
case InlineSearch.SUCCESS: case InlineSearch.SUCCESS:
const inlineResults = (<InlineSearchResponse>action).payload; const inlineResults = (<InlineSearchResponse>action).payload;
if (inlineResults === undefined) {
throw Error(
'InlineSearchResponse.payload must be specified for SUCCESS type'
);
}
return { return {
...state, ...state,
inlineResults: { inlineResults: {
......
...@@ -112,6 +112,7 @@ export function* submitSearchResourceWatcher(): SagaIterator { ...@@ -112,6 +112,7 @@ export function* submitSearchResourceWatcher(): SagaIterator {
export function* updateSearchStateWorker( export function* updateSearchStateWorker(
action: UpdateSearchStateRequest action: UpdateSearchStateRequest
): SagaIterator { ): SagaIterator {
if (action.payload !== undefined) {
const { filters, resource, updateUrl, submitSearch } = action.payload; const { filters, resource, updateUrl, submitSearch } = action.payload;
const state = yield select(getSearchState); const state = yield select(getSearchState);
if (filters && submitSearch) { if (filters && submitSearch) {
...@@ -124,6 +125,7 @@ export function* updateSearchStateWorker( ...@@ -124,6 +125,7 @@ export function* updateSearchStateWorker(
filters: filters || state.filters, filters: filters || state.filters,
}); });
} }
}
} }
export function* updateSearchStateWatcher(): SagaIterator { export function* updateSearchStateWatcher(): SagaIterator {
yield takeEvery(UpdateSearchState.REQUEST, updateSearchStateWorker); yield takeEvery(UpdateSearchState.REQUEST, updateSearchStateWorker);
......
...@@ -20,11 +20,11 @@ export const getPageIndex = ( ...@@ -20,11 +20,11 @@ export const getPageIndex = (
resource = resource || state.resource; resource = resource || state.resource;
switch (resource) { switch (resource) {
case ResourceType.table: case ResourceType.table:
return state.tables.page_index; return state.tables?.page_index || 0;
case ResourceType.user: case ResourceType.user:
return state.users.page_index; return state.users?.page_index || 0;
case ResourceType.dashboard: case ResourceType.dashboard:
return state.dashboards.page_index; return state.dashboards?.page_index || 0;
} }
return 0; return 0;
}; };
......
...@@ -180,7 +180,7 @@ describe('helpers', () => { ...@@ -180,7 +180,7 @@ describe('helpers', () => {
it('returns false if not a user with display_name', () => { it('returns false if not a user with display_name', () => {
const testUser = { const testUser = {
...globalState.user.loggedInUser, ...globalState.user.loggedInUser,
display_name: null, display_name: '',
}; };
expect(Helpers.shouldSendNotification(testUser)).toBe(false); expect(Helpers.shouldSendNotification(testUser)).toBe(false);
}); });
......
...@@ -483,7 +483,7 @@ describe('tableMetadata ducks', () => { ...@@ -483,7 +483,7 @@ describe('tableMetadata ducks', () => {
sagaTest = (mockSuccess) => { sagaTest = (mockSuccess) => {
return testSaga( return testSaga(
updateTableDescriptionWorker, updateTableDescriptionWorker,
updateTableDescription(newDescription, mockSuccess, null) updateTableDescription(newDescription, mockSuccess, undefined)
) )
.next() .next()
.select() .select()
...@@ -510,7 +510,7 @@ describe('tableMetadata ducks', () => { ...@@ -510,7 +510,7 @@ describe('tableMetadata ducks', () => {
sagaTest = (mockFailure) => { sagaTest = (mockFailure) => {
return testSaga( return testSaga(
updateTableDescriptionWorker, updateTableDescriptionWorker,
updateTableDescription(newDescription, null, mockFailure) updateTableDescription(newDescription, undefined, mockFailure)
) )
.next() .next()
.select() .select()
...@@ -623,7 +623,7 @@ describe('tableMetadata ducks', () => { ...@@ -623,7 +623,7 @@ describe('tableMetadata ducks', () => {
newDescription, newDescription,
columnIndex, columnIndex,
mockSuccess, mockSuccess,
null undefined
) )
) )
.next() .next()
...@@ -655,7 +655,7 @@ describe('tableMetadata ducks', () => { ...@@ -655,7 +655,7 @@ describe('tableMetadata ducks', () => {
updateColumnDescription( updateColumnDescription(
newDescription, newDescription,
columnIndex, columnIndex,
null, undefined,
mockFailure mockFailure
) )
) )
......
...@@ -67,7 +67,7 @@ const globalState: GlobalState = { ...@@ -67,7 +67,7 @@ const globalState: GlobalState = {
}, },
issue: { issue: {
issues: [], issues: [],
allIssuesUrl: null, allIssuesUrl: '',
total: 0, total: 0,
isLoading: true, isLoading: true,
}, },
......
export const activeUser0 = { import { PeopleUser } from 'interfaces/User';
manager_id: null,
manager_fullname: null, export const activeUser0: PeopleUser = {
manager_email: null, manager_fullname: undefined,
manager_email: undefined,
profile_url: '/test0', profile_url: '/test0',
role_name: null, role_name: undefined,
display_name: null, display_name: '',
github_username: null, github_username: '',
team_name: null, team_name: '',
last_name: null, last_name: '',
full_name: null, full_name: '',
slack_id: null, slack_id: '',
first_name: null, first_name: '',
employee_type: null, employee_type: '',
other_key_values: {},
is_active: true, is_active: true,
email: 'user0@test.com', email: 'user0@test.com',
user_id: 'user0', user_id: 'user0',
}; };
export const activeUser1 = { export const activeUser1: PeopleUser = {
manager_id: null, manager_fullname: undefined,
manager_fullname: null, manager_email: undefined,
manager_email: null,
profile_url: '/test1', profile_url: '/test1',
role_name: null, role_name: undefined,
display_name: null, display_name: '',
github_username: null, github_username: '',
team_name: null, team_name: '',
last_name: null, last_name: '',
full_name: null, full_name: '',
slack_id: null, slack_id: '',
first_name: null, first_name: '',
employee_type: null, employee_type: '',
other_key_values: {},
is_active: true, is_active: true,
email: 'user10@test.com', email: 'user10@test.com',
user_id: 'user1', user_id: 'user1',
......
...@@ -5,7 +5,7 @@ import * as History from 'history'; ...@@ -5,7 +5,7 @@ import * as History from 'history';
// Mock React-Router // Mock React-Router
export function getMockRouterProps<P>( export function getMockRouterProps<P>(
data: P, data: P,
location: Partial<History.Location> location: Partial<History.Location> = {}
): RouteComponentProps<P> { ): RouteComponentProps<P> {
const mockLocation: History.Location = { const mockLocation: History.Location = {
hash: '', hash: '',
...@@ -24,7 +24,10 @@ export function getMockRouterProps<P>( ...@@ -24,7 +24,10 @@ export function getMockRouterProps<P>(
url: '', url: '',
}, },
location: mockLocation, location: mockLocation,
history: { // This history object is a mock and `null`s many of the required methods. The
// tests are designed not to trigger them, if they do, an error is expected.
// So cast this as any.
history: <any>{
length: 2, length: 2,
action: 'POP', action: 'POP',
location: mockLocation, location: mockLocation,
......
...@@ -99,7 +99,7 @@ export const allResourcesExample = { ...@@ -99,7 +99,7 @@ export const allResourcesExample = {
{ {
display_name: 'Test User', display_name: 'Test User',
email: 'tuser@test.com', email: 'tuser@test.com',
employee_type: null, employee_type: '',
first_name: 'Test', first_name: 'Test',
full_name: 'Test User', full_name: 'Test User',
github_username: '', github_username: '',
...@@ -108,8 +108,8 @@ export const allResourcesExample = { ...@@ -108,8 +108,8 @@ export const allResourcesExample = {
manager_email: 'tuser2@test.com', manager_email: 'tuser2@test.com',
manager_fullname: 'Test User2', manager_fullname: 'Test User2',
profile_url: '', profile_url: '',
role_name: null, role_name: undefined,
slack_id: null, slack_id: '',
team_name: 'Amundsen Team', team_name: 'Amundsen Team',
type: 'user', type: 'user',
user_id: 'tuser@test.com', user_id: 'tuser@test.com',
...@@ -117,7 +117,7 @@ export const allResourcesExample = { ...@@ -117,7 +117,7 @@ export const allResourcesExample = {
{ {
display_name: 'Test User2', display_name: 'Test User2',
email: 'tuser2@test.com', email: 'tuser2@test.com',
employee_type: null, employee_type: '',
first_name: 'Test', first_name: 'Test',
full_name: 'Test User2', full_name: 'Test User2',
github_username: '', github_username: '',
...@@ -126,8 +126,8 @@ export const allResourcesExample = { ...@@ -126,8 +126,8 @@ export const allResourcesExample = {
manager_email: 'tuser3@test.com', manager_email: 'tuser3@test.com',
manager_fullname: 'Test User3', manager_fullname: 'Test User3',
profile_url: '', profile_url: '',
role_name: null, role_name: undefined,
slack_id: null, slack_id: '',
team_name: 'Amundsen Team', team_name: 'Amundsen Team',
type: 'user', type: 'user',
user_id: 'tuser2@test.com', user_id: 'tuser2@test.com',
......
...@@ -67,7 +67,7 @@ describe('SearchPage', () => { ...@@ -67,7 +67,7 @@ describe('SearchPage', () => {
let wrapper; let wrapper;
beforeAll(() => { beforeAll(() => {
({ props, wrapper } = setup(null, { ({ props, wrapper } = setup(undefined, {
search: '/search?searchTerm=testName&resource=table&pageIndex=1', search: '/search?searchTerm=testName&resource=table&pageIndex=1',
})); }));
}); });
...@@ -84,7 +84,7 @@ describe('SearchPage', () => { ...@@ -84,7 +84,7 @@ describe('SearchPage', () => {
let mockPrevProps; let mockPrevProps;
beforeAll(() => { beforeAll(() => {
({ props, wrapper } = setup(null, { ({ props, wrapper } = setup(undefined, {
search: '/search?searchTerm=testName&resource=table&pageIndex=1', search: '/search?searchTerm=testName&resource=table&pageIndex=1',
})); }));
mockPrevProps = { mockPrevProps = {
...@@ -267,7 +267,11 @@ describe('SearchPage', () => { ...@@ -267,7 +267,11 @@ describe('SearchPage', () => {
resource: ResourceType.table, resource: ResourceType.table,
}); });
const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent'); const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent');
shallow(wrapper.instance().renderSearchResults()); const rendered = wrapper.instance().renderSearchResults();
if (rendered === null) {
throw Error('renderSearchResults returned null');
}
shallow(rendered);
expect(getTabContentSpy).toHaveBeenCalledWith( expect(getTabContentSpy).toHaveBeenCalledWith(
props.tables, props.tables,
ResourceType.table ResourceType.table
...@@ -279,7 +283,11 @@ describe('SearchPage', () => { ...@@ -279,7 +283,11 @@ describe('SearchPage', () => {
resource: ResourceType.user, resource: ResourceType.user,
}); });
const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent'); const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent');
shallow(wrapper.instance().renderSearchResults()); const rendered = wrapper.instance().renderSearchResults();
if (rendered === null) {
throw Error('renderSearchResults returned null');
}
shallow(rendered);
expect(getTabContentSpy).toHaveBeenCalledWith( expect(getTabContentSpy).toHaveBeenCalledWith(
props.users, props.users,
ResourceType.user ResourceType.user
...@@ -291,7 +299,11 @@ describe('SearchPage', () => { ...@@ -291,7 +299,11 @@ describe('SearchPage', () => {
resource: ResourceType.dashboard, resource: ResourceType.dashboard,
}); });
const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent'); const getTabContentSpy = jest.spyOn(wrapper.instance(), 'getTabContent');
shallow(wrapper.instance().renderSearchResults()); const rendered = wrapper.instance().renderSearchResults();
if (rendered === null) {
throw Error('renderSearchResults returned null');
}
shallow(rendered);
expect(getTabContentSpy).toHaveBeenCalledWith( expect(getTabContentSpy).toHaveBeenCalledWith(
props.dashboards, props.dashboards,
ResourceType.dashboard ResourceType.dashboard
...@@ -300,7 +312,7 @@ describe('SearchPage', () => { ...@@ -300,7 +312,7 @@ describe('SearchPage', () => {
it('renders null for an invalid resource', () => { it('renders null for an invalid resource', () => {
const { wrapper } = setup({ const { wrapper } = setup({
resource: null, resource: undefined,
}); });
const renderedSearchResults = wrapper.instance().renderSearchResults(); const renderedSearchResults = wrapper.instance().renderSearchResults();
expect(renderedSearchResults).toBe(null); expect(renderedSearchResults).toBe(null);
......
...@@ -8,7 +8,7 @@ export enum CaseType { ...@@ -8,7 +8,7 @@ export enum CaseType {
TITLE_CASE = 'titleCase', TITLE_CASE = 'titleCase',
} }
export function convertText(str = '', caseType: CaseType): string { export function convertText(str = '', caseType: CaseType | null): string {
switch (caseType) { switch (caseType) {
case CaseType.LOWER_CASE: case CaseType.LOWER_CASE:
return str.toLowerCase(); return str.toLowerCase();
......
...@@ -36,7 +36,7 @@ const PATHS = { ...@@ -36,7 +36,7 @@ const PATHS = {
}; };
// Process of Templates // Process of Templates
const walkSync = (dir, filelist = []) => { const walkSync = (dir: string, filelist: string[] = []) => {
fs.readdirSync(dir).forEach((file) => { fs.readdirSync(dir).forEach((file) => {
filelist = fs.statSync(path.join(dir, file)).isDirectory() filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist) ? walkSync(path.join(dir, file), filelist)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment