From c9fa6d29de5ac413e85936c9b6150dce4d417fab Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Tue, 21 Jan 2020 23:17:10 -0500 Subject: [PATCH 01/12] Add featured programs list --- src/actions/program.js | 6 ++++++ src/components/ProgramList.js | 34 ++++++++++++++++++++++++++++++++++ src/reducers/program.js | 21 +++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/actions/program.js b/src/actions/program.js index 5ff0b74a..39513ed5 100644 --- a/src/actions/program.js +++ b/src/actions/program.js @@ -11,6 +11,10 @@ export const FETCH_USER_PROGRAMS = 'FETCH_USER_PROGRAMS'; export const FETCH_USER_PROGRAMS_PENDING = `${FETCH_USER_PROGRAMS}_PENDING`; export const FETCH_USER_PROGRAMS_FULFILLED = `${FETCH_USER_PROGRAMS}_FULFILLED`; export const FETCH_USER_PROGRAMS_REJECTED = `${FETCH_USER_PROGRAMS}_REJECTED`; +export const FETCH_FEATURED_PROGRAMS = 'FETCH_FEATURED_PROGRAMS'; +export const FETCH_FEATURED_PROGRAMS_PENDING = `${FETCH_FEATURED_PROGRAMS}_PENDING`; +export const FETCH_FEATURED_PROGRAMS_FULFILLED = `${FETCH_FEATURED_PROGRAMS}_FULFILLED`; +export const FETCH_FEATURED_PROGRAMS_REJECTED = `${FETCH_FEATURED_PROGRAMS}_REJECTED`; export const REMOVE_PROGRAM = 'REMOVE_PROGRAM'; export const REMOVE_PROGRAM_PENDING = `${REMOVE_PROGRAM}_PENDING`; export const REMOVE_PROGRAM_FULFILLED = `${REMOVE_PROGRAM}_FULFILLED`; @@ -22,6 +26,8 @@ export const fetchPrograms = (xhrOptions) => { if (xhrOptions && xhrOptions.params && xhrOptions.params.user) { type = FETCH_USER_PROGRAMS; + } else if (xhrOptions && xhrOptions.params && xhrOptions.params.admin_tags) { + type = FETCH_FEATURED_PROGRAMS; } return ({ diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index 033c46f7..ef2b8ffa 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -42,6 +42,8 @@ class ProgramList extends Component { user: user.user_id, }).then(() => fetchPrograms({ user__not: user.user_id, + })).then(() => fetchPrograms({ + admin_tags: "featured", })).then(() => fetchTags()); } @@ -123,6 +125,7 @@ class ProgramList extends Component { programs, tag, userPrograms, + featuredPrograms, } = this.props; const { confirmOpen, @@ -136,6 +139,12 @@ class ProgramList extends Component { defaultMessage: 'My Programs', }); + const featuredProgramsHeader = intl.formatMessage({ + id: 'app.program_list.featured_programs', + description: 'Header for all featured programs', + defaultMessage: 'Featured Programs', + }); + const otherProgramsHeader = intl.formatMessage({ id: 'app.program_list.other_programs', description: 'Header for finding other user\'s programs', @@ -191,6 +200,11 @@ class ProgramList extends Component { ? () : this.programSegment(userPrograms, tag, myProgramsHeader, true) } + { + featuredPrograms === null + ? () + : this.programSegment(featuredPrograms, tag, featuredProgramsHeader, true) + } { programs === null ? () @@ -223,6 +237,12 @@ ProgramList.defaultProps = { total_pages: 1, results: [], }, + featuredPrograms: { + next: null, + previous: null, + total_pages: 1, + results: [], + }, tag: { tags: [], }, @@ -266,6 +286,20 @@ ProgramList.propTypes = { }), ), }), + featuredPrograms: PropTypes.shape({ + next: PropTypes.string, + previous: PropTypes.string, + total_pages: PropTypes.number, + results: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + name: PropTypes.string.isRequired, + user: PropTypes.shape({ + username: PropTypes.string.isRequired, + }).isRequired, + }), + ), + }), tag: PropTypes.shape({ tags: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string, diff --git a/src/reducers/program.js b/src/reducers/program.js index ad3f640f..eb0ed30d 100644 --- a/src/reducers/program.js +++ b/src/reducers/program.js @@ -5,6 +5,9 @@ import { FETCH_USER_PROGRAMS_PENDING, FETCH_USER_PROGRAMS_FULFILLED, FETCH_USER_PROGRAMS_REJECTED, + FETCH_FEATURED_PROGRAMS_PENDING, + FETCH_FEATURED_PROGRAMS_FULFILLED, + FETCH_FEATURED_PROGRAMS_REJECTED, REMOVE_PROGRAM_PENDING, REMOVE_PROGRAM_FULFILLED, REMOVE_PROGRAM_REJECTED, @@ -33,6 +36,11 @@ export default function programs( ...state, userProgramsIsFetching: true, }; + case FETCH_FEATURED_PROGRAMS_PENDING: + return { + ...state, + featuredProgramsIsFetching: true, + }; case FETCH_PROGRAMS_FULFILLED: return { ...state, @@ -47,6 +55,13 @@ export default function programs( userPrograms: action.payload, userProgramsError: null, }; + case FETCH_FEATURED_PROGRAMS_FULFILLED: + return { + ...state, + featuredProgramsIsFetching: false, + featuredPrograms: action.payload, + featuredProgramsError: null, + }; case FETCH_PROGRAMS_REJECTED: return { ...state, @@ -59,6 +74,12 @@ export default function programs( userProgramsIsFetching: false, userProgramsError: action.payload, }; + case FETCH_FEATURED_PROGRAMS_REJECTED: + return { + ...state, + featuredProgramsIsFetching: false, + featuredProgramsError: action.payload, + }; case REMOVE_PROGRAM_PENDING: return { ...state, From 3d2098aebfbbbb835eea21775e02cbd6522f360f Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 18:52:49 -0500 Subject: [PATCH 02/12] Show featured programs as not your own --- src/components/ProgramList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index ef2b8ffa..432eaa0d 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -203,7 +203,7 @@ class ProgramList extends Component { { featuredPrograms === null ? () - : this.programSegment(featuredPrograms, tag, featuredProgramsHeader, true) + : this.programSegment(featuredPrograms, tag, featuredProgramsHeader, false) } { programs === null From 396dc4de95082dbb5edfde052ce302e96efd50c4 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 20:05:05 -0500 Subject: [PATCH 03/12] dd featured program tests --- src/actions/__test__/program.test.js | 28 ++++++++++ src/components/ProgramList.js | 2 +- src/components/__tests__/ProgramList.test.js | 27 ++++++++-- .../__snapshots__/ProgramList.test.js.snap | 29 ++++++++++ src/reducers/__tests__/program.test.js | 53 +++++++++++++++++++ src/reducers/program.js | 3 ++ 6 files changed, 137 insertions(+), 5 deletions(-) diff --git a/src/actions/__test__/program.test.js b/src/actions/__test__/program.test.js index bab5f97a..a7bafe9f 100644 --- a/src/actions/__test__/program.test.js +++ b/src/actions/__test__/program.test.js @@ -52,6 +52,34 @@ describe('Program actions', () => { mock.restore(); }); + test('fetch featured programs', async () => { + const mock = new MockAdapter(axios); + const programs = [{ + id: 33, + name: 'Unnamed_Design_3', + content: '', + admin_tags: ['featured'], + }]; + + mock.onGet('/api/v1/block-diagrams/', { + params: { + admin_tags: ['featured'], + }, + }).reply(200, programs); + + const action = fetchPrograms({ + params: { + admin_tags: ['featured'], + }, + }); + const { type } = action; + const payload = await action.payload; + + expect(type).toEqual('FETCH_FEATURED_PROGRAMS'); + expect(payload).toEqual(programs); + mock.restore(); + }); + test('remove program', async () => { const mock = new MockAdapter(axios); diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index 432eaa0d..7704c507 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -43,7 +43,7 @@ class ProgramList extends Component { }).then(() => fetchPrograms({ user__not: user.user_id, })).then(() => fetchPrograms({ - admin_tags: "featured", + admin_tags: 'featured', })).then(() => fetchTags()); } diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index 3821d4d1..59e9d817 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -98,7 +98,7 @@ describe('The ProgramList component', () => { ).dive(); expect(wrapper.find(ProgramCollection).exists()).toBe(true); - expect(wrapper.find(ProgramCollection).length).toBe(2); + expect(wrapper.find(ProgramCollection).length).toBe(3); expect(wrapper.find(Loader).exists()).toBe(false); }); @@ -117,7 +117,7 @@ describe('The ProgramList component', () => { ).dive(); expect(wrapper.find(ProgramCollection).exists()).toBe(true); - expect(wrapper.find(ProgramCollection).length).toBe(1); + expect(wrapper.find(ProgramCollection).length).toBe(2); expect(wrapper.find(Loader).exists()).toBe(true); }); @@ -136,7 +136,26 @@ describe('The ProgramList component', () => { ).dive(); expect(wrapper.find(ProgramCollection).exists()).toBe(true); - expect(wrapper.find(ProgramCollection).length).toBe(1); + expect(wrapper.find(ProgramCollection).length).toBe(2); + expect(wrapper.find(Loader).exists()).toBe(true); + }); + + test('shows loading when featured programs fetching', () => { + const wrapper = shallowWithIntl( + , + ).dive(); + + expect(wrapper.find(ProgramCollection).exists()).toBe(true); + expect(wrapper.find(ProgramCollection).length).toBe(2); expect(wrapper.find(Loader).exists()).toBe(true); }); @@ -413,7 +432,7 @@ describe('The ProgramList component', () => { }); await wrapper.instance().removeProgram(); - expect(fetchPrograms).toHaveBeenCalledTimes(4); + expect(fetchPrograms).toHaveBeenCalledTimes(5); expect(removeProgram).toHaveBeenCalledWith(33); }); diff --git a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap index 273d67a5..b4779451 100644 --- a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap +++ b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap @@ -64,6 +64,35 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` } /> + + + { userProgramsIsFetching: false, userProgramsError: null, userPrograms: null, + featuredProgramsIsFetching: false, + featuredProgramsError: null, + featuredPrograms: null, isRemoving: false, }); @@ -62,6 +68,9 @@ describe('The program reducer', () => { userProgramsIsFetching: true, userProgramsError: null, userPrograms: null, + featuredProgramsIsFetching: false, + featuredProgramsError: null, + featuredPrograms: null, isRemoving: false, }); @@ -88,6 +97,47 @@ describe('The program reducer', () => { userProgramsIsFetching: false, }); }); + test('should handle FETCH_FEATURED_PROGRAMS_PENDING', () => { + expect( + reducer(undefined, { + type: FETCH_FEATURED_PROGRAMS_PENDING, + }), + ).toEqual({ + programsIsFetching: false, + programsError: null, + programs: null, + userProgramsIsFetching: false, + userProgramsError: null, + userPrograms: null, + featuredProgramsIsFetching: true, + featuredProgramsError: null, + featuredPrograms: null, + isRemoving: false, + }); + + const featuredPrograms = []; + expect( + reducer({}, { + type: FETCH_FEATURED_PROGRAMS_FULFILLED, + payload: featuredPrograms, + }), + ).toEqual({ + featuredPrograms, + featuredProgramsIsFetching: false, + featuredProgramsError: null, + }); + + const featuredProgramsError = 'woops'; + expect( + reducer({}, { + type: FETCH_FEATURED_PROGRAMS_REJECTED, + payload: featuredProgramsError, + }), + ).toEqual({ + featuredProgramsError, + featuredProgramsIsFetching: false, + }); + }); test('should handle REMOVE_PROGRAM_PENDING', () => { expect( reducer(undefined, { @@ -100,6 +150,9 @@ describe('The program reducer', () => { userProgramsIsFetching: false, userProgramsError: null, userPrograms: null, + featuredProgramsIsFetching: false, + featuredProgramsError: null, + featuredPrograms: null, isRemoving: true, }); diff --git a/src/reducers/program.js b/src/reducers/program.js index eb0ed30d..fd69143c 100644 --- a/src/reducers/program.js +++ b/src/reducers/program.js @@ -17,11 +17,14 @@ export default function programs( state = { programsIsFetching: false, userProgramsIsFetching: false, + featuredProgramsIsFetching: false, isRemoving: false, programs: null, userPrograms: null, + featuredPrograms: null, programsError: null, userProgramsError: null, + featuredProgramsError: null, }, action, ) { From 29b4f36bb24836197bb8a490ff76d0e82e947668 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 21:18:24 -0500 Subject: [PATCH 04/12] Allow mixed program lists --- src/components/ProgramCollection.js | 25 +++++++++----- src/components/ProgramList.js | 51 +++++++++++++++++++---------- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/components/ProgramCollection.js b/src/components/ProgramCollection.js index c5df582b..e10e1cb0 100644 --- a/src/components/ProgramCollection.js +++ b/src/components/ProgramCollection.js @@ -27,7 +27,7 @@ class ProgramCollection extends Component { } update = () => { - const { onUpdate, owned } = this.props; + const { onUpdate } = this.props; const { page, ordering, @@ -45,7 +45,7 @@ class ProgramCollection extends Component { params.search = searchQuery; } - onUpdate(params, owned); + onUpdate(params); } toggleOrdering = (name) => { @@ -81,11 +81,11 @@ class ProgramCollection extends Component { render() { const { + user, label, onProgramClick, onRemoveClick, programs, - owned, intl, tag, } = this.props; @@ -182,7 +182,7 @@ class ProgramCollection extends Component { { - owned ? ( + user.username === program.user.username ? ( - - diff --git a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap index b4779451..6990a21b 100644 --- a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap +++ b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap @@ -48,7 +48,6 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` onProgramClick={[Function]} onRemoveClick={[Function]} onUpdate={[Function]} - owned={true} programs={ Object { "next": null, @@ -62,6 +61,11 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` "tags": Array [], } } + user={ + Object { + "user_id": 1, + } + } /> Date: Thu, 23 Jan 2020 21:57:30 -0500 Subject: [PATCH 06/12] Fix coverage hole in ProgramList test --- src/components/ProgramList.js | 2 +- src/components/__tests__/ProgramList.test.js | 77 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index fa611e2d..90289ab9 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -103,7 +103,7 @@ class ProgramList extends Component { fetchFeaturedPrograms = (params) => { const { fetchPrograms } = this.props; fetchPrograms({ - admin_tags: 'featured', + admin_tags: ['featured'], ...params, }); } diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index 40dd10a4..ed053520 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -282,6 +282,43 @@ describe('The ProgramList component', () => { }); }); + test('fetches featured programs after page change', async () => { + const programs = { + next: null, + previous: null, + total_pages: 1, + results: [{ + id: 33, + name: 'Unnamed_Design_3', + content: '', + user: { + username: 'admin', + }, + }], + }; + const wrapper = shallowWithIntl( + , + ).dive(); + + await wrapper.instance().fetchFeaturedPrograms({ + page: 2, + }, false); + + expect(fetchPrograms).toHaveBeenCalledWith({ + admin_tags: ['featured'], + page: 2, + }); + }); + test('fetches other programs after page change', async () => { const programs = { next: null, @@ -358,6 +395,46 @@ describe('The ProgramList component', () => { }); }); + test('fetches featured programs after search change', () => { + const programs = { + next: null, + previous: null, + total_pages: 1, + results: [{ + id: 33, + name: 'Unnamed_Design_3', + content: '', + user: { + username: 'admin', + }, + }], + }; + const wrapper = shallowWithIntl( + , + ).dive(); + + wrapper.instance().fetchFeaturedPrograms({ + search: 'abc', + page: 1, + }, false); + + expect(fetchPrograms).toHaveBeenCalledWith({ + admin_tags: ['featured'], + page: 1, + search: 'abc', + }); + }); + + test('fetches other programs after search change', () => { const programs = { next: null, From 753a71cc4bc42bd4dda2f97b6a3babae1edf2c53 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 22:31:58 -0500 Subject: [PATCH 07/12] Fix ProgramCollection and ProgramList tests --- src/components/ProgramCollection.js | 1 - .../__tests__/ProgramCollection.test.js | 12 +++---- src/components/__tests__/ProgramList.test.js | 34 +++++++++---------- .../__snapshots__/ProgramList.test.js.snap | 3 ++ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/components/ProgramCollection.js b/src/components/ProgramCollection.js index e10e1cb0..65403411 100644 --- a/src/components/ProgramCollection.js +++ b/src/components/ProgramCollection.js @@ -263,7 +263,6 @@ ProgramCollection.defaultProps = { ProgramCollection.propTypes = { user: PropTypes.shape({ - user_id: PropTypes.number.isRequired, username: PropTypes.string.isRequired, }).isRequired, programs: PropTypes.shape({ diff --git a/src/components/__tests__/ProgramCollection.test.js b/src/components/__tests__/ProgramCollection.test.js index a9b349c2..52560428 100644 --- a/src/components/__tests__/ProgramCollection.test.js +++ b/src/components/__tests__/ProgramCollection.test.js @@ -255,7 +255,7 @@ describe('The ProgramCollection component', () => { page: 2, ordering: 'name', tag: '', - }, true); + }); }); test('callback when search changes', () => { @@ -301,7 +301,7 @@ describe('The ProgramCollection component', () => { page: 1, ordering: 'name', tag: '', - }, true); + }); }); test('callback when order changes', () => { @@ -344,7 +344,7 @@ describe('The ProgramCollection component', () => { page: 1, ordering: '-name', tag: '', - }, true); + }); wrapper.find({ name: 'name' }).simulate('click', null, { name: 'name', @@ -354,7 +354,7 @@ describe('The ProgramCollection component', () => { page: 1, ordering: 'name', tag: '', - }, true); + }); wrapper.instance().handleOrderingChange(null, { name: 'field_name', @@ -364,7 +364,7 @@ describe('The ProgramCollection component', () => { page: 1, ordering: 'field_name', tag: '', - }, true); + }); }); test('callback when tag changes', () => { @@ -418,6 +418,6 @@ describe('The ProgramCollection component', () => { page: 1, ordering: 'name', tag: 'tag1,tag2', - }, true); + }); }); }); diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index ed053520..f04f3f36 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -32,7 +32,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); wrapper.setState({ @@ -54,7 +54,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} /> , ); @@ -93,7 +93,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -111,7 +111,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} programs={null} />, ).dive(); @@ -130,7 +130,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} userPrograms={null} />, ).dive(); @@ -149,7 +149,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} featuredPrograms={null} />, ).dive(); @@ -168,7 +168,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -205,7 +205,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -268,7 +268,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -305,7 +305,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -342,7 +342,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -379,7 +379,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -418,7 +418,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -458,7 +458,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -497,7 +497,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -522,7 +522,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); @@ -548,7 +548,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 }} + user={{ user_id: 1 , username: 'testuser'}} />, ).dive(); diff --git a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap index 6990a21b..32f29cdf 100644 --- a/src/components/__tests__/__snapshots__/ProgramList.test.js.snap +++ b/src/components/__tests__/__snapshots__/ProgramList.test.js.snap @@ -64,6 +64,7 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` user={ Object { "user_id": 1, + "username": "testuser", } } /> @@ -97,6 +98,7 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` user={ Object { "user_id": 1, + "username": "testuser", } } /> @@ -130,6 +132,7 @@ exports[`The ProgramList component renders on the page with no errors 1`] = ` user={ Object { "user_id": 1, + "username": "testuser", } } /> From a44e29bac51c1f6b3f1a62b9b1d9ad01c22c95df Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 22:32:39 -0500 Subject: [PATCH 08/12] Update strings for featured programs --- src/translations/locales/en.json | 1 + src/translations/locales/es.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/translations/locales/en.json b/src/translations/locales/en.json index db2d0a28..7714c705 100644 --- a/src/translations/locales/en.json +++ b/src/translations/locales/en.json @@ -55,6 +55,7 @@ "app.program_list.confirm": "Yes", "app.program_list.dialog_content": "Are you sure you want to remove {name}?", "app.program_list.dialog_header": "Remove Program", + "app.program_list.featured_programs": "Featured Programs", "app.program_list.my_programs": "My Programs", "app.program_list.new": "New Program", "app.program_list.other_programs": "Find More", diff --git a/src/translations/locales/es.json b/src/translations/locales/es.json index 9d6b7d3f..d18cd078 100644 --- a/src/translations/locales/es.json +++ b/src/translations/locales/es.json @@ -55,6 +55,7 @@ "app.program_list.confirm": "Sí", "app.program_list.dialog_content": "¿Estás seguro de que quieres eliminar {name}?", "app.program_list.dialog_header": "Quitar Program", + "app.program_list.featured_programs": "Featured Programs", "app.program_list.my_programs": "Mis Programas", "app.program_list.new": "Programa Nuevo", "app.program_list.other_programs": "Encontrar Mas", From d37fd4e0b768de06ce0ad8320c08cd0da5e81183 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 22:43:02 -0500 Subject: [PATCH 09/12] Fix bug with admin_tag array --- src/components/ProgramList.js | 2 +- .../__tests__/ProgramCollection.test.js | 4 +- src/components/__tests__/ProgramList.test.js | 38 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index 90289ab9..fa611e2d 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -103,7 +103,7 @@ class ProgramList extends Component { fetchFeaturedPrograms = (params) => { const { fetchPrograms } = this.props; fetchPrograms({ - admin_tags: ['featured'], + admin_tags: 'featured', ...params, }); } diff --git a/src/components/__tests__/ProgramCollection.test.js b/src/components/__tests__/ProgramCollection.test.js index 52560428..1d3e426f 100644 --- a/src/components/__tests__/ProgramCollection.test.js +++ b/src/components/__tests__/ProgramCollection.test.js @@ -22,8 +22,8 @@ describe('The ProgramCollection component', () => { onProgramClick = jest.fn(); onRemoveClick = jest.fn(); onUpdate = jest.fn(); - adminUser = {username : 'admin'}; - testUser = {username : 'testuser'}; + adminUser = { username: 'admin' }; + testUser = { username: 'testuser' }; }); test('renders on the page with no errors', () => { diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index f04f3f36..2a598913 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -32,7 +32,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); wrapper.setState({ @@ -54,7 +54,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} /> , ); @@ -93,7 +93,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -111,7 +111,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} programs={null} />, ).dive(); @@ -130,7 +130,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} userPrograms={null} />, ).dive(); @@ -149,7 +149,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} featuredPrograms={null} />, ).dive(); @@ -168,7 +168,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -205,7 +205,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -268,7 +268,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -305,7 +305,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -314,7 +314,7 @@ describe('The ProgramList component', () => { }, false); expect(fetchPrograms).toHaveBeenCalledWith({ - admin_tags: ['featured'], + admin_tags: 'featured', page: 2, }); }); @@ -342,7 +342,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -379,7 +379,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -418,7 +418,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -428,7 +428,7 @@ describe('The ProgramList component', () => { }, false); expect(fetchPrograms).toHaveBeenCalledWith({ - admin_tags: ['featured'], + admin_tags: 'featured', page: 1, search: 'abc', }); @@ -458,7 +458,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -497,7 +497,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -522,7 +522,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); @@ -548,7 +548,7 @@ describe('The ProgramList component', () => { removeProgram={removeProgram} fetchTags={fetchTags} clearProgram={clearProgram} - user={{ user_id: 1 , username: 'testuser'}} + user={{ user_id: 1, username: 'testuser' }} />, ).dive(); From 4969c8f0a7d33f65a5ff5870631b06222cfba303 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 22:56:28 -0500 Subject: [PATCH 10/12] Only re-fetch user's programs on delete --- src/components/ProgramList.js | 6 ------ src/components/__tests__/ProgramList.test.js | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index fa611e2d..cdb1786f 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -66,12 +66,6 @@ class ProgramList extends Component { return removeProgram(focusProgram.id) .then(() => fetchPrograms({ user: user.user_id, - })) - .then(() => fetchPrograms({ - user__not: user.user_id, - })) - .then(() => fetchPrograms({ - admin_tags: 'featured', })); } diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index 2a598913..75156b1f 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -509,7 +509,7 @@ describe('The ProgramList component', () => { }); await wrapper.instance().removeProgram(); - expect(fetchPrograms).toHaveBeenCalledTimes(6); + expect(fetchPrograms).toHaveBeenCalledTimes(4); expect(removeProgram).toHaveBeenCalledWith(33); }); From 9b8a6ed0096d13a8f379fcecfa3d7193292a153e Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 22:58:43 -0500 Subject: [PATCH 11/12] Revert "Only re-fetch user's programs on delete" This reverts commit 4969c8f0a7d33f65a5ff5870631b06222cfba303. --- src/components/ProgramList.js | 6 ++++++ src/components/__tests__/ProgramList.test.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ProgramList.js b/src/components/ProgramList.js index cdb1786f..fa611e2d 100644 --- a/src/components/ProgramList.js +++ b/src/components/ProgramList.js @@ -66,6 +66,12 @@ class ProgramList extends Component { return removeProgram(focusProgram.id) .then(() => fetchPrograms({ user: user.user_id, + })) + .then(() => fetchPrograms({ + user__not: user.user_id, + })) + .then(() => fetchPrograms({ + admin_tags: 'featured', })); } diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index 75156b1f..2a598913 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -509,7 +509,7 @@ describe('The ProgramList component', () => { }); await wrapper.instance().removeProgram(); - expect(fetchPrograms).toHaveBeenCalledTimes(4); + expect(fetchPrograms).toHaveBeenCalledTimes(6); expect(removeProgram).toHaveBeenCalledWith(33); }); From 26d84f7cb6407c4c1e6d9e3eb1682b133950ac18 Mon Sep 17 00:00:00 2001 From: Brady Hurlburt Date: Thu, 23 Jan 2020 23:06:06 -0500 Subject: [PATCH 12/12] Check for only one loader --- src/components/__tests__/ProgramList.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/__tests__/ProgramList.test.js b/src/components/__tests__/ProgramList.test.js index 2a598913..b5620385 100644 --- a/src/components/__tests__/ProgramList.test.js +++ b/src/components/__tests__/ProgramList.test.js @@ -119,6 +119,7 @@ describe('The ProgramList component', () => { expect(wrapper.find(ProgramCollection).exists()).toBe(true); expect(wrapper.find(ProgramCollection).length).toBe(2); expect(wrapper.find(Loader).exists()).toBe(true); + expect(wrapper.find(Loader).length).toBe(1); }); test('shows loading when user programs fetching', () => { @@ -138,6 +139,7 @@ describe('The ProgramList component', () => { expect(wrapper.find(ProgramCollection).exists()).toBe(true); expect(wrapper.find(ProgramCollection).length).toBe(2); expect(wrapper.find(Loader).exists()).toBe(true); + expect(wrapper.find(Loader).length).toBe(1); }); test('shows loading when featured programs fetching', () => { @@ -157,6 +159,7 @@ describe('The ProgramList component', () => { expect(wrapper.find(ProgramCollection).exists()).toBe(true); expect(wrapper.find(ProgramCollection).length).toBe(2); expect(wrapper.find(Loader).exists()).toBe(true); + expect(wrapper.find(Loader).length).toBe(1); }); test('redirects to mission control when program loads', () => {