Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Apr 9, 2024
1 parent 1885658 commit dc086af
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 102 deletions.
6 changes: 3 additions & 3 deletions src/actions/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export const onHistoryMiddleware = ({ dispatch, getState }) => (next) => (action
dispatch(selectDevice(pathDongleId, false));
}

// TODO: this should redirect to a log id
const pathZoom = getZoom(action.payload.location.pathname);
if (pathZoom !== state.zoom) {
console.debug("TODO: this should redirect to a log id")
//dispatch(pushTimelineRange(pathZoom?.start, pathZoom?.end, false));
}

const pathSegmentRange = getSegmentRange(action.payload.location.pathname);
if (pathSegmentRange != state.segmentRange) {
dispatch(pushTimelineRange(pathSegmentRange?.log_id, pathSegmentRange?.start, pathSegmentRange?.end, true));
if (pathSegmentRange !== state.segmentRange) {
dispatch(pushTimelineRange(pathSegmentRange?.log_id, pathSegmentRange?.start, pathSegmentRange?.end, false));
}

const pathPrimeNav = getPrimeNav(action.payload.location.pathname);
Expand Down
7 changes: 3 additions & 4 deletions src/actions/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('history middleware', () => {
};
invoke(action);
expect(next).toHaveBeenCalledWith(action);
expect(store.dispatch).toHaveBeenCalledTimes(1);
expect(store.dispatch).toHaveBeenCalledWith(fakeInner);
expect(actionsIndex.selectDevice).toHaveBeenCalledWith('0000aaaa0000aaaa', false);
});
Expand All @@ -96,14 +95,14 @@ describe('history middleware', () => {
type: LOCATION_CHANGE,
payload: {
action: 'POP',
location: { pathname: '0000aaaa0000aaaa/1230/1234' },
location: { pathname: '0000aaaa0000aaaa/00000014--55a0b1280e/1230/1234' },
},
};
invoke(action);
expect(next).toHaveBeenCalledWith(action);
expect(store.dispatch).toHaveBeenCalledTimes(1);
expect(store.dispatch).toHaveBeenCalledWith(fakeInner);
expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(1230, 1234, false);
expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith('00000014--55a0b1280e', 1230, 1234, false);
});

