Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
enable skipped tests and fix memoization (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril committed Dec 13, 2019
1 parent 48e6eb7 commit cc8a8c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import shallowEqual from 'shallow-equals';
import {Dictionary} from 'types/utilities';
export function memoizeResult<F extends Function>(func: F): any {
let lastArgs: IArguments|null = null;
let lastResult: any = null; // we reference arguments instead of spreading them for performance reasons
let lastResult: any = null;

return function shallowCompare(...args: any[]) {
if (!shallowEqual(lastArgs, args)) {
// we reference arguments instead of spreading them for performance reasons
return function shallowCompare() {
if (!shallowEqual(lastArgs, arguments)) { //eslint-disable-line prefer-rest-params
//eslint-disable-line prefer-rest-params
// apply arguments instead of spreading for performance.
const result = Reflect.apply(func, null, arguments); //eslint-disable-line prefer-rest-params
Expand Down
19 changes: 14 additions & 5 deletions src/utils/post_list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import assert from 'assert';

import {Posts, Preferences} from 'constants';
import {Posts, Preferences} from '../constants';
import deepFreeze from 'utils/deep_freeze';
import {getPreferenceKey} from 'utils/preference_utils';

Expand Down Expand Up @@ -35,6 +35,9 @@ describe('makeFilterPostsAndAddSeparators', () => {

let state = {
entities: {
general: {
config: {},
},
posts: {
posts: {
1001: {id: '1001', create_at: time, type: ''},
Expand Down Expand Up @@ -147,6 +150,9 @@ describe('makeFilterPostsAndAddSeparators', () => {

const state = {
entities: {
general: {
config: {},
},
posts: {
posts: {
1000: {id: '1000', create_at: time + 1000, type: ''},
Expand Down Expand Up @@ -251,6 +257,9 @@ describe('makeFilterPostsAndAddSeparators', () => {
};
let state = {
entities: {
general: {
config: {},
},
posts: {
posts: initialPosts,
},
Expand Down Expand Up @@ -903,19 +912,19 @@ describe('getLastPostId', () => {
});

describe('getLastPostIndex', () => {
test.only('should return index of last post for list of all regular posts', () => {
test('should return index of last post for list of all regular posts', () => {
expect(getLastPostIndex(['post1', 'post2', 'post3'])).toBe(2);
});

test.only('should return index of last combined post', () => {
test('should return index of last combined post', () => {
expect(getLastPostIndex(['user-activity-post2_post3', 'post4', 'user-activity-post5_post6'])).toBe(2);
});

test.only('should skip date separators and return index of last post', () => {
test('should skip date separators and return index of last post', () => {
expect(getLastPostIndex(['date-1234', 'user-activity-post1_post2', 'post3', 'post4', 'date-1000'])).toBe(3);
});

test.only('should skip the new message line and return index of last post', () => {
test('should skip the new message line and return index of last post', () => {
expect(getLastPostIndex(['post2', 'post3', 'post4', START_OF_NEW_MESSAGES])).toBe(2);
});
});
Expand Down

0 comments on commit cc8a8c9

Please sign in to comment.