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

Clean up map view info window #418

Merged
merged 6 commits into from
Jan 30, 2018

Conversation

stardust66
Copy link
Contributor

Context

Summary of Changes

  • Replace the NumberedCircle class by using Google's built-in custom marker and info window system. For details please see my commit message.
  • Make the filter icons horizontal, as suggested in the issue.

Checklist

  • Tested Mobile Responsiveness
  • Added Unit Tests
  • CI Passes
  • Deploys to Heroku on test Correctly (Maintainers will handle)
  • Added Documentation (Service and Code when required)

Screenshots

Before

image

After

image

Using the built-in marker eliminates the need for the NumberedCircle
class and significantly simplifies the code, since now the Google
API takes care of positioning the marker, the label, and the
info window.

This also solves the overflow and lack of padding problems that the
old info window had.
@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 11, 2018

Some tests failed, so I'll go look into that, but the screenshot sure looks nice!

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 11, 2018

For some reason this breaks a few cucumber tests.

There is a supporting ruby function, mock_location, for 4 of the tests that actually just executes a javascript function on the page.

see: features/support/locations.rb which contains the underlying functions that are error-ing out.

That set of functions errors out for 4 of the tests now.

These are:
cucumber features/nearby.feature:4 # Scenario: Show nearby restrooms when guessing
cucumber features/nearby.feature:9 # Scenario: Show absence of nearby restrooms
cucumber features/search.feature:10 # Scenario: Location search from splash page
cucumber features/search.feature:20 # Scenario: Map display