it('should call prime nav with history', async () => {
Expand All @@ -130,7 +129,7 @@ describe('history middleware', () => {
expect(store.dispatch).toHaveBeenCalledTimes(2);
expect(store.dispatch).toHaveBeenCalledWith(fakeInner);
expect(store.dispatch).toHaveBeenCalledWith(fakeInner2);
expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(undefined, undefined, false);
expect(actionsIndex.pushTimelineRange).toHaveBeenCalledWith(undefined, undefined, undefined, false);
expect(actionsIndex.primeNav).toHaveBeenCalledWith(true);
});
});
1 change: 0 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export function checkRoutesData() {
...r,
url: r.url.replace('chffrprivate.blob.core.windows.net', 'chffrprivate.azureedge.net'),
log_id: r.fullname.split('|')[1],
//offset: Math.round(startTime),
duration: endTime - startTime,
start_time_utc_millis: startTime,
end_time_utc_millis: endTime,
Expand Down
4 changes: 2 additions & 2 deletions src/actions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe('timeline actions', () => {
it('should push history state when editing zoom', () => {
const dispatch = jest.fn();
const getState = jest.fn();
const actionThunk = pushTimelineRange(123, 1234);
const actionThunk = pushTimelineRange("log_id", 123, 1234);

getState.mockImplementationOnce(() => ({
dongleId: 'statedongle',
loop: {},
zoom: {},
}));
actionThunk(dispatch, getState);
expect(push).toBeCalledWith('/statedongle/123/1234');
expect(push).toBeCalledWith('/statedongle/log_id/123/1234');
});
});
3 changes: 1 addition & 2 deletions src/components/TimeDisplay/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class TimeDisplay extends Component {

getDisplayTime() {
const offset = currentOffset();
const { filter, currentRoute } = this.props;
const { currentRoute } = this.props;
const now = new Date(offset + currentRoute.start_time_utc_millis);
if (Number.isNaN(now.getTime())) {
return '...';
Expand Down Expand Up @@ -299,7 +299,6 @@ const stateToProps = Obstruction({
currentRoute: 'currentRoute',
zoom: 'zoom',
desiredPlaySpeed: 'desiredPlaySpeed',
filter: 'filter',
});

export default connect(stateToProps)(withStyles(styles)(TimeDisplay));
2 changes: 1 addition & 1 deletion src/initialState.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDongleID, getZoom, getPrimeNav, getSegmentRange } from './url';
import { getDongleID, getPrimeNav, getSegmentRange } from './url';
import * as Demo from './demo';

export function getDefaultFilter() {
Expand Down
6 changes: 3 additions & 3 deletions src/reducers/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ export default function reducer(_state, action) {
};

if (!state.currentRoute && state.segmentRange) {
const r = state.routes?.find((route) => route.log_id === state.segmentRange.log_id);
if (r) {
const curr = state.routes?.find((route) => route.log_id === state.segmentRange.log_id);
if (curr) {
state.currentRoute = {
...r,
...curr,
};
if (state.segmentRange.start && state.segmentRange.end) {
state.zoom = {
Expand Down
2 changes: 1 addition & 1 deletion src/timeline/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function reducer(_state, action) {
break;
}

if (state.currentRoute && state.currentRoute.videoStartOffset && state.loop && state.zoom && state.filter
if (state.currentRoute && state.currentRoute.videoStartOffset && state.loop && state.zoom
&& state.loop.startTime === state.zoom.start && state.zoom.start === 0) {
const loopRouteOffset = state.loop.startTime - state.zoom.start;
if (state.currentRoute.videoStartOffset > loopRouteOffset) {
Expand Down
22 changes: 9 additions & 13 deletions src/timeline/playback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { bufferVideo, pause, play, reducer, seek, selectLoop } from './playback'

const makeDefaultStruct = function makeDefaultStruct() {
return {
filter: {
start: Date.now(),
end: Date.now() + 100000,
},
desiredPlaySpeed: 1, // 0 = stopped, 1 = playing, 2 = 2x speed... multiplier on speed
desiredPlaySpeed: 1, // 0 = stopped, 1 = playing, 2 = 2x speed
offset: 0, // in miliseconds from the start
startTime: Date.now(), // millisecond timestamp in which play began

Expand Down Expand Up @@ -81,14 +77,14 @@ describe('playback', () => {
// set up loop
state = reducer(state, play());
state = reducer(state, selectLoop(
state.filter.start + 1000,
state.filter.start + 2000,
1000,
2000,
));
expect(state.loop.startTime).toEqual(state.filter.start + 1000);
expect(state.loop.startTime).toEqual(1000);

// seek past loop end boundary a
state = reducer(state, seek(3000));
expect(state.loop.startTime).toEqual(state.filter.start + 1000);
expect(state.loop.startTime).toEqual(1000);
expect(state.offset).toEqual(2000);
});

Expand All @@ -99,14 +95,14 @@ describe('playback', () => {
// set up loop
state = reducer(state, play());
state = reducer(state, selectLoop(
state.filter.start + 1000,
state.filter.start + 2000,
1000,
2000,
));
expect(state.loop.startTime).toEqual(state.filter.start + 1000);
expect(state.loop.startTime).toEqual(1000);

// seek past loop end boundary a
state = reducer(state, seek(0));
expect(state.loop.startTime).toEqual(state.filter.start + 1000);
expect(state.loop.startTime).toEqual(1000);
expect(state.offset).toEqual(1000);
});

Expand Down
2 changes: 0 additions & 2 deletions src/timeline/segments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as Types from '../actions/types';

export function getSegmentFetchRange(state) {
// TODO: fix this for relative routes
return state.filter;
Expand Down
69 changes: 0 additions & 69 deletions src/timeline/segments.test.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,9 @@
/* eslint-env jest */
import { getCurrentRoute } from '.';
import { hasRoutesData } from './segments';
import { getSegmentNumber } from '../utils';

export const SEGMENT_LENGTH = 1000 * 60;

const routes = [{
fullname: '99c94dc769b5d96e|2018-04-09--10-10-00',
offset: 36600000,
duration: 2558000,
segment_numbers: Array.from(Array(43).keys()),
segment_offsets: Array.from(Array(43).keys()).map((i) => i * SEGMENT_LENGTH + 36600000),
events: [{
time: 36600123,
type: 'event',
}],
}, {
fullname: '99c94dc769b5d96e|2018-04-09--11-29-08',
offset: 41348000,
duration: 214000,
segment_numbers: Array.from(Array(4).keys()),
segment_offsets: Array.from(Array(4).keys()).map((i) => i * SEGMENT_LENGTH + 41348000),
events: [{
time: 41348123,
type: 'event',
}],
}];

describe('segments', () => {
it('finds current segment', async () => {
const [route] = routes;
let r = getCurrentRoute({
routes,
offset: route.offset,
desiredPlaySpeed: 1,
startTime: Date.now(),
});
expect(r.fullname).toBe(route.fullname);
expect(getSegmentNumber(r, route.offset)).toBe(0);

r = getCurrentRoute({
routes,
offset: route.offset + SEGMENT_LENGTH * 1.1,
desiredPlaySpeed: 1,
startTime: Date.now(),
});
expect(getSegmentNumber(r, route.offset + SEGMENT_LENGTH * 1.1)).toBe(1);
});

it('finds last segment of a route', async () => {
const [route] = routes;
const offset = route.offset + SEGMENT_LENGTH * (route.segment_offsets.length - 1) + 1000;
const r = getCurrentRoute({
routes,
offset,
desiredPlaySpeed: 1,
startTime: Date.now(),
});
expect(r.fullname).toBe(route.fullname);
expect(getSegmentNumber(r, offset)).toBe(route.segment_offsets.length - 1);
});

it('ends last segment of a route', async () => {
const [route] = routes;
const offset = route.offset + route.duration - 10;
const r = getCurrentRoute({
routes,
offset,
desiredPlaySpeed: 1,
startTime: Date.now() - 50,
});
expect(getSegmentNumber(r, offset)).toBe(null);
});

it('can check if it has segment metadata', () => {
expect(hasRoutesData()).toBe(false);
expect(hasRoutesData({})).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getPrimeNav(pathname) {
let parts = pathname.split('/');
parts = parts.filter((m) => m.length);

if (parts.length === 2 && parts[0] !== 'auth' && parts[1] === 'prime') {
if (parts.length === 2 && dongleIdRegex.test(parts[0]) && parts[1] === 'prime') {
return true;
}
return false;
Expand Down

0 comments on commit dc086af

Please sign in to comment.