Fixes download filtered submissions: don't reset state on modal hide#1309
Conversation
aa3f0dc to
2bfa4ac
Compare
|
When the |
matthew-white
left a comment
There was a problem hiding this comment.
Wow, surprisingly tricky bug!
There was a problem hiding this comment.
I was thinking that it'd be nice if we could add a test to prevent future regression. I know it's a bit hard to hook into the default event handler though. What do you think of something like the following? It fails with the code today, but passes with your change.
it('does not remove filter from link after modal is hidden', async () => {
testData.extendedForms.createPast(1);
const component = await load('/projects/1/forms/f/submissions?reviewState=null');
let clickCount = 0;
let failure = false;
component.element.addEventListener('click', (event) => {
if (event.target.tagName !== 'A') return;
event.preventDefault(); // Don't actually download the file.
clickCount += 1;
const url = relativeUrl(event.target.getAttribute('href'));
const filter = url.searchParams.get('$filter');
if (filter == null || !filter.includes('reviewState')) failure = true;
});
// Click the link in the modal.
await component.find('#submission-download-button .btn-primary').trigger('click');
await component.find('#submission-download-button li:nth-of-type(1) button').trigger('click');
await component.getComponent(SubmissionDownload).get('a').trigger('click');
// Click the link via the CTA in the toast.
component.vm.$container.toast.cta.handler();
await nextTick();
clickCount.should.equal(2);
failure.should.be.false;
});There was a problem hiding this comment.
I added the event listener to component.element so that it would run after the Vue handler that hides the modal.
8f51a11 to
c1b0de8
Compare
Closes getodk/central#1168
This was kinda hard bug to fix.
What's happening: When you hover on the hyperlink, you see the correct link but when you click on it, another function runs and hides the modal resulting in resetting of modal state/data, so when default event handler of browser is run it sees no odatafilter query parameter.
Before submitting this PR, please make sure you have:
npm run testandnpm run lintand confirmed all checks still pass OR confirm CircleCI build passes