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

Feature: Hide live preview input and button #3968

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

KevinMulhern
Copy link
Member

Because:

  • Some solutions do not accept previews - for example the early Ruby projects.

This commit:

  • If the project does not accept live previews...
    • Hide the live preview input.
    • hide the live preview button

@KevinMulhern KevinMulhern self-assigned this Jul 14, 2023
@KevinMulhern KevinMulhern added the Type: Enhancement Involves a new feature or enhancement request label Jul 14, 2023
@KevinMulhern KevinMulhern changed the title Feature: Hide live preview button Feature: Hide live previews Jul 14, 2023
@KevinMulhern KevinMulhern changed the title Feature: Hide live previews Feature: Hide live preview input and button Jul 14, 2023
@KevinMulhern KevinMulhern temporarily deployed to odin-review-app-pr-3968 July 14, 2023 00:34 Inactive
Copy link
Member

@ChargrilledChook ChargrilledChook left a comment

Choose a reason for hiding this comment

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

🚀

@@ -8,7 +8,10 @@

<div class="flex flex-col md:flex-row md:items-center">
<%= link_to 'View code', project_submission.repo_url, target: '_blank', rel: 'noreferrer', class: 'button button--gray font-semibold md:mr-4', data: { test_id: 'view-code-btn' } %>
<%= link_to 'Live preview', project_submission.live_preview_url, target: '_blank', rel: 'noreferrer', class: 'button button--gray font-semibold mt-5 md:mt-0 md:mr-4', data: { test_id: 'live-preview-btn' } %>

<% if project_submission.lesson.has_live_preview? %>
Copy link
Member

Choose a reason for hiding this comment

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

Mega nit: Demeter

A delegated previewable? or similar method might be a nice minor addition to the project submission model? I was going to suggest doing it in the component, but we're calling the same logic from the form too

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! previewable is a much better name. What do you think about us renaming the db column to that? we'd get those nice predicate methods for free.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah mint even better, love that ❤️

Copy link
Member Author

Choose a reason for hiding this comment

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

I created a follow up issue to rename it #4003

Best to do it after the react version gets the 🪓

Comment on lines +66 to +76
it 'adds the submission without a preview' do
Pages::ProjectSubmissions::Form
.new(has_live_preview: false)
.open
.fill_in
.submit

within(:test_id, 'submissions-list') do
expect(page).to have_content(user.username)
expect(page).to have_link('View code')
expect(page).not_to have_link('Live preview')
Copy link
Member

Choose a reason for hiding this comment

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

I haven't done thing kind of thing much before, but it intrigues me. Do you find it generally helpful? Is there a risk of drifting away from reality, since there's such a test specific interface? Or is it more about convenience in this case?

Curious to hear your thoughts in general on the goals / benefits / downsides of an approach like this

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry @ChargrilledChook, I'm probably being very dense lol. But is this about the page object or the line you commented on expect(page).not_to have_link('Live preview')?

Copy link
Member

Choose a reason for hiding this comment

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

No worries and my bad, re-reading my comment it is a bit cryptic / stream of consciousness 😅

You're spot on though, I'm referring to the page object Pages::ProjectSubmissions::Form

Copy link
Member Author

@KevinMulhern KevinMulhern Jul 20, 2023

Choose a reason for hiding this comment

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

No worries @ChargrilledChook , happy to explain the approach

I've been using them for a few years at work / on side projects. Heavily inspired by Thoughtbot / Evil Martians and hating having to spend a lot of time figuring out what large specs were actually doing lol.

Two biggest benefits for me:

  • Readability - As time goes on and they grow, Capyabara tests tend get harder to read. Mostly because they're imperative with lots of details on how something is done, think of all the click_button, click_link and fill_in methods calls. Page objects allow for far more expressive and declarative tests - "what will be done" kind of deal. A bunch of related steps can be encapsulated and called with one easy to grok method call - like form.fill_in_and_submit.
  • Reusability - Once you have a page object, it makes all future related tests easier and quicker to write. Theres a more tangible benefit with them on larger systems where there will be a few core forms/pages which many different system tests need to interact with. For us, it's been great for the project submissions where we need different tests for editing, flagging, voting etc.

Is there a risk of drifting away from reality, since there's such a test specific interface? Or is it more about convenience in this case?

I haven't had too many issues with things drifting. But definitely see how they could. I think the trick is not to overuse them. If everything is a page object, you'd be jumping from file to file and absolutely hating the test suite.
Forms are always great candidates for page objects, they need the same steps, potentially in many specs and their interface is always pretty standard, they all need fill_in and submit methods.

These articles were a big help when I first started using them:
https://thoughtbot.com/blog/better-acceptance-tests-with-page-objects
https://evilmartians.com/chronicles/system-of-a-test-2-robust-rails-browser-testing-with-siteprism

Because:
* Some solutions do not accept previews - for example the early Ruby projects.

This commit:
* If the project does not accept live previews...
  * Hide the live preview input.
  * hide the live preview button
@KevinMulhern KevinMulhern temporarily deployed to odin-review-app-pr-3968 July 21, 2023 14:35 Inactive
@KevinMulhern KevinMulhern merged commit 12dd249 into main Jul 21, 2023
@KevinMulhern KevinMulhern deleted the chore/hide-preview-input branch July 21, 2023 14:35
Mclilzee pushed a commit to Mclilzee/theodinproject that referenced this pull request Aug 2, 2023
Because:
* Some solutions do not accept previews - for example the early Ruby
projects.

This commit:
* If the project does not accept live previews...
  * Hide the live preview input.
  * hide the live preview button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Involves a new feature or enhancement request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants