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

Tests for Simple-Data-Grapher #6104

Closed
wants to merge 26 commits into from
Closed

Conversation

IshaGupta18
Copy link
Collaborator

Here are a few of the tests I have written for csvfiles_controller.rb file and I will add more as and when required.
Since I have done most of my testing (logical and UI) in Simple-Data-Grapher as well, I think these will be good to go for now.
Also, this gives more confidence to #5993 which can be merged soon, now that we have tests to back it up.
@jywarren @gauravano @sagarpreet-chadha @namangupta01 kindly review this and let me know what else can be done!

@IshaGupta18
Copy link
Collaborator Author

PS: I would be fixing the linting soon!

@IshaGupta18
Copy link
Collaborator Author

Here only the test file bears important, rest all is from #5993 https://github.com/publiclab/plots2/pull/6104/files#diff-b6813d8a7c58e0cf4118a4a9e17873cd


}
function graphMaker(data,divId){
var obj = data["sdgobject"];
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be possible to use let instead of var here, because limiting the scope could avoid future global variable-related bugs :) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let

@@ -38,6 +43,10 @@ def rich
image if params[:i]
end

# def tempfunc
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to leave this commented code?

@@ -0,0 +1,2 @@
module CsvfilesHelper
Copy link
Member

Choose a reason for hiding this comment

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

More changes in the future I guess

var headerContainer = document.getElementsByClassName("body-container")[0];
SimpleDataGrapherObject = new SimpleDataGrapher("first");
var value = '<%= current_user %>';
<% if current_user %>
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I did not understand why you have JS code in an embedded ruby file. Would it make sense to move the JS code to a separate file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this file is very much like the rich.html.erb , which integrates the PL Editor in the same way as Simple-Data-Grapher, that is why it's required here!

</table>

<style>
.main_heading_data{
Copy link
Member

Choose a reason for hiding this comment

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

A separate file for these css styles would be great I think

assert_redirected_to '/login'
end

test 'should save graph object' do
Copy link
Member

Choose a reason for hiding this comment

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

Can you think of other unhappy path tests for this? For example, is there any circumstance in which the save/fetch graph object should fail? (e.g. user not logged in)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For fetching, maybe yes! But for saving, I have checked for the login redirect!

@IgorWilbert
Copy link
Member

Thank you @IshaGupta18 ! I left some comments, I hope they are helpful :)

@jywarren
Copy link
Member

jywarren commented Aug 5, 2019

Hi!!! Does this include all the commits from #5993? If so, I'd prefer to merge this instead of that, to do it all in one. That way the tests and functionality are linked!

@IshaGupta18
Copy link
Collaborator Author

IshaGupta18 commented Aug 5, 2019 via email

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Just wondering a bit about the flow and left a question above, but also would you consider adding some system tests to protect the basic workflow here?

if params[:id] && params[:uid]
@graphobject = [params[:id],params[:uid]]
end
# byebug
Copy link
Member

Choose a reason for hiding this comment

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

Hm, is this required?

</div>
<% else %>
<div class="ple-module-content col-lg-9">
<% x = "Power Tag: simple-data-grapher: i/" + @graphobject[0] + "/" + @graphobject[1] %>
Copy link
Member

Choose a reason for hiding this comment

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

Hm, can you walk me through exactly what's happening here, or link to the previous PR where it's explained? Thanks!

@IshaGupta18
Copy link
Collaborator Author

IshaGupta18 commented Aug 5, 2019 via email

@IshaGupta18
Copy link
Collaborator Author

Okay so here is the flow of things, a part of which I will be borrowing from my comment in publiclab/simple-data-grapher#65.

The User clicks on "Publish as a Research Note" button
image
When this happens, as suggested by @sagarpreet-chadha and @gauravano, I save a hash containing the data I will be needing to plot the same graph again. This is done by sending an AJAX to the controller action in csvfiles_controller.rb , which creates a new csvfiles object, and returns just the id and uid of this object.
image

We need this id and uid in order to create the Power Tag for simple-data-grapher.

Once we get this, we give the control to the editor_controller.rb file by doing this:
image
We have passed the id and uid in params here, which is received by the post function (which has the control now)
image

The global variable @graphobject is available to the corresponding view that post function fetches ie rich.html.erb

There, we just use a simple if condition, to check if we need to insert a power tag for simple-data-grapher or not.

image

image

The remaining flow is as described in this comment
ie. we have a function in node_shared.rb (which is yet to be modified) and we have a js file for plotting the graph etc.

And voila! We have a chart here!
image

I know this sounds a little complicated at first, but throughout my research in being able to accomplish this, this is the best method I have been able to find, without hampering much of the existing code. The remaining flow is pretty standard, I have just introduced 2-3 extra lines in editor controller and rih.html.erb. Let me know if you follow this!

@jywarren
Copy link
Member

This looks great; can you actually merge these commits into the PR #5993, so that the tests and functionality are linked into one PR that shows both the functionality and the tests that secure them?

@IshaGupta18
Copy link
Collaborator Author

IshaGupta18 commented Aug 15, 2019

@jywarren we have shifted to #6113, which is the latest PR for all the SDG work, so could you please take a look at that one?

@jywarren
Copy link
Member

OK, great, good to know, and we can close this then, right? THat way people finding this PR aren't confused (as I was! lol)

@jywarren
Copy link
Member

And likewise should #5993 be closed too and a comment left redirecting to #6113?

@IshaGupta18
Copy link
Collaborator Author

Yes, I will be closing that one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants