forked from TheOdinProject/theodinproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add more and improve view component previews
Because: * It's more useful the more previews there are This commit: * Adds Notification and User::Avatar previews * Makes use of lookbook tags to group related previews together * Adds more state to completion components to more easily compare * Rework Title link component previews as the base component was changed to Section::LessonComponent
- Loading branch information
1 parent
552faf7
commit 7d54fb0
Showing
7 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
spec/components/previews/about_page/belief_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
spec/components/previews/complete/button_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
module Complete | ||
class ButtonComponentPreview < ViewComponent::Preview | ||
def default | ||
render(ButtonComponent.new(lesson: Lesson.first, current_user: User.first)) | ||
# @!group | ||
def uncompleted | ||
render(ButtonComponent.new(lesson: Lesson.first, current_user: User.find(21))) | ||
end | ||
|
||
def completed | ||
lesson = Lesson.first | ||
current_user = User.last | ||
complete_lesson!(lesson, User.last) | ||
render(ButtonComponent.new(lesson:, current_user:)) | ||
end | ||
|
||
private | ||
|
||
def complete_lesson!(lesson, user) | ||
user.lesson_completions.create( | ||
lesson_id: lesson.id, | ||
lesson_identifier_uuid: lesson.identifier_uuid, | ||
course_id: lesson.course.id, | ||
path_id: lesson.course.path.id, | ||
) | ||
end | ||
end | ||
end |
21 changes: 20 additions & 1 deletion
21
spec/components/previews/complete/icon_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
module Complete | ||
class IconComponentPreview < ViewComponent::Preview | ||
def default | ||
# @!group | ||
def uncompleted | ||
render(IconComponent.new(lesson: Lesson.first, current_user: User.first)) | ||
end | ||
|
||
def completed | ||
lesson = Lesson.first | ||
current_user = User.last | ||
complete_lesson!(lesson, current_user) | ||
render(IconComponent.new(lesson:, current_user:)) | ||
end | ||
|
||
private | ||
|
||
def complete_lesson!(lesson, user) | ||
user.lesson_completions.create( | ||
lesson_id: lesson.id, | ||
lesson_identifier_uuid: lesson.identifier_uuid, | ||
course_id: lesson.course.id, | ||
path_id: lesson.course.path.id, | ||
) | ||
end | ||
end | ||
end |
18 changes: 0 additions & 18 deletions
18
spec/components/previews/lessons/title_link_component_preview.rb
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
spec/components/previews/notification_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class NotificationComponentPreview < ViewComponent::Preview | ||
# @!group | ||
# @display bg_color "#eee" | ||
def unread | ||
render(NotificationComponent.new(notification: unread_notification)) | ||
end | ||
|
||
def read | ||
render(NotificationComponent.new(notification: read_notification)) | ||
end | ||
|
||
private | ||
|
||
def unread_notification | ||
Notification.new(id: 1, title: 'test title', message: 'test message') | ||
end | ||
|
||
def read_notification | ||
Notification.new(id: 1, title: 'test title', message: 'test message', read_at: DateTime.yesterday) | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
spec/components/previews/sections/lesson_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Sections | ||
class LessonComponentPreview < ViewComponent::Preview | ||
# @!group | ||
def with_lesson | ||
render(LessonComponent.new(lesson: Lesson.first, current_user: User.first)) | ||
end | ||
|
||
def with_completed_lesson | ||
lesson = Lesson.first | ||
current_user = User.last | ||
complete_lesson!(lesson, current_user) | ||
render(LessonComponent.new(lesson: Lesson.first, current_user: User.last)) | ||
end | ||
|
||
def with_project | ||
render(LessonComponent.new(lesson: Lesson.find(22), current_user: User.first)) | ||
end | ||
|
||
# @param lesson_id | ||
def with_param(lesson_id: 6) | ||
lesson = Lesson.find_by(id: lesson_id) || Lesson.first | ||
render(LessonComponent.new(lesson:, current_user: User.first)) | ||
end | ||
|
||
private | ||
|
||
def complete_lesson!(lesson, user) | ||
user.lesson_completions.create( | ||
lesson_id: lesson.id, | ||
lesson_identifier_uuid: lesson.identifier_uuid, | ||
course_id: lesson.course.id, | ||
path_id: lesson.course.path.id, | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class User::AvatarComponentPreview < ViewComponent::Preview | ||
def default | ||
current_user = User.first | ||
render(User::AvatarComponent.new(current_user:, classes: nil)) | ||
end | ||
end |