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

Consolidating view_components previews into test/previews/ folder #1232

Merged
merged 16 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ demo/app/assets/stylesheets/primer.css
# Generated by lib/tasks/docs.rake
/.yardoc
/doc
demo/test/components/previews/primer/docs/
test/components/previews/primer/docs/
lookbook/app/assets/builds/
docs/content/adr/
docs/content/components/
Expand Down
4 changes: 2 additions & 2 deletions component_generator.thor
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class ComponentGenerator < Thor::Group

def create_system_test
template("templates/system_test.rb.tt", "test/system/#{status_path}#{underscore_name}_test.rb") if js_package_name
template("templates/#{status_template_path}system_test_preview.rb.tt", "demo/test/components/previews/primer/#{status_path}#{underscore_name}_preview.rb") if js_package_name
template("templates/preview.tt", "test/components/previews/primer/#{status_path}#{underscore_name}_preview.rb") if js_package_name
end

def create_preview
template("templates/preview.tt", "test/components/previews/#{status_path}#{underscore_name}_preview.rb")
template("templates/preview.tt", "test/components/previews/primer/#{status_path}#{underscore_name}_preview.rb")
end

def add_to_docs_rakefile
Expand Down
2 changes: 1 addition & 1 deletion contributor-docs/adding-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ If the `js` flag is passed in it will create some extra files:

- `app/components/<status>/<component_name>.ts` contains the imports for any specified npm dependencies
- `test/system/<status>/<component_name>.rb` contains the component’s system tests
- `demo/test/components/preview/primer/<status>/<component_name>_preview.rb` contains the component’s previews
- `test/components/preview/primer/<status>/<component_name>_preview.rb` contains the component’s previews

The script also edits some files:

Expand Down
2 changes: 2 additions & 0 deletions demo/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@
# config.action_view.raise_on_missing_translations = true
config.primer_view_components.silence_deprecations = true
config.primer_view_components.raise_on_invalid_options = false

config.view_component.preview_paths << Rails.root.join("../test/components/previews")
end
9 changes: 0 additions & 9 deletions demo/test/components/previews/primer/tooltip_preview.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/tasks/docs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ namespace :docs do
task :preview do
registry = generate_yard_registry

FileUtils.rm_rf("demo/test/components/previews/primer/docs/")
FileUtils.rm_rf("test/components/previews/primer/docs/")

components = Primer::Component.descendants

Expand All @@ -373,7 +373,7 @@ namespace :docs do

yard_example_tags = initialize_method.tags(:example)

path = Pathname.new("demo/test/components/previews/primer/docs/#{short_name.underscore}_preview.rb")
path = Pathname.new("test/components/previews/primer/docs/#{short_name.underscore}_preview.rb")
path.dirname.mkdir unless path.dirname.exist?

File.open(path, "w") do |f|
Expand All @@ -386,7 +386,7 @@ namespace :docs do
method_name = name.split("|").first.downcase.parameterize.underscore
f.puts(" def #{method_name}; end")
f.puts unless index == yard_example_tags.size - 1
path = Pathname.new("demo/test/components/previews/primer/docs/#{short_name.underscore}_preview/#{method_name}.html.erb")
path = Pathname.new("test/components/previews/primer/docs/#{short_name.underscore}_preview/#{method_name}.html.erb")
path.dirname.mkdir unless path.dirname.exist?
File.open(path, "w") do |view_file|
view_file.puts(code.to_s)
Expand Down
9 changes: 0 additions & 9 deletions templates/stable/system_test_preview.rb.tt

This file was deleted.

11 changes: 0 additions & 11 deletions templates/system_test_preview.rb.tt

This file was deleted.

2 changes: 1 addition & 1 deletion test/components/previews/beta/flash_preview.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Beta
# @label FlashComponent
# @label Flash
class FlashPreview < ViewComponent::Preview
# @label Playground
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class AutoCompletePreview < ViewComponent::Preview
def default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class CounterComponentPreview < ViewComponent::Preview
def default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class LocalTimeComponentPreview < ViewComponent::Preview
def default
Expand All @@ -6,16 +8,16 @@ def default

def with_all_the_options
render(Primer::LocalTime.new(
datetime: DateTime.parse("2016-06-01T13:05:07Z"),
weekday: :long,
year: :"2-digit",
month: :long,
day: :"2-digit",
hour: :"2-digit",
minute: :"2-digit",
second: :"2-digit",
time_zone_name: :long
))
datetime: DateTime.parse("2016-06-01T13:05:07Z"),
weekday: :long,
year: :"2-digit",
month: :long,
day: :"2-digit",
hour: :"2-digit",
minute: :"2-digit",
second: :"2-digit",
time_zone_name: :long
))
end

def with_contents
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class TabPanelsPreview < ViewComponent::Preview
def default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class TimeAgoComponentPreview < ViewComponent::Preview
def default
Expand Down
9 changes: 9 additions & 0 deletions test/components/previews/primer/tooltip_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Primer
class TooltipPreview < ViewComponent::Preview
def description; end

def label; end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Primer
class UnderlinePanelsPreview < ViewComponent::Preview
def default
Expand Down