mirror of
https://github.com/discourse/discourse-rewind.git
synced 2025-07-07 14:22:12 +00:00
create kitchen sink spec for fake data
This commit is contained in:
parent
80210f11d2
commit
90a03dec31
@ -42,7 +42,7 @@ module DiscourseRewind
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
SiteSetting.discourse_reaction_enabled || SiteSetting.chat_enabled
|
SiteSetting.discourse_reactions_enabled || SiteSetting.chat_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_and_limit(reactions)
|
def sort_and_limit(reactions)
|
||||||
|
@ -10,7 +10,7 @@ module DiscourseRewind
|
|||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
reading_time: reading_time,
|
reading_time: reading_time,
|
||||||
books: best_book_fit(reading_time),
|
book: best_book_fit(reading_time),
|
||||||
},
|
},
|
||||||
identifier: "reading-time",
|
identifier: "reading-time",
|
||||||
}
|
}
|
||||||
@ -44,11 +44,13 @@ module DiscourseRewind
|
|||||||
def best_book_fit(reading_time)
|
def best_book_fit(reading_time)
|
||||||
reading_time_rest = reading_time
|
reading_time_rest = reading_time
|
||||||
books = []
|
books = []
|
||||||
|
|
||||||
while reading_time_rest > 0
|
while reading_time_rest > 0
|
||||||
books << popular_book_reading_time.min_by { |_, v| (v - reading_time_rest).abs }.first
|
books << popular_book_reading_time.min_by { |_, v| (v - reading_time_rest).abs }.first
|
||||||
reading_time_rest -= popular_book_reading_time[books.last]
|
reading_time_rest -= popular_book_reading_time[books.last]
|
||||||
end
|
end
|
||||||
books.group_by(&:itself).transform_values(&:count)
|
|
||||||
|
books.group_by(&:itself).transform_values(&:count).max_by { |_, count| count }.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { concat } from "@ember/helper";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
|
import emoji from "discourse/helpers/emoji";
|
||||||
|
|
||||||
|
export default class BestTopics extends Component {
|
||||||
|
rank(idx) {
|
||||||
|
return idx + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
emojiName(rank) {
|
||||||
|
if (rank + 1 === 1) {
|
||||||
|
return "1st_place_medal";
|
||||||
|
} else if (rank + 1 === 2) {
|
||||||
|
return "2nd_place_medal";
|
||||||
|
} else if (rank + 1 === 3) {
|
||||||
|
return "3rd_place_medal";
|
||||||
|
} else {
|
||||||
|
return "medal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="rewind-report-page -best-topics">
|
||||||
|
<h2 class="rewind-report-title">Your 3 best topics</h2>
|
||||||
|
<div class="rewind-report-container">
|
||||||
|
{{log @report.data}}
|
||||||
|
<div class="rewind-card">
|
||||||
|
{{#each @report.data as |topic idx|}}
|
||||||
|
<a
|
||||||
|
href={{concat "/t/-/" topic.topic_id}}
|
||||||
|
class={{concat "best-topics__topic" " rank-" (this.rank idx)}}
|
||||||
|
>
|
||||||
|
<span class="best-topics__rank">{{emoji
|
||||||
|
(this.emojiName idx)
|
||||||
|
}}</span><h2>{{topic.title}}</h2>
|
||||||
|
<span class="best-topics__excerpt">{{htmlSafe
|
||||||
|
topic.excerpt
|
||||||
|
}}</span>
|
||||||
|
</a>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
}
|
@ -31,6 +31,7 @@ export default class Reactions extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
{{log @report}}
|
||||||
<div class="rewind-report-page -post-received-reactions">
|
<div class="rewind-report-page -post-received-reactions">
|
||||||
<h2 class="rewind-report-title">Most received reactions in topics</h2>
|
<h2 class="rewind-report-title">Most received reactions in topics</h2>
|
||||||
<div class="rewind-report-container">
|
<div class="rewind-report-container">
|
||||||
|
@ -3,12 +3,12 @@ import Component from "@glimmer/component";
|
|||||||
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
|
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
|
||||||
export default class ReadingTime extends Component {
|
export default class ReadingTime extends Component {
|
||||||
<template>
|
<template>
|
||||||
<div class="rewind-report-page">
|
<div class="rewind-report-page -reading-time">
|
||||||
Reading time
|
<h2 class="rewind-report-title">Reading time</h2>
|
||||||
</div>
|
<div class="rewind-report-container">
|
||||||
|
<span class="reading-time__time">{{@report.data.reading_time}}</span>
|
||||||
<div class="rewind-report-page">
|
<span class="reading-time__book">{{@report.data.book}}</span>
|
||||||
page 2
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,8 @@ export default class Rewind extends Component {
|
|||||||
<ActivityCalendar @report={{report}} />
|
<ActivityCalendar @report={{report}} />
|
||||||
{{else if (eq report.identifier "favorite-tags")}}
|
{{else if (eq report.identifier "favorite-tags")}}
|
||||||
<FavoriteTags @report={{report}} />
|
<FavoriteTags @report={{report}} />
|
||||||
|
{{else if (eq report.identifier "reading-time")}}
|
||||||
|
<ReadingTime @report={{report}} />
|
||||||
{{else if (eq report.identifier "favorite-categories")}}
|
{{else if (eq report.identifier "favorite-categories")}}
|
||||||
<FavoriteCategories @report={{report}} />
|
<FavoriteCategories @report={{report}} />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
47
spec/system/kitchen_sink_spec.rb
Normal file
47
spec/system/kitchen_sink_spec.rb
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "Discourse Rewind - kitchen sink", type: :system do
|
||||||
|
fab!(:current_user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SiteSetting.discourse_reactions_enabled = true
|
||||||
|
SiteSetting.chat_enabled = true
|
||||||
|
SiteSetting.discourse_rewind_enabled = true
|
||||||
|
|
||||||
|
sign_in(current_user)
|
||||||
|
|
||||||
|
# reactions received
|
||||||
|
reactions = %w[open_mouth confetti_ball hugs +1 laughing heart]
|
||||||
|
Fabricate
|
||||||
|
.times(10, :post, user: current_user)
|
||||||
|
.each do |post|
|
||||||
|
DiscourseReactions::Reaction.create!(
|
||||||
|
created_at: (Date.new(2024, 1, 1) + rand(1..200).days),
|
||||||
|
post:,
|
||||||
|
reaction_value: reactions.sample,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
# reading time
|
||||||
|
100.times do |i|
|
||||||
|
UserVisit.create!(
|
||||||
|
user_id: current_user.id,
|
||||||
|
time_read: rand(1..200),
|
||||||
|
visited_at: (Date.new(2024, 1, 1) + i.days).strftime("%Y-%m-%d"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
# calendar
|
||||||
|
Fabricate.times(10, :post, user: current_user, created_at: Date.new(2024, 1, 25))
|
||||||
|
Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 3, 12))
|
||||||
|
Fabricate.times(5, :post, user: current_user, created_at: Date.new(2024, 8, 19))
|
||||||
|
Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 10, 29))
|
||||||
|
Fabricate.times(20, :post, user: current_user, created_at: Date.new(2024, 11, 2))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can visit the rewind page" do
|
||||||
|
visit("/my/activity/rewind")
|
||||||
|
|
||||||
|
pause_test
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user