Skip to content

Fix Server-side filtering on challenge listings #2339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions __tests__/shared/actions/challenge-listing/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sidebarActions from 'actions/challenge-listing/sidebar';

const actions = sidebarActions.challengeListing.sidebar;
const actions = sidebarActions.challengeListingFrontend.sidebar;

const mockFetch = (ok, resolvesTo) => jest.fn(
() => Promise.resolve({ ok, json: () => resolvesTo }),
Expand All @@ -17,11 +17,11 @@ afterAll(() => {
jest.clearAllMocks();
});

describe('challengeListing.sidebar.changeFilterName', () => {
describe('challengeListingFront.sidebar.changeFilterName', () => {
const a = actions.changeFilterName('index', 'name');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/CHANGE_FILTER_NAME');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/CHANGE_FILTER_NAME');
});

test('payload is expected object', () => expect(a.payload).toEqual({
Expand All @@ -30,126 +30,126 @@ describe('challengeListing.sidebar.changeFilterName', () => {
}));
});

describe('challengeListing.sidebar.deleteSavedFilter', () => {
describe('challengeListingFrontend.sidebar.deleteSavedFilter', () => {
global.fetch = mockFetch(true, 'dummy');

const a = actions.deleteSavedFilter('id', 'token');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/DELETE_SAVED_FILTER');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/DELETE_SAVED_FILTER');
});

test('payload is a promise which resolves to the expected object', () => a.payload.then(res => expect(res).toEqual('id')));
});

describe('challengeListing.sidebar.dragSavedFilterMove', () => {
describe('challengeListingFrontend.sidebar.dragSavedFilterMove', () => {
const a = actions.dragSavedFilterMove(
{ target: { offsetHeight: 10 } },
{ y: 0, startIndex: 0, index: 10 },
);

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
});

test('payload is expected object', () => expect(a.payload).toEqual({ y: 0, startIndex: 0, index: 10 }));
});

describe('challengeListing.sidebar.dragSavedFilterMove with screenY', () => {
describe('challengeListingFrontend.sidebar.dragSavedFilterMove with screenY', () => {
const a = actions.dragSavedFilterMove(
{ screenY: 10, target: { offsetHeight: 10 } },
{ y: 0, startIndex: 0, index: 10 },
);

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
});

test('payload is expected object', () => expect(a.payload).toEqual({
y: 0, startIndex: 0, index: 10, currentIndex: 1,
}));
});

describe('challengeListing.sidebar.dragSavedFilterMove same index', () => {
describe('challengeListingFrontend.sidebar.dragSavedFilterMove same index', () => {
const a = actions.dragSavedFilterMove(
{ screenY: 10, target: { offsetHeight: 10 } },
{ y: 0, startIndex: 9, index: 10 },
);

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/DRAG_SAVED_FILTER_MOVE');
});

test('payload is expected object', () => expect(a.payload).toEqual({ y: 0, startIndex: 9, index: 10 }));
});

describe('challengeListing.sidebar.dragSavedFilterStart', () => {
describe('challengeListingFrontend.sidebar.dragSavedFilterStart', () => {
const a = actions.dragSavedFilterStart(10, { screenY: 5 });

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_START');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/DRAG_SAVED_FILTER_START');
});

test('payload is expected object', () => expect(a.payload).toEqual({ y: 5, startIndex: 10, currentIndex: 10 }));
});

describe('challengeListing.sidebar.getSavedFilters', () => {
describe('challengeListingFrontend.sidebar.getSavedFilters', () => {
global.fetch = mockFetch(true, []);

const a = actions.getSavedFilters('id', 'token');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/GET_SAVED_FILTERS');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/GET_SAVED_FILTERS');
});

// FIXME: Broken in topcoder-react-lib v0.3.0
// test('payload is a promise which resolves to the expected object', () =>
// a.payload.then(res => expect(res).toEqual([])));
});

describe('challengeListing.sidebar.resetFilterName', () => {
describe('challengeListingFrontend.sidebar.resetFilterName', () => {
const a = actions.resetFilterName(1);

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/RESET_FILTER_NAME');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/RESET_FILTER_NAME');
});

test('payload is expected object', () => expect(a.payload).toEqual(1));
});

describe('challengeListing.sidebar.saveFilter', () => {
describe('challengeListingFrontend.sidebar.saveFilter', () => {
global.fetch = mockFetch(true, 'dummy');

const a = actions.saveFilterDone('name', {}, 'token');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/SAVE_FILTER_DONE');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/SAVE_FILTER_DONE');
});

// FIXME: Broken in topcoder-react-lib v0.3.0
// test('payload is a promise which resolves to the expected object', () =>
// a.payload.then(res => expect(res).toEqual('dummy')));
});

describe('challengeListing.sidebar.updateAllSavedFilters', () => {
describe('challengeListingFrontend.sidebar.updateAllSavedFilters', () => {
global.fetch = mockFetch(true, 'dummy');

const a = actions.updateAllSavedFilters([{ filter: {} }], 'token');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/UPDATE_ALL_SAVED_FILTERS');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/UPDATE_ALL_SAVED_FILTERS');
});

test('payload is undefined', () => expect(a.payload).toBeUndefined());
});

describe('challengeListing.sidebar.updateSavedFilter', () => {
describe('challengeListingFrontend.sidebar.updateSavedFilter', () => {
global.fetch = mockFetch(true, 'dummy');

const a = actions.updateSavedFilter({}, 'token');

test('has expected type', () => {
expect(a.type).toBe('CHALLENGE_LISTING/SIDEBAR/UPDATE_SAVED_FILTER');
expect(a.type).toBe('CHALLENGE_LISTING_FRONTEND/SIDEBAR/UPDATE_SAVED_FILTER');
});

// FIXME: Broken in topcoder-react-lib v0.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`Matches shallow shapshot 1`] = `
displayFormat="MMM DD, YYYY"
enableOutsideDays={false}
endDate={null}
endDateId="date-range-picker-two-month"
endDatePlaceholderText="End Date"
firstDayOfWeek={null}
focusedInput={null}
Expand Down Expand Up @@ -89,6 +90,7 @@ exports[`Matches shallow shapshot 1`] = `
showDefaultInputIcon={false}
small={false}
startDate={null}
startDateId="date-range-picker-one-month"
startDatePlaceholderText="Start Date"
verticalHeight={null}
verticalSpacing={22}
Expand Down
Loading