-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Curation] Add promoted/hidden documents section & logic + Restore defaults button #94769
Changes from all commits
303a281
1f2617c
df49b74
8788bb3
942cbe8
8ca1efe
f2b6446
b02a63e
b0ae5fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,10 @@ describe('CurationLogic', () => { | |
queriesLoading: false, | ||
activeQuery: '', | ||
organicDocumentsLoading: false, | ||
promotedIds: [], | ||
promotedDocumentsLoading: false, | ||
hiddenIds: [], | ||
hiddenDocumentsLoading: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
|
@@ -64,7 +68,7 @@ describe('CurationLogic', () => { | |
|
||
describe('actions', () => { | ||
describe('onCurationLoad', () => { | ||
it('should set curation, queries, activeQuery, & all loading states to false', () => { | ||
it('should set curation, queries, activeQuery, promotedIds, hiddenIds, & all loading states to false', () => { | ||
mount(); | ||
|
||
CurationLogic.actions.onCurationLoad(MOCK_CURATION_RESPONSE); | ||
|
@@ -74,9 +78,13 @@ describe('CurationLogic', () => { | |
curation: MOCK_CURATION_RESPONSE, | ||
queries: ['some search'], | ||
activeQuery: 'some search', | ||
promotedIds: ['some-promoted-document'], | ||
hiddenIds: ['some-hidden-document'], | ||
dataLoading: false, | ||
queriesLoading: false, | ||
organicDocumentsLoading: false, | ||
promotedDocumentsLoading: false, | ||
hiddenDocumentsLoading: false, | ||
}); | ||
}); | ||
|
||
|
@@ -95,6 +103,8 @@ describe('CurationLogic', () => { | |
dataLoading: true, | ||
queriesLoading: true, | ||
organicDocumentsLoading: true, | ||
promotedDocumentsLoading: true, | ||
hiddenDocumentsLoading: true, | ||
}); | ||
|
||
CurationLogic.actions.onCurationError(); | ||
|
@@ -104,6 +114,8 @@ describe('CurationLogic', () => { | |
dataLoading: false, | ||
queriesLoading: false, | ||
organicDocumentsLoading: false, | ||
promotedDocumentsLoading: false, | ||
hiddenDocumentsLoading: false, | ||
}); | ||
}); | ||
}); | ||
|
@@ -136,6 +148,121 @@ describe('CurationLogic', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('setPromotedIds', () => { | ||
it('should set promotedIds state & promotedDocumentsLoading to true', () => { | ||
mount(); | ||
|
||
CurationLogic.actions.setPromotedIds(['hello', 'world']); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
promotedIds: ['hello', 'world'], | ||
promotedDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('addPromotedId', () => { | ||
it('should set promotedIds state & promotedDocumentsLoading to true', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fairly certain you'll hate this, but thought it might be a cool way to dry up these tests.
const itShouldChangePromotedIdsState = (from, to, callback) => {
it('should set promotedIds state & promotedDocumentsLoading to true', () => {
mount({ promotedIds: from });
callback();
expect(CurationLogic.values).toEqual({
...DEFAULT_VALUES,
promotedIds: to,
promotedDocumentsLoading: true,
});
});
}
describe('addPromotedId', () => {
itShouldChangePromotedIdsState(['hello'], ['hello', 'world'], () => {
CurationLogic.actions.addPromotedId('world');
});
}
describe('setPromotedIds', () => {
itShouldChangePromotedIdsState([], ['hello', 'world'], () => {
CurationLogic.actions.addPromotedId(['hello', 'world']);
});
}
describe('removePromotedId', () => {
itShouldChangePromotedIdsState(['hello', 'deleteme', 'world'], ['hello', 'world'], () => {
CurationLogic.actions.removePromotedId('deleteme');
});
} Or some variant of that it('should set promotedIds state & promotedDocumentsLoading to true', () => {
expectAction(() => {
CurationLogic.actions.removePromotedId('deleteme');
}).toChangePromotedIds(
['hello', 'deleteme', 'world'],
['hello', 'world']
);
} Just riffing now, what if we had a generic "expectAction" we could use in specs: it('should set promotedIds state & promotedDocumentsLoading to true', () => {
expectAction(() => {
CurationLogic.actions.removePromotedId('deleteme');
}).toChangeState(
{
promotedIds: ['hello', 'deleteme', 'world'],
promotedDocumentsLoading: false
},
{
promotedIds: ['hello', 'world'],
promotedDocumentsLoading: true
}
);
} It would handle mounting with defaults, and then running expectations on values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your last iteration feels super readable/straightforward to me! I like that a lot and would be super open to changing that wholesale across our app. I'd have maybe one minor change request, which is changing the passed arg to an object and using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I should clarify - this isn't a change request for the this PR right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope |
||
mount({ promotedIds: ['hello'] }); | ||
|
||
CurationLogic.actions.addPromotedId('world'); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
promotedIds: ['hello', 'world'], | ||
promotedDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('removePromotedId', () => { | ||
it('should set promotedIds state & promotedDocumentsLoading to true', () => { | ||
mount({ promotedIds: ['hello', 'deleteme', 'world'] }); | ||
|
||
CurationLogic.actions.removePromotedId('deleteme'); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
promotedIds: ['hello', 'world'], | ||
promotedDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('clearPromotedId', () => { | ||
it('should reset promotedIds state & set promotedDocumentsLoading to true', () => { | ||
mount({ promotedIds: ['hello', 'world'] }); | ||
|
||
CurationLogic.actions.clearPromotedIds(); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
promotedIds: [], | ||
promotedDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('addHiddenId', () => { | ||
it('should set hiddenIds state & hiddenDocumentsLoading to true', () => { | ||
mount({ hiddenIds: ['hello'] }); | ||
|
||
CurationLogic.actions.addHiddenId('world'); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
hiddenIds: ['hello', 'world'], | ||
hiddenDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('removeHiddenId', () => { | ||
it('should set hiddenIds state & hiddenDocumentsLoading to true', () => { | ||
mount({ hiddenIds: ['hello', 'deleteme', 'world'] }); | ||
|
||
CurationLogic.actions.removeHiddenId('deleteme'); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
hiddenIds: ['hello', 'world'], | ||
hiddenDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('clearHiddenId', () => { | ||
it('should reset hiddenIds state & set hiddenDocumentsLoading to true', () => { | ||
mount({ hiddenIds: ['hello', 'world'] }); | ||
|
||
CurationLogic.actions.clearHiddenIds(); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
hiddenIds: [], | ||
hiddenDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('resetCuration', () => { | ||
it('should clear promotedIds & hiddenIds & set dataLoading to true', () => { | ||
mount({ promotedIds: ['hello'], hiddenIds: ['world'] }); | ||
|
||
CurationLogic.actions.resetCuration(); | ||
|
||
expect(CurationLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
dataLoading: true, | ||
promotedIds: [], | ||
promotedDocumentsLoading: true, | ||
hiddenIds: [], | ||
hiddenDocumentsLoading: true, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('listeners', () => { | ||
|
@@ -187,6 +314,8 @@ describe('CurationLogic', () => { | |
{ | ||
queries: ['a', 'b', 'c'], | ||
activeQuery: 'b', | ||
promotedIds: ['d', 'e', 'f'], | ||
hiddenIds: ['g'], | ||
}, | ||
{ curationId: 'cur-123456789' } | ||
); | ||
|
@@ -199,7 +328,7 @@ describe('CurationLogic', () => { | |
expect(http.put).toHaveBeenCalledWith( | ||
'/api/app_search/engines/some-engine/curations/cur-123456789', | ||
{ | ||
body: '{"queries":["a","b","c"],"query":"b","promoted":[],"hidden":[]}', // Uses state currently in CurationLogic | ||
body: '{"queries":["a","b","c"],"query":"b","promoted":["d","e","f"],"hidden":["g"]}', // Uses state currently in CurationLogic | ||
} | ||
); | ||
expect(CurationLogic.actions.onCurationLoad).toHaveBeenCalledWith(MOCK_CURATION_RESPONSE); | ||
|
@@ -249,6 +378,34 @@ describe('CurationLogic', () => { | |
it('setActiveQuery', () => { | ||
CurationLogic.actions.setActiveQuery('test'); | ||
}); | ||
|
||
it('setPromotedIds', () => { | ||
CurationLogic.actions.setPromotedIds(['test']); | ||
}); | ||
|
||
it('addPromotedId', () => { | ||
CurationLogic.actions.addPromotedId('test'); | ||
}); | ||
|
||
it('removePromotedId', () => { | ||
CurationLogic.actions.removePromotedId('test'); | ||
}); | ||
|
||
it('clearPromotedIds', () => { | ||
CurationLogic.actions.clearPromotedIds(); | ||
}); | ||
|
||
it('addHiddenId', () => { | ||
CurationLogic.actions.addHiddenId('test'); | ||
}); | ||
|
||
it('removeHiddenId', () => { | ||
CurationLogic.actions.removeHiddenId('test'); | ||
}); | ||
|
||
it('clearHiddenIds', () => { | ||
CurationLogic.actions.clearHiddenIds(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note - the actual listener assertion is being done in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhhh. That's super clever. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't take the credit haha, I think our rspec tests also do this a lot pattern-wise in our server-side code :) |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the
Restore defaults
button in 3-4 different views in App Search, so I'm hoping to pull this out to a shared i18n constants file soon (alongside other reusable actions such as Edit, Save, etc.)