Skip to content

Commit

Permalink
added small suite of tests to validate defaults.js using Jest - MR
Browse files Browse the repository at this point in the history
  • Loading branch information
marungo committed Mar 22, 2018
1 parent 6802928 commit 16a242c
Show file tree
Hide file tree
Showing 7 changed files with 2,598 additions and 180 deletions.
Binary file modified .DS_Store
Binary file not shown.
88 changes: 88 additions & 0 deletions __tests__/defaults.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { defaultValues, createDefaultLevelsObject, createDefaultBranch, createDefaultBranchesObject } from '../app/utilities/defaults';

describe('Default Branches Setup', () => {
it('is defaulted to first frame of video', () => {
expect(defaultValues.time).toBe("00:00.01");
});


it('creates a branch properly', () => {
const expectedBranch = {
start: "00:00.01",
end: "00:00.01",
enabled: true,
outcome: "0"
};

expect(createDefaultBranch()).toEqual(expectedBranch);
});

it('creates an object with 6 emotion branches', () => {
const defaultBranch = {
start: "00:00.01",
end: "00:00.01",
enabled: true,
outcome: "0"
};

const expected = {
"Anger": defaultBranch,
"Fear": defaultBranch,
"Calm": defaultBranch,
"Disgust": defaultBranch,
"Contempt": defaultBranch,
"Surprise": defaultBranch
};

expect(createDefaultBranchesObject()).toEqual(expected);
});

});

describe('Default Levels Setup', () => {
it ('is expected to create an empty object', () => {
expect(createDefaultLevelsObject(0)).toEqual({});
});

it ('is expected to return empty object with negative input', () => {
expect(createDefaultLevelsObject(-3)).toEqual({});
});

it('is expected to create an object with one level', () => {
const oneLevel = {
1: {
level: 1,
start: "00:00.01",
end: "00:00.01",
branches: createDefaultBranchesObject()
}
};

expect(createDefaultLevelsObject(1)).toEqual(oneLevel);
});

it('is expected to create an object with 3 levels', () => {
const threeLevels = {
1: {
level: 1,
start: "00:00.01",
end: "00:00.01",
branches: createDefaultBranchesObject()
},
2: {
level: 2,
start: "00:00.01",
end: "00:00.01",
branches: createDefaultBranchesObject()
},
3: {
level: 3,
start: "00:00.01",
end: "00:00.01",
branches: createDefaultBranchesObject()
}
};

expect(createDefaultLevelsObject(3)).toEqual(threeLevels);
});
});
18 changes: 7 additions & 11 deletions app/utilities/defaults.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
export const defaultValues = {
time: "00:00.01",
enabled: true,
video: "src/main/resources/video/film_with_credits.m4v",
audio: "src/main/resources/audio/audio.wav"
}

const createDefaultBranch = () => {
export const createDefaultBranch = () => {
return {
start: defaultValues.time,
end: defaultValues.time,
Expand All @@ -14,7 +7,7 @@ const createDefaultBranch = () => {
};
}

const createDefaultBranchesObject = () => {
export const createDefaultBranchesObject = () => {
const emotions = ["Anger", "Fear", "Calm", "Disgust", "Contempt", "Surprise"];

let branches = {}
Expand All @@ -37,6 +30,9 @@ export const createDefaultLevelsObject = (numLevels) => {
return populatedLevels;
}

export const allInputsValid = (state) => {

export const defaultValues = {
time: "00:00.01",
enabled: true,
video: "src/main/resources/video/film_with_credits.m4v",
audio: "src/main/resources/audio/audio.wav"
}
14 changes: 9 additions & 5 deletions app/utilities/exportHelperFunctions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const convertToMilliseconds = (value, numFrames) => {
export const convertToMilliseconds = (value, numFrames) => {
if (Number(numFrames) <= 0) {
return "number of frames must be a positive integer";
}

const valuesArray = value.split(".");
const numMillisecondsPerFrame = 1000/Number(numFrames);
const frame = Number(valuesArray[1])-1; // convert to a 0-indexed format
Expand All @@ -7,7 +11,7 @@ const convertToMilliseconds = (value, numFrames) => {
return valuesArray[0] + "." + milliseconds;
}

const traverseAndConvertToMilliseconds = (state, numFrames) => {
export const traverseAndConvertToMilliseconds = (state, numFrames) => {
if( typeof state == "object" ) {
Object.entries(state).forEach(([key, value]) => {

Expand All @@ -22,7 +26,7 @@ const traverseAndConvertToMilliseconds = (state, numFrames) => {
}
}

const trimStateAndArrayify = (state) => {
export const trimStateAndArrayify = (state) => {
let levels = state.levels;

Object.keys(levels).map( function(levelId,_) {
Expand All @@ -42,15 +46,15 @@ const trimStateAndArrayify = (state) => {
state.displayvalue = undefined;
}

const arrayifyLevelsObject = (levels) => {
export const arrayifyLevelsObject = (levels) => {
let levelsArray = new Array(Object.keys(levels).length);
Object.keys(levels).map((levelIndex,_) => {
levelsArray[levelIndex-1] = levels[levelIndex];
});
return levelsArray;
}

const arrayifySlidesObject = (slides, slideType) => {
export const arrayifySlidesObject = (slides, slideType) => {
const slideKeys = Object.keys(slides).sort();
let slideArray = [];
for (let i=0; i<slideKeys.length;i++) {
Expand Down
Loading

0 comments on commit 16a242c

Please sign in to comment.