From 250802a16db51da9a86895c78efffdaad4bba087 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 21 Jul 2023 15:35:56 +0100 Subject: [PATCH] Feature: Hide live preview input and button (#3968) 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 --- .../item_component.html.erb | 5 +++- .../v2_project_submissions/_form.html.erb | 14 ++++++---- .../support/pages/project_submissions/form.rb | 3 +- .../add_submission_spec.rb | 28 +++++++++++++++++-- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/components/project_submissions/item_component.html.erb b/app/components/project_submissions/item_component.html.erb index becefac62a..1ffcd1991c 100644 --- a/app/components/project_submissions/item_component.html.erb +++ b/app/components/project_submissions/item_component.html.erb @@ -8,7 +8,10 @@
<%= link_to 'View code', project_submission.repo_url, target: '_blank', rel: 'noreferrer', class: 'button button--gray font-semibold 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 mr-4', data: { test_id: 'live-preview-btn' } %> + + <% if project_submission.lesson.has_live_preview? %> + <%= link_to 'Live preview', project_submission.live_preview_url, target: '_blank', rel: 'noreferrer', class: 'button button--gray font-semibold mr-4', data: { test_id: 'live-preview-btn' } %> + <% end %>
-
- <%= form.label :live_preview_url, 'Live preview (optional)' %> - <%= form.text_field :live_preview_url, leading_icon: true, placeholder: 'http://example.com', class: 'text-sm', data: { test_id: 'live-preview-url-field' } do %> - <%= inline_svg_tag 'icons/link.svg', class: 'h-5 w-5 text-gray-400', aria: true, title: 'Project live preview', desc: 'Link icon' %> - <% end %> -
+ <% if project_submission.lesson.has_live_preview? %> +
+ <%= form.label :live_preview_url, 'Live preview (optional)' %> + <%= form.text_field :live_preview_url, leading_icon: true, placeholder: 'http://example.com', class: 'text-sm', data: { test_id: 'live-preview-url-field' } do %> + <%= inline_svg_tag 'icons/link.svg', class: 'h-5 w-5 text-gray-400', aria: true, title: 'Project live preview', desc: 'Link icon' %> + <% end %> +
+ <% end %>
Privacy diff --git a/spec/support/pages/project_submissions/form.rb b/spec/support/pages/project_submissions/form.rb index d5d55aad78..9dc81bb2a3 100644 --- a/spec/support/pages/project_submissions/form.rb +++ b/spec/support/pages/project_submissions/form.rb @@ -6,6 +6,7 @@ class Form option :repo_url, default: -> { 'https://github.com/myname/my-project' } option :live_preview_url, default: -> { 'https://myprojectlivepreview.com' } + option :has_live_preview, default: -> { true } def self.fill_in_and_submit(**args) new(**args) @@ -22,7 +23,7 @@ def open def fill_in find(:test_id, 'repo-url-field').fill_in(with: @repo_url) - find(:test_id, 'live-preview-url-field').fill_in(with: @live_preview_url) + find(:test_id, 'live-preview-url-field').fill_in(with: @live_preview_url) if @has_live_preview self end diff --git a/spec/system/v2_lesson_project_submissions/add_submission_spec.rb b/spec/system/v2_lesson_project_submissions/add_submission_spec.rb index 6c4b212948..514eec3f84 100644 --- a/spec/system/v2_lesson_project_submissions/add_submission_spec.rb +++ b/spec/system/v2_lesson_project_submissions/add_submission_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' RSpec.describe 'Add a Project Submission' do - let(:lesson) { create(:lesson, :project) } - before do Flipper.enable(:v2_project_submissions) end @@ -12,6 +10,7 @@ end context 'when a user is signed in' do + let(:lesson) { create(:lesson, :project) } let(:user) { create(:user) } let(:another_user) { create(:user) } @@ -55,8 +54,33 @@ end end + context 'when lesson does not allow previews' do + let(:lesson) { create(:lesson, :project, has_live_preview: false) } + let(:user) { create(:user) } + + before do + sign_in(user) + visit lesson_path(lesson) + end + + 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') + end + end + end + context 'when a user is not signed in' do it 'they cannot add a project submission' do + lesson = create(:lesson, :project) visit lesson_path(lesson) expect(page).not_to have_button('Add Solution')