more test coverage
This commit is contained in:
Родитель
be8434f5e9
Коммит
3fb5504334
|
@ -5,7 +5,7 @@ import Sample from '../../data-sources/plugins/Sample';
|
|||
import { formatTests } from './formats';
|
||||
import * as formats from '../../utils/data-formats';
|
||||
|
||||
describe('Data Source: Application Insights: Forked Query', () => {
|
||||
describe('Data Formats', () => {
|
||||
|
||||
let sampleMockPlugin = new Sample(<any>{
|
||||
params: {
|
||||
|
@ -18,7 +18,7 @@ describe('Data Source: Application Insights: Forked Query', () => {
|
|||
|
||||
Object.keys(formatTests).forEach(testFormat => {
|
||||
|
||||
it ('Check data format ' + testFormat, () => {
|
||||
it (testFormat, () => {
|
||||
|
||||
let testCase = formatTests[testFormat];
|
||||
let tests = [];
|
||||
|
@ -37,8 +37,10 @@ describe('Data Source: Application Insights: Forked Query', () => {
|
|||
params: test.params
|
||||
}, {});
|
||||
}
|
||||
|
||||
let dependencies = test.dependencies || {};
|
||||
|
||||
let result = formats[testFormat](test.format, test.state, {}, mockPlugin, {});
|
||||
let result = formats[testFormat](test.format, test.state, dependencies, mockPlugin, {});
|
||||
expect(result).toMatchObject(test.expected);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import * as _ from 'lodash';
|
||||
import { IFormatTest } from './formats';
|
||||
|
||||
const values = [
|
||||
{ name: 'skype-en', value: 9, locale: 'en', channel: 'skype' },
|
||||
{ name: 'skype-fr', value: 8, locale: 'fr', channel: 'skype' },
|
||||
{ name: 'skype-de', value: 7, locale: 'de', channel: 'skype' },
|
||||
{ name: 'messenger-en', value: 6, locale: 'en', channel: 'messenger' },
|
||||
{ name: 'messenger-fr', value: 5, locale: 'fr', channel: 'messenger' },
|
||||
{ name: 'messenger-de', value: 4, locale: 'de', channel: 'messenger' },
|
||||
{ name: 'slack-en', value: 3, locale: 'en', channel: 'slack' },
|
||||
{ name: 'slack-fr', value: 2, locale: 'fr', channel: 'slack' },
|
||||
{ name: 'slack-de', value: 1, locale: 'de', channel: 'slack' }
|
||||
];
|
||||
|
||||
export default <IFormatTest[]>[
|
||||
{
|
||||
format: 'filtered_samples',
|
||||
params: {
|
||||
samples: { values },
|
||||
filters: [
|
||||
{ dependency: 'selectedFilter1', queryProperty: 'locale' },
|
||||
{ dependency: 'selectedFilter2', queryProperty: 'channel' }
|
||||
]
|
||||
},
|
||||
dependencies: {
|
||||
values,
|
||||
selectedFilter1: [],
|
||||
selectedFilter2: []
|
||||
},
|
||||
state: { values: [ 'value 1', 'value 2', 'value 3' ] },
|
||||
expected: {
|
||||
"filtered_values": values
|
||||
}
|
||||
},
|
||||
{
|
||||
format: 'filtered_samples',
|
||||
params: {
|
||||
samples: { values },
|
||||
filters: [
|
||||
{ dependency: 'selectedFilter1', queryProperty: 'locale' },
|
||||
{ dependency: 'selectedFilter2', queryProperty: 'channel' }
|
||||
]
|
||||
},
|
||||
dependencies: {
|
||||
values,
|
||||
selectedFilter1: ['en'],
|
||||
selectedFilter2: []
|
||||
},
|
||||
state: { values: [ 'value 1', 'value 2', 'value 3' ] },
|
||||
expected: {
|
||||
"filtered_values": _.filter(values, { locale: 'en' })
|
||||
}
|
||||
}
|
||||
];
|
|
@ -2,5 +2,6 @@ export interface IFormatTest {
|
|||
format: any,
|
||||
params?: any,
|
||||
state: any,
|
||||
dependencies?: any,
|
||||
expected: any
|
||||
}
|
|
@ -6,5 +6,15 @@ import retention from './retention';
|
|||
import scorecard from './scorecard';
|
||||
import timeline from './timeline';
|
||||
import timespan from './timespan';
|
||||
import filtered_samples from './filtered_samples';
|
||||
|
||||
export const formatTests = <IDict<IFormatTest | IFormatTest[]>>{ bars, filter, flags, retention, scorecard, timeline, timespan };
|
||||
export const formatTests = <IDict<IFormatTest | IFormatTest[]>>{
|
||||
bars,
|
||||
filter,
|
||||
flags,
|
||||
retention,
|
||||
scorecard,
|
||||
timeline,
|
||||
timespan,
|
||||
filtered_samples
|
||||
};
|
|
@ -1,34 +1,71 @@
|
|||
import { IFormatTest } from './formats';
|
||||
|
||||
export default <IFormatTest>{
|
||||
format: 'retention',
|
||||
state: {
|
||||
values: [
|
||||
{
|
||||
totalUnique: 10,
|
||||
totalUniqueUsersIn24hr: 5,
|
||||
totalUniqueUsersIn7d: 7,
|
||||
totalUniqueUsersIn30d: 10,
|
||||
returning24hr: 3,
|
||||
returning7d: 3,
|
||||
returning30d: 6
|
||||
}
|
||||
]
|
||||
export default <IFormatTest[]>[
|
||||
{
|
||||
format: 'retention',
|
||||
state: {
|
||||
values: [
|
||||
{
|
||||
totalUnique: 10,
|
||||
totalUniqueUsersIn24hr: 5,
|
||||
totalUniqueUsersIn7d: 7,
|
||||
totalUniqueUsersIn30d: 10,
|
||||
returning24hr: 3,
|
||||
returning7d: 3,
|
||||
returning30d: 6
|
||||
}
|
||||
]
|
||||
},
|
||||
expected: {
|
||||
"returning": 0,
|
||||
"returning24hr": 3,
|
||||
"returning30d": 6,
|
||||
"returning7d": 3,
|
||||
"total": 0,
|
||||
"totalUnique": 10,
|
||||
"totalUniqueUsersIn24hr": 5,
|
||||
"totalUniqueUsersIn30d": 10,
|
||||
"totalUniqueUsersIn7d": 7,
|
||||
"values": [
|
||||
{ "retention": "60%", "returning": 3, "timespan": "24 hours", "unique": 5 },
|
||||
{ "retention": "43%", "returning": 3, "timespan": "7 days", "unique": 7 },
|
||||
{ "retention": "60%", "returning": 6, "timespan": "30 days", "unique": 10 }
|
||||
]
|
||||
}
|
||||
},
|
||||
expected: {
|
||||
"returning": 0,
|
||||
"returning24hr": 3,
|
||||
"returning30d": 6,
|
||||
"returning7d": 3,
|
||||
"total": 0,
|
||||
"totalUnique": 10,
|
||||
"totalUniqueUsersIn24hr": 5,
|
||||
"totalUniqueUsersIn30d": 10,
|
||||
"totalUniqueUsersIn7d": 7,
|
||||
"values": [
|
||||
{ "retention": "60%", "returning": 3, "timespan": "24 hours", "unique": 5 },
|
||||
{ "retention": "43%", "returning": 3, "timespan": "7 days", "unique": 7 },
|
||||
{ "retention": "60%", "returning": 6, "timespan": "30 days", "unique": 10 }
|
||||
]
|
||||
{
|
||||
format: 'retention',
|
||||
dependencies: {
|
||||
selectedTimespan: 'PT24H'
|
||||
},
|
||||
state: {
|
||||
values: [
|
||||
{
|
||||
totalUnique: 10,
|
||||
totalUniqueUsersIn24hr: 5,
|
||||
totalUniqueUsersIn7d: 7,
|
||||
totalUniqueUsersIn30d: 10,
|
||||
returning24hr: 3,
|
||||
returning7d: 3,
|
||||
returning30d: 6
|
||||
}
|
||||
]
|
||||
},
|
||||
expected: {
|
||||
"returning": 3,
|
||||
"returning24hr": 3,
|
||||
"returning30d": 6,
|
||||
"returning7d": 3,
|
||||
"total": 5,
|
||||
"totalUnique": 10,
|
||||
"totalUniqueUsersIn24hr": 5,
|
||||
"totalUniqueUsersIn30d": 10,
|
||||
"totalUniqueUsersIn7d": 7,
|
||||
"values": [
|
||||
{ "retention": "60%", "returning": 3, "timespan": "24 hours", "unique": 5 },
|
||||
{ "retention": "43%", "returning": 3, "timespan": "7 days", "unique": 7 },
|
||||
{ "retention": "60%", "returning": 6, "timespan": "30 days", "unique": 10 }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
];
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* Use this method to rewire a module to render children other than
|
||||
* it's native components. (For shalow testing)
|
||||
*
|
||||
* @link http://stackoverflow.com/questions/32057745/using-scryrenderedcomponentswithtype-or-findrenderedcomponentwithtype
|
||||
*
|
||||
* @param rewiredModule - The React module to rewire
|
||||
* @param varValues - The new component to use
|
||||
*/
|
||||
function rewireModule (rewiredModule, varValues) {
|
||||
let rewiredReverts = [];
|
||||
|
||||
beforeEach(() => {
|
||||
let key, value, revert;
|
||||
for (key in varValues) {
|
||||
if (varValues.hasOwnProperty(key)) {
|
||||
value = varValues[key];
|
||||
revert = rewiredModule.__set__(key, value);
|
||||
rewiredReverts.push(revert);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rewiredReverts.forEach(revert => revert());
|
||||
});
|
||||
|
||||
return rewiredModule;
|
||||
}
|
||||
|
||||
export { rewireModule };
|
|
@ -0,0 +1,12 @@
|
|||
import utils from "../../utils";
|
||||
import AccountActions from "../../actions/AccountActions";
|
||||
import { mockRequests } from '../mocks/requests/account';
|
||||
|
||||
describe('Utils', () => {
|
||||
|
||||
it ('Ago', () => {
|
||||
let time = new Date();
|
||||
time.setSeconds(time.getSeconds() - 10);
|
||||
expect(utils.ago(time)).toBe('10 seconds ago');
|
||||
});
|
||||
});
|
|
@ -26,11 +26,7 @@ export function filtered_samples (
|
|||
prevState: any) {
|
||||
let result = {};
|
||||
|
||||
if (typeof format === 'string') {
|
||||
return formatWarn('format should be an object with args', 'bars', plugin);
|
||||
}
|
||||
|
||||
const args = format.args || {};
|
||||
const args = typeof format !== 'string' && format.args || {};
|
||||
const prefix = args['prefix'] || 'filtered';
|
||||
|
||||
const params = plugin.getParams();
|
||||
|
|
Загрузка…
Ссылка в новой задаче