Skip to content
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

Frontend should consume postData written to JSP #2933

Merged
merged 1 commit into from
Dec 16, 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
49 changes: 49 additions & 0 deletions end-to-end-test/local/specs/core/resultspage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var assert = require('assert');
var goToUrlAndSetLocalStorage = require('../../../shared/specUtils').goToUrlAndSetLocalStorage;
var postDataToUrl = require('../../../shared/specUtils').postDataToUrl;
var parse = require('url-parse');
var _ = require('lodash');

var useExternalFrontend = require('../../../shared/specUtils').useExternalFrontend;

const CBIOPORTAL_URL = process.env.CBIOPORTAL_URL.replace(/\/$/, "");

describe('study select page', function() {

if (useExternalFrontend) {

describe('error messaging for invalid study id(s)', function(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am lost here. This file resutspage.spec.js has describe study select page which belongs to Query Page. So, what does this test actually test? Is there also a test that checks for correct working of the POST method? It is not apparent from the test titles. It seems to only deal with checking of error messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

achhh. terrible, i forgot to update these descriptions. they are totally wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will make PR to correct these.


it('show error alert and query form for single invalid study id',function(){
var url = `${CBIOPORTAL_URL}/results?localdist=true`;

const query = {"gene_list":"KRAS NRAS BRAF"
,"cancer_study_list":"coadread_tcga_pub",
"case_ids":"","case_set_id":"coadread_tcga_pub_nonhypermut",
"Z_SCORE_THRESHOLD":"2.0",
"genetic_profile_ids_PROFILE_MUTATION_EXTENDED":"coadread_tcga_pub_mutations",
"genetic_profile_ids_PROFILE_COPY_NUMBER_ALTERATION":"coadread_tcga_pub_gistic"
};

postDataToUrl(url, query);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data is posted to page here


browser.waitUntil(()=>{
var url = browser.getUrl();

// make sure param in query is passed to url
return _.every(query,(item,key)=>{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pvannierop here we check that every posted parameter key has made it into the url. this could only happen as a result of our code transferring the postData variable into the URL.

return url.includes(key);
});
});

const postData = browser.execute(()=>{
return window.postData;
}).value;

assert(postData === null, "postData has been set to null after read");

});
});

}
});
37 changes: 36 additions & 1 deletion end-to-end-test/shared/specUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,38 @@ function getOncoprintGroupHeaderOptionsElements(trackGroupIndex) {
};
}


function postDataToUrl(url, data) {

browser.execute((url, data)=>{

function formSubmit(url, params) {
// method="smart" means submit with GET iff the URL wouldn't be too long

const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', url);
form.setAttribute('target', '_self');

for (const key of Object.keys(params)) {
const hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}

document.body.appendChild(form);
form.submit();
}

formSubmit(url, data)

},url, data)

}


module.exports = {
checkElementWithElementHidden: checkElementWithElementHidden,
waitForPlotsTab: waitForPlotsTab,
Expand Down Expand Up @@ -332,5 +364,8 @@ module.exports = {
getOncoprintGroupHeaderOptionsElements:getOncoprintGroupHeaderOptionsElements,
showGsva: showGsva,
setResultsPageSettingsMenuOpen:setResultsPageSettingsMenuOpen,
setDropdownOpen:setDropdownOpen
setDropdownOpen:setDropdownOpen,
postDataToUrl:postDataToUrl
};


4 changes: 3 additions & 1 deletion src/pages/resultsView/ResultsViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import setWindowVariable from 'shared/lib/setWindowVariable';
import LoadingIndicator from "shared/components/loadingIndicator/LoadingIndicator";
import onMobxPromise from "shared/lib/onMobxPromise";
import {createQueryStore} from "shared/lib/createQueryStore";
import {handleLegacySubmission} from "shared/lib/redirectHelpers";
import {handleLegacySubmission, handlePostedSubmission} from "shared/lib/redirectHelpers";

function initStore(appStore: AppStore, urlWrapper: ResultsViewURLWrapper) {
const resultsViewPageStore = new ResultsViewPageStore(
Expand Down Expand Up @@ -103,6 +103,8 @@ export default class ResultsViewPage extends React.Component<

handleLegacySubmission(this.urlWrapper);

handlePostedSubmission(this.urlWrapper);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I understand this correctly, only the ResultsViewPage can handle POST requests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct. the server writes the post data in all cases though so any page can in theory access it.


setWindowVariable('urlWrapper', this.urlWrapper);

if (this.urlWrapper.hasSessionId) {
Expand Down
9 changes: 9 additions & 0 deletions src/shared/lib/redirectHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export function restoreRouteAfterRedirect(injected: { routing:ExtendedRouterStor

}

// harvest query data written to the page by JSP to support queries originating
// from external posts
export function handlePostedSubmission(urlWrapper:ResultsViewURLWrapper){
if (getBrowserWindow().postData) {
urlWrapper.updateURL(getBrowserWindow().postData, "results", true, true);
// we don't want this data to be around anymore once we've tranferred it to URL
getBrowserWindow().postData = null;
}
}

export function handleLegacySubmission(urlWrapper:ResultsViewURLWrapper){
const legacySubmission = localStorage.getItem("legacyStudySubmission");
Expand Down