The error messages look pretty much like this all 4 times:

    When I am in Winnipeg and I guess my location on the submission page # features/step_definitions/submission_steps.rb:29
      One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
      ReferenceError: Can't find variable: Refuge
      ReferenceError: Can't find variable: Refuge
          at undefined:4
          at :21
          at :21 (Capybara::Poltergeist::JavascriptError)
      ./features/support/locations.rb:12:in `mock_location'
      ./features/step_definitions/submission_steps.rb:33:in `/^I am in (.*) and I guess my location on the submission page$/'
      features/nearby.feature:6:in `When I am in Winnipeg and I guess my location on the submission page'
    Then I should see an existing restroom nearby                        # features/step_definitions/restroom_steps.rb:9

(The innermost error is "Can't find variable: Refuge".)


There are also two tests where searching for an HTML element by its #id and/or .class fails:

Here
cucumber features/search.feature:4 # Scenario: Text search from splash page

    When I am on the splash page         # features/step_definitions/navigation_steps.rb:1
    And I search for "Winnipeg"          # features/step_definitions/search_steps.rb:1
    Then I should see a restroom         # features/step_definitions/restroom_steps.rb:5
      expected to find visible css "#list .listItem" but there were no matches (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/restroom_steps.rb:6:in `/^I should( not)? see a restroom$/'
      features/search.feature:8:in `Then I should see a restroom'

and Here
cucumber features/preview.feature:4 # Scenario: Preview a restroom before submitting

  Scenario: Preview a restroom before submitting    # features/preview.feature:4
    Given I have filled out the address information # features/step_definitions/preview_steps.rb:1
    When I click the preview button                 # features/step_definitions/preview_steps.rb:11
    Then I should see the map preview               # features/step_definitions/preview_steps.rb:15
      expected to find visible css "div#mapArea" but there were no matches. Also found "", which matched the selector but not all filters. (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/preview_steps.rb:16:in `/^I should see the map preview$/'
      features/preview.feature:7:in `Then I should see the map preview'

@stardust66
Copy link
Contributor Author

I don't know what's making the tests not pass. The website seems to exhibit normal behavior when I use it, i.e. it searches and displays bathrooms correctly. I'll try and debug the tests but that might take a while since I'll be busy over the next few days.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 13, 2018

I agree that the code looks normal to me, and it definitely works. These errors are also really strange to me.

In order to hopefully save some time on manual debugging, or at least narrow the bug hunt a bit, it might be worth submitting each commit to a PR one at a time. That would let Travis CI do a full run on each commit.

I have in mind a way to do this from the command line, but perhaps you already know exactly how, so feel free to ignore; Regardless, I'm not going to hint at a way without explaining it, so here goes:

​If you preserve these commits (for example, just make an identical branch with ​git branch -b [any-name-here])...

you can switch back to (git checkout) the map-bathroom-detail branch, and then git reset --hard HEAD~3 (reset this branch to the commit at 3 commits back from the HEAD.)

and then merge your commits back, one at a time, i.e:

  • git merge 3f7f316 (which would automatically grab the first of the three commits for this PR, from your copy branch mentioned above)

and then git push https://github.com/stardust66/refugerestrooms

This is the standard approach and having mixed tabs and spaces isn't
good.
Taking the outer html of the container element to the container
itself. This is useful because the container has the markerPopup
class.
@stardust66
Copy link
Contributor Author

It seems like the first commit already broke the tests.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 15, 2018

From here on the first commit's tests:

Failing Scenarios:
cucumber features/nearby.feature:4 # Scenario: Show nearby restrooms when guessing
cucumber features/nearby.feature:9 # Scenario: Show absence of nearby restrooms
cucumber features/preview.feature:4 # Scenario: Preview a restroom before submitting
cucumber features/search.feature:4 # Scenario: Text search from splash page
cucumber features/search.feature:10 # Scenario: Location search from splash page
cucumber features/search.feature:20 # Scenario: Map display

The tests failing on the first commit are the same as the ones that failed previously for the PR as a whole. All that from changing the whitespace in the maps javascript file? Kinda weird.

@stardust66
Copy link
Contributor Author

Actually, the first commit is right below the top post. It's titled "Use google maps built-in custom marker". In there, I deleted the NumberedCircle class, and replaced it with a Google Maps custom marker with label.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 15, 2018

Okay, yep. Anyway, failing tests are the same after commit 1, 2, and 3, i.e. nothing additional breaks later than commit 1, so I guess the troubleshooting can be limited to commit 1. Hopefully that narrows it down a bit. (I'm not that great with JavaScript, but I'll look it over anyway.)

@stardust66
Copy link
Contributor Author

Thank you @DeeDeeG! I'm gonna be busy over the next couple of days so I probably won't be able to work on this that much.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 16, 2018

So we're assuming there is some obscure thing wrong with maps.js, since that's the only change in commit one.

According to this online JavaScript validator, [link], there are some undefined functions (among other, possibly more-minor errors):

Line Column Error
4 52 'currentLocationImage' is not defined.
54 10 'circleMarkerImage' is not defined.
143 20 'locator' is not defined.
182 64 'showMarkerImage' is not defined.

Maybe that has something to do with it?

@stardust66
Copy link
Contributor Author

@DeeDeeG Thanks for taking a look. Those are all variables defined outside of maps.js that are automatically included in the <head> of every page by rails. The image ones are in global_vars.js.erb.

During testing, working from the original commit, I've deleted the entire NumberedCircle class, which would cause the bathrooms to not show up on the map at all, and the tests still pass. Taking a further look, most of the steps for testing the map feature have been previously commented out, in map_steps.rb. The tests that are failing for this PR don't pertain to the map feature.

This is what was breaking the tests. The headless browser doesn't
support arrow functions, which most modern browsers support now.
This was breaking all the tests.
@stardust66
Copy link
Contributor Author

@DeeDeeG Fixed it! In the end the problem was me using an arrow function () => {}, which the headless browser that ran the tests didn't support. Although every up to date browser other than internet explorer supports it, I probably shouldn't have used it because we want to support the internet explorer users. However, I think we should make the tests a little easier to debug.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 28, 2018

Nice! So this looks merge-ready to me. (Ideally reviewed by someone who gets JavaScript better than I do, but this seems pretty simple.)

Any thoughts on how to make the tests better?

Maybe some broader (less hyper-narrow, less feature-oriented) error steps, for example add a more generic "page should not show a big huge error message"?

(Not that that would help with this PR, I think.)

Maybe there is a way to make PhantomJS, the headless browser we use, surface an error message of its own?

@stardust66
Copy link
Contributor Author

I just made #432 and #433 regarding test debugging.

@DeeDeeG
Copy link
Contributor

DeeDeeG commented Jan 28, 2018

@mi-wood, would you like to review this, now that the Travis CI build is passing?

I think it would be better to have a reviewer who knows more about JavaScript, but I am comfortable with merging it, since it works in testing.

Copy link
Member

@mi-wood mi-wood left a comment

Choose a reason for hiding this comment

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

Minor comment, but I this seems to get rid of a lot of code, which is nice :)

My one question is if this makes #298 harder? Do the helper map classes included in their licensing, or is it separate from the data? And if we decide to move off of google maps, will these need to be changed back to our custom objects?

// Create Icon
var circleIcon = {
url: circleMarkerImage,
size: new google.maps.Size(37, 37),
Copy link
Member

Choose a reason for hiding this comment

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

Where are these values coming from? Can we move them out into constants DEFAULT_WIDTH or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I measured the size of the image. It's in a constant now.

@stardust66
Copy link
Contributor Author

stardust66 commented Jan 29, 2018

As per your question, when we get to #298, we'll probably need to use another library to do this, so it'll be a bit of work, but the old solution depended on the Google Maps API as well, just not as much. Also, it'll be a better idea to use a library to avoid reinventing the wheel, so I think moving on we just won't use custom objects.

From my understanding, OpenStreetMap is mostly just the data, and to deploy it we need some other library. Leaflet, suggested by https://wiki.openstreetmap.org/wiki/Deploying_your_own_Slippy_Map, seems like a good choice and it has a powerful API for markers and popups.

@mi-wood
Copy link
Member

mi-wood commented Jan 30, 2018

I'm good with this 👍

@mi-wood mi-wood merged commit 3505b12 into RefugeRestrooms:develop Jan 30, 2018
@stardust66 stardust66 deleted the map-bathroom-detail branch January 30, 2018 02:36
DeeDeeG pushed a commit to DeeDeeG/refugerestrooms that referenced this pull request Oct 15, 2018
DeeDeeG pushed a commit to DeeDeeG/refugerestrooms that referenced this pull request Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants