Skip to content

Commit

Permalink
Tests: move spec files closer to file under test (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Mar 1, 2022
1 parent 838a9d4 commit 92b515f
Show file tree
Hide file tree
Showing 74 changed files with 164 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { setGraphExplorerMode } from '../../../app/services/actions/explorer-mode-action-creator';
import { SET_GRAPH_EXPLORER_MODE_SUCCESS } from '../../../app/services/redux-constants';
import { setGraphExplorerMode } from './explorer-mode-action-creator';
import { SET_GRAPH_EXPLORER_MODE_SUCCESS } from '../redux-constants';
import { Mode } from '../../../types/enums';

const middlewares = [thunk];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import {
FETCH_SCOPES_PENDING,
FETCH_SCOPES_SUCCESS,
QUERY_GRAPH_STATUS
} from '../../../app/services/redux-constants';
} from '../redux-constants';

import {
fetchScopesSuccess, fetchScopesPending, fetchScopesError, getPermissionsScopeType, fetchScopes,
consentToScopes
} from
'../../../app/services/actions/permissions-action-creator';
'./permissions-action-creator';
import { IPermissionsResponse } from '../../../types/permissions';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import fetch from 'jest-fetch-mock';
import { store } from '../../../../src/store/index';
import { store } from '../../../store/index';
import { IRootState } from '../../../types/root';
import { Mode } from '../../../types/enums';
const middleware = [thunk];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PERMISSIONS_PANEL_OPEN } from '../../../app/services/redux-constants';
import { togglePermissionsPanel } from '../../../app/services/actions/permissions-panel-action-creator';
import { PERMISSIONS_PANEL_OPEN } from '../redux-constants';
import { togglePermissionsPanel } from './permissions-panel-action-creator';

describe('Tests permissions panel action creator', () => {
it('tests permissions panel action creator', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { getProfileInfo, profileRequestError, getProfileInformation,
import {
getProfileInfo, profileRequestError, getProfileInformation,
profileRequestSuccess, getBetaProfile, getProfileType,
getProfileImage, getProfileResponse } from '../../../app/services/actions/profile-action-creators';
getProfileImage, getProfileResponse
} from './profile-action-creators';
import {
PROFILE_REQUEST_ERROR, PROFILE_REQUEST_SUCCESS} from '../../../app/services/redux-constants';
PROFILE_REQUEST_ERROR, PROFILE_REQUEST_SUCCESS
} from '../redux-constants';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

Expand Down Expand Up @@ -35,7 +38,7 @@ describe('actions', () => {
const includesError = store.getActions().filter(k => k.type === PROFILE_REQUEST_ERROR)
expect(!!includesError).toEqual(true);
})
.catch( (e : Error) => { throw e})
.catch((e: Error) => { throw e })
});

