fix query for go to reply

fixes VICE-2028
flag=isolated_view

Basically 2 issues:
1) we need to pass the parent entry of a reply.
 Non legacy will always be rootEntry. But for legacy
 it could be parent or root. Its safer to check if
 root present (thus its a child), then pass parent or root.

2) root || entry
 give preference to root.
 we need to give preference to entry.

Test Plan:
1) Create a deeply nested entry.
1a.) To do this turn off isolated view and discussion_design
 feature flags.
1b.) Then create your entries
1b.) See the ticket for more details if needed.
2) search for the entry with search input.
3) Click go to reply should not break and should work.
4) Work means: entry will be in thread and parent will
 be the IsolateParent.

Change-Id: If9530418c00804a88540f4652e1fa690f3711f46
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/272955
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com>
QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
This commit is contained in:
Chawn Neal 2021-09-03 22:48:15 -05:00
parent e46a98e923
commit 8e1afe6078
3 changed files with 47 additions and 18 deletions

View File

@ -84,7 +84,7 @@ const DiscussionTopicManager = props => {
}, [highlightEntryId])
const openIsolatedView = (discussionEntryId, rootEntryId, withRCE, relativeId = null) => {
setIsolatedEntryId(rootEntryId || discussionEntryId)
setIsolatedEntryId(discussionEntryId || rootEntryId)
setReplyId(discussionEntryId)
setIsolatedViewOpen(true)
setEditorExpanded(withRCE)

View File

@ -54,7 +54,7 @@ export function ThreadingToolbar({...props}) {
data-testid="go-to-reply"
onClick={() => {
const isolatedId = props.discussionEntry.rootEntryId
? props.discussionEntry.rootEntryId
? props.discussionEntry.parentId || props.discussionEntry.rootEntryId
: props.discussionEntry._id
const relativeId = props.discussionEntry.rootEntryId
? props.discussionEntry._id

View File

@ -91,23 +91,52 @@ describe('PostToolbar', () => {
expect(queryByText('Go to Reply')).toBeNull()
})
it('calls the onOpenIsolatedView callback with the root entry id', async () => {
window.ENV.isolated_view = true
const onOpenIsolatedView = jest.fn()
const container = render(
<ThreadingToolbar
discussionEntry={DiscussionEntry.mock({
id: '1',
_id: '1',
rootEntryId: '2'
})}
searchTerm="neato"
onOpenIsolatedView={onOpenIsolatedView}
/>
)
describe('when rootEntryId is present', () => {
it('calls the onOpenIsolatedView callback with the parent entry id', async () => {
window.ENV.isolated_view = true
const onOpenIsolatedView = jest.fn()
const container = render(
<ThreadingToolbar
discussionEntry={DiscussionEntry.mock({
id: '1',
_id: '1',
rootEntryId: '2',
parentId: '3'
})}
searchTerm="neato"
onOpenIsolatedView={onOpenIsolatedView}
/>
)
fireEvent.click(container.getByText('Go to Reply'))
await waitFor(() => expect(onOpenIsolatedView).toHaveBeenCalledWith('2', '2', false, '1', '1'))
fireEvent.click(container.getByText('Go to Reply'))
await waitFor(() =>
expect(onOpenIsolatedView).toHaveBeenCalledWith('3', '2', false, '1', '1')
)
})
})
describe('when rootEntryId is not present', () => {
it('calls the onOpenIsolatedView callback with the entry id', async () => {
window.ENV.isolated_view = true
const onOpenIsolatedView = jest.fn()
const container = render(
<ThreadingToolbar
discussionEntry={DiscussionEntry.mock({
id: '1',
_id: '1',
rootEntryId: null,
parentId: null
})}
searchTerm="neato"
onOpenIsolatedView={onOpenIsolatedView}
/>
)
fireEvent.click(container.getByText('Go to Reply'))
await waitFor(() =>
expect(onOpenIsolatedView).toHaveBeenCalledWith('1', null, false, null, '1')
)
})
})
it('calls the onOpenIsolatedView callback with its own id if it is a root entry', async () => {