it('dispatches PROFILE_REQUEST_ERROR if profile request fails', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { runQuery } from '../../../app/services/actions/query-action-creators';
import { QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS, QUERY_GRAPH_SUCCESS } from '../../../app/services/redux-constants';
import { runQuery } from './query-action-creators';
import { QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS, QUERY_GRAPH_SUCCESS } from '../redux-constants';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('query actions', () => {
.then(() => {
expect(store.getActions()[0]).toEqual(expectedActions[0]);
})
.catch((e : Error) => { throw e});
.catch((e: Error) => { throw e });
});

it('dispatches QUERY_GRAPH_STATUS for failed requests', () => {
Expand Down Expand Up @@ -127,6 +127,6 @@ describe('query actions', () => {
.then(() => {
expect(store.getActions()[0]).toEqual(expectedActions[0]);
})
.catch((e : Error) => { throw e});
.catch((e: Error) => { throw e });
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { setSampleQuery } from '../../../app/services/actions/query-input-action-creators';
import { SET_SAMPLE_QUERY_SUCCESS } from '../../../app/services/redux-constants';
import { setSampleQuery } from './query-input-action-creators';
import { SET_SAMPLE_QUERY_SUCCESS } from '../redux-constants';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { addHistoryItem, viewHistoryItem, removeHistoryItem,
bulkRemoveHistoryItems } from '../../../app/services/actions/request-history-action-creators';
import { ADD_HISTORY_ITEM_SUCCESS, VIEW_HISTORY_ITEM_SUCCESS,
import {
addHistoryItem, viewHistoryItem, removeHistoryItem,
bulkRemoveHistoryItems
} from './request-history-action-creators';
import {
ADD_HISTORY_ITEM_SUCCESS, VIEW_HISTORY_ITEM_SUCCESS,
REMOVE_HISTORY_ITEM_SUCCESS,
REMOVE_ALL_HISTORY_ITEMS_SUCCESS} from '../../../app/services/redux-constants';
REMOVE_ALL_HISTORY_ITEMS_SUCCESS
} from '../redux-constants';
import { IHistoryItem } from '../../../types/history';

const middlewares = [thunk];
Expand All @@ -21,7 +25,7 @@ describe('Request History Action Creators', () => {
}
];

const store = mockStore({ history: []});
const store = mockStore({ history: [] });

// @ts-ignore
store.dispatch(addHistoryItem(historyItem));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { fetchSamplesSuccess, fetchSamplesError,
fetchSamplesPending } from '../../../app/services/actions/samples-action-creators';
import {
fetchSamplesSuccess, fetchSamplesError,
fetchSamplesPending
} from './samples-action-creators';
import {
SAMPLES_FETCH_SUCCESS, SAMPLES_FETCH_PENDING, SAMPLES_FETCH_ERROR
} from '../../../app/services/redux-constants';
} from '../redux-constants';


describe('actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
getSnippetSuccess, getSnippetError,
getSnippetPending,
getSnippet
} from '../../../app/services/actions/snippet-action-creator';
import { GET_SNIPPET_SUCCESS, GET_SNIPPET_ERROR, GET_SNIPPET_PENDING } from '../../../app/services/redux-constants';
} from './snippet-action-creator';
import { GET_SNIPPET_SUCCESS, GET_SNIPPET_ERROR, GET_SNIPPET_PENDING } from '../redux-constants';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import { toggleSidebar } from '../../../app/services/actions/toggle-sidebar-action-creator';
import { TOGGLE_SIDEBAR_SUCCESS } from '../../../app/services/redux-constants';
import { toggleSidebar } from './toggle-sidebar-action-creator';
import { TOGGLE_SIDEBAR_SUCCESS } from '../redux-constants';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { authToken, consentedScopes } from '../../../app/services/reducers/auth-reducers';
import { GET_AUTH_TOKEN_SUCCESS, GET_CONSENTED_SCOPES_SUCCESS } from '../../../app/services/redux-constants';
import { authToken, consentedScopes } from './auth-reducers';
import { GET_AUTH_TOKEN_SUCCESS, GET_CONSENTED_SCOPES_SUCCESS } from '../redux-constants';

describe('Auth Reducer', () => {
it('should return initial state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sampleQuery } from '../../../app/services/reducers/query-input-reducers';
import { SET_SAMPLE_QUERY_SUCCESS } from '../../../app/services/redux-constants';
import { sampleQuery } from './query-input-reducers';
import { SET_SAMPLE_QUERY_SUCCESS } from '../redux-constants';

describe('Query INput Reducer', () => {
it('should return initial state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isLoadingData } from '../../../app/services/reducers/query-loading-reducers';
import { isLoadingData } from './query-loading-reducers';
import {
FETCH_SCOPES_ERROR,
GET_CONSENT_ERROR,
Expand All @@ -7,7 +7,7 @@ import {
QUERY_GRAPH_RUNNING,
QUERY_GRAPH_STATUS,
QUERY_GRAPH_SUCCESS
} from '../../../app/services/redux-constants';
} from '../redux-constants';

describe('Query loading reducer', () => {
it('should return false in case of get_consent error', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { graphResponse } from '../../../app/services/reducers/query-runner-reducers';
import { queryRunnerStatus } from '../../../app/services/reducers/query-runner-status-reducers';
import { CLEAR_QUERY_STATUS, QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS,
QUERY_GRAPH_SUCCESS, VIEW_HISTORY_ITEM_SUCCESS } from '../../../app/services/redux-constants';
import { graphResponse } from './query-runner-reducers';
import { queryRunnerStatus } from './query-runner-status-reducers';
import {
CLEAR_QUERY_STATUS, QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS,
QUERY_GRAPH_SUCCESS, VIEW_HISTORY_ITEM_SUCCESS
} from '../redux-constants';
import { IGraphResponse } from '../../../types/query-response';

describe('Query Runner Reducer', () => {
Expand Down Expand Up @@ -60,7 +62,7 @@ describe('Query Runner Reducer', () => {
}
};

const action = { type: VIEW_HISTORY_ITEM_SUCCESS, response: mockResponse };
const action = { type: VIEW_HISTORY_ITEM_SUCCESS, response: mockResponse };

const newState = queryRunnerStatus(initialState, action);
expect(newState).toEqual(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { history } from '../../../app/services/reducers/request-history-reducers';
import { ADD_HISTORY_ITEM_SUCCESS, REMOVE_ALL_HISTORY_ITEMS_SUCCESS,
REMOVE_HISTORY_ITEM_SUCCESS } from '../../../app/services/redux-constants';
import { history } from './request-history-reducers';
import {
ADD_HISTORY_ITEM_SUCCESS, REMOVE_ALL_HISTORY_ITEMS_SUCCESS,
REMOVE_HISTORY_ITEM_SUCCESS
} from '../redux-constants';


describe('Request History Reducer', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { snippets } from '../../../app/services/reducers/snippet-reducer';
import { GET_SNIPPET_ERROR, GET_SNIPPET_SUCCESS } from '../../../app/services/redux-constants';
import { snippets } from './snippet-reducer';
import { GET_SNIPPET_ERROR, GET_SNIPPET_SUCCESS } from '../redux-constants';

describe('Graph Explorer Snippet Reducer', () => {
it('should set csharp code snippet', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sidebarProperties } from '../../../app/services/reducers/toggle-sidebar-reducer';
import { sidebarProperties } from './toggle-sidebar-reducer';
import {
SET_SAMPLE_QUERY_SUCCESS, TOGGLE_SIDEBAR_SUCCESS,
VIEW_HISTORY_ITEM_SUCCESS
} from '../../../app/services/redux-constants';
} from '../redux-constants';


describe('Toggle sidebar', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dynamicSort } from '../../app/utils/dynamic-sort';
import { dynamicSort } from './dynamic-sort';
import { SortOrder } from '../../types/enums';

describe('Dynamic Sort', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isValidHttpsUrl, validateExternalLink } from '../../app/utils/external-link-validation';
import { isValidHttpsUrl, validateExternalLink } from './external-link-validation';

describe('External link', () => {

const links = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateGroupsFromList } from '../../app/utils/generate-groups';
import { generateGroupsFromList } from './generate-groups';

function setUp() {
return [{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lookupToolkitUrl } from '../../app/utils/graph-toolkit-lookup';
import { lookupToolkitUrl } from './graph-toolkit-lookup';

describe('Tests lookToolkitUrl', () => {
it('Returns valid toolkit url depending on sampleQuery passed', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringToHash } from '../../app/utils/hash-string';
import { stringToHash } from './hash-string';

describe('String to hash should', () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { parseOpenApiResponse } from '../../app/utils/open-api-parser';
import { parseSampleUrl } from '../../app/utils/sample-url-generation';
import { parseOpenApiResponse } from './open-api-parser';
import { getSample } from './open-api-sample';

import { parseSampleUrl } from './sample-url-generation';

describe('Open api spec parser should', () => {

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import {
sanitizeQueryParameter
} from '../../app/utils/query-parameter-sanitization';
import { isAllAlpha, sanitizeQueryParameter } from './query-parameter-sanitization';

describe('isAllAlpha should ', () => {
const list = [
{ key: 'aaa', isAllAlphabetic: true },
{ key: 'aZa', isAllAlphabetic: true },
{ key: '111', isAllAlphabetic: false },
{ key: '1a1', isAllAlphabetic: false }
];

list.forEach(element => {
it(`return ${element.isAllAlphabetic} for ${element.key}`, () => {
const key = isAllAlpha(element.key);
expect(key).toBe(element.isAllAlphabetic);
});
});
});

describe('Sanitize Query Parameters should', () => {
const list = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
import {
isAllAlpha
} from '../../app/utils/query-parameter-sanitization';
import {
isDeprecation, sanitizeQueryUrl
} from '../../app/utils/query-url-sanitization';


describe('isAllAlpha should ', () => {
const list = [
{ key: 'aaa', isAllAlphabetic: true },
{ key: 'aZa', isAllAlphabetic: true },
{ key: '111', isAllAlphabetic: false },
{ key: '1a1', isAllAlphabetic: false }
];

list.forEach(element => {
it(`return ${element.isAllAlphabetic} for ${element.key}`, () => {
const key = isAllAlpha(element.key);
expect(key).toBe(element.isAllAlphabetic);
});
});
});
} from './query-url-sanitization';

describe('isDepraction should ', () => {
const list = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasWhiteSpace, parseSampleUrl } from '../../app/utils/sample-url-generation';
import { hasWhiteSpace, parseSampleUrl } from './sample-url-generation';

describe('Sample Url Generation', () => {

Expand Down Expand Up @@ -80,15 +80,17 @@ describe('Sample Url Generation', () => {

describe('hasWhiteSpaces should', () => {
const invalidUrls = [
{url: ' https://graph.microsoft.com/v1.0/me', output: false},
{url: 'https: //graph.microsoft.com/v1.0/me', output: true},
{url: 'https://%20graph.microsoft.com/v1.0/me', output: true},
{url: 'https://graph.microsoft.com/ v1.0/me', output: true},
{url: 'https://graph.microsoft.com/v1.0/ me', output: true},
{url:
'https://graph.microsoft.com/v1.0/me/contacts?$filter=emailAddresses/any(a:a/address eq \'garth@contoso.com\')',
output: false},
{url: 'https://graph.microsoft.com/v1.0/me ', output: false}
{ url: ' https://graph.microsoft.com/v1.0/me', output: false },
{ url: 'https: //graph.microsoft.com/v1.0/me', output: true },
{ url: 'https://%20graph.microsoft.com/v1.0/me', output: true },
{ url: 'https://graph.microsoft.com/ v1.0/me', output: true },
{ url: 'https://graph.microsoft.com/v1.0/ me', output: true },
{
url:
'https://graph.microsoft.com/v1.0/me/contacts?$filter=emailAddresses/any(a:a/address eq \'garth@contoso.com\')',
output: false
},
{ url: 'https://graph.microsoft.com/v1.0/me ', output: false }
];
invalidUrls.forEach(invalidUrl => {
it(`validate whitespaces in the url: ${invalidUrl.url}`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-len */
import { extractUrl, replaceLinks, convertArrayToObject, getMatchesAndParts, setStatusMessage } from '../../app/utils/status-message';
import { extractUrl, replaceLinks, convertArrayToObject, getMatchesAndParts, setStatusMessage } from './status-message';

describe('status message should', () => {

Expand Down
File renamed without changes.
Loading

0 comments on commit 92b515f

Please sign in to comment.