DEV: Clean up the plugin (#426)

This commit is contained in:
Jarek Radosz 2023-08-01 22:32:30 +02:00 committed by GitHub
parent 6309490901
commit 6761e2c84f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 1051 additions and 998 deletions

8
.gitignore vendored
View File

@ -1,7 +1,3 @@
.DS_Store
gems/
/node_modules
.on-save.json
node_modules node_modules
yarn-error.log /gems
.rubocop-https---raw-githubusercontent-com-discourse-* /auto_generated

View File

@ -1,3 +1,3 @@
--print-width=100 --print-width=100
--plugins=plugin/trailing_comma --plugins=plugin/trailing_comma,disable_ternary
--ignore-files=vendor/* --ignore-files=vendor/*

View File

@ -5,4 +5,5 @@ source "https://rubygems.org"
group :development do group :development do
gem "rubocop-discourse" gem "rubocop-discourse"
gem "syntax_tree" gem "syntax_tree"
gem "syntax_tree-disable_ternary"
end end

View File

@ -2,35 +2,46 @@ GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
ast (2.4.2) ast (2.4.2)
json (2.6.2) json (2.6.3)
parallel (1.22.1) language_server-protocol (3.17.0.3)
parser (3.1.2.1) parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1) ast (~> 2.4.1)
prettier_print (1.2.0) racc
prettier_print (1.2.1)
racc (1.7.1)
rainbow (3.1.1) rainbow (3.1.1)
regexp_parser (2.6.0) regexp_parser (2.8.1)
rexml (3.2.5) rexml (3.2.6)
rubocop (1.36.0) rubocop (1.55.1)
json (~> 2.3) json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.1.2.1) parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0) regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0) rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0) rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0) unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.21.0) rubocop-ast (1.29.0)
parser (>= 3.1.1.0) parser (>= 3.2.1.0)
rubocop-discourse (3.0) rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-discourse (3.3.0)
rubocop (>= 1.1.0) rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0) rubocop-rspec (>= 2.0.0)
rubocop-rspec (2.13.2) rubocop-factory_bot (2.23.1)
rubocop (~> 1.33) rubocop (~> 1.33)
ruby-progressbar (1.11.0) rubocop-rspec (2.23.0)
syntax_tree (5.1.0) rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0) prettier_print (>= 1.2.0)
unicode-display_width (2.3.0) syntax_tree-disable_ternary (1.0.0)
unicode-display_width (2.4.2)
PLATFORMS PLATFORMS
ruby ruby
@ -38,6 +49,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
rubocop-discourse rubocop-discourse
syntax_tree syntax_tree
syntax_tree-disable_ternary
BUNDLED WITH BUNDLED WITH
2.1.4 2.1.4

View File

@ -1,38 +1,38 @@
## Discourse Calendar # Discourse Calendar
Adds the ability to create a dynamic calendar in the first post of a topic. Adds the ability to create a dynamic calendar in the first post of a topic.
Topic discussing the plugin itself can be found here: [https://meta.discourse.org/t/discourse-calendar/97376](https://meta.discourse.org/t/discourse-calendar/97376) Topic discussing the plugin itself can be found here: [https://meta.discourse.org/t/discourse-calendar/97376](https://meta.discourse.org/t/discourse-calendar/97376)
### Customisation ## Customization
#### Plugins ### Events
##### Events
- `discourse_post_event_event_will_start` this DiscourseEvent will be triggered one hour before an event starts - `discourse_post_event_event_will_start` this DiscourseEvent will be triggered one hour before an event starts
- `discourse_post_event_event_started` this DiscourseEvent will be triggered when an event starts - `discourse_post_event_event_started` this DiscourseEvent will be triggered when an event starts
- `discourse_post_event_event_ended` this DiscourseEvent will be triggered when an event ends - `discourse_post_event_event_ended` this DiscourseEvent will be triggered when an event ends
#### Custom Fields ### Custom Fields
Custom fields can be set in plugin settings. Once added a new form will appear on event UI. Custom fields can be set in plugin settings. Once added a new form will appear on event UI.
These custom fields are available when a plugin event is triggered. These custom fields are available when a plugin event is triggered.
#### Holidays ### Holidays
See an incorrect or missing holiday? Familiarize yourself with the [holiday definition Syntax](vendor/holidays/definitions/doc/SYNTAX.md). Then make your updates in the `vendor/holiday/definitions` directory. See an incorrect or missing holiday? Familiarize yourself with the [holiday definition Syntax](vendor/holidays/definitions/doc/SYNTAX.md). Then make your updates in the `vendor/holiday/definitions` directory.
Generate updated holidays as follows. Generate updated holidays as follows.
```sh ```sh
cd vendor/holidays cd vendor/holidays
# Generate holiday definitions # Generate holiday definitions
bundle exec rake generate:definitions bin/rails generate:definitions
``` ```
Install the plugin and switch to the discourse root(not the plugin directory). Install the plugin and switch to the discourse root(not the plugin directory).
```sh ```sh
# Collect all holiday regions into assets/javascripts/lib/regions.js # Collect all holiday regions into assets/javascripts/lib/regions.js
bundle exec rake javascript:update_constants bin/rails javascript:update_constants
``` ```

View File

@ -11,7 +11,7 @@
<AdminHolidaysListItem <AdminHolidaysListItem
@holiday={{holiday}} @holiday={{holiday}}
@isHolidayDisabled={{holiday.disabled}} @isHolidayDisabled={{holiday.disabled}}
@region_code={{region_code}} @region_code={{@region_code}}
/> />
{{/each}} {{/each}}
</tbody> </tbody>

View File

@ -1,5 +1,5 @@
import { computed } from "@ember/object"; import { computed } from "@ember/object";
import { HOLIDAY_REGIONS } from "discourse/plugins/discourse-calendar/lib/regions"; import { HOLIDAY_REGIONS } from "../lib/regions";
import I18n from "I18n"; import I18n from "I18n";
import ComboBoxComponent from "select-kit/components/combo-box"; import ComboBoxComponent from "select-kit/components/combo-box";

View File

@ -1,6 +1,6 @@
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import { isNotFullDayEvent } from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import { isNotFullDayEvent } from "../lib/guess-best-date-format";
import { formatEventName } from "discourse/plugins/discourse-calendar/helpers/format-event-name"; import { formatEventName } from "../helpers/format-event-name";
import loadScript from "discourse/lib/load-script"; import loadScript from "discourse/lib/load-script";
import Component from "@ember/component"; import Component from "@ember/component";
import { schedule } from "@ember/runloop"; import { schedule } from "@ember/runloop";

View File

@ -1,5 +1,5 @@
import { action } from "@ember/object"; import { action } from "@ember/object";
import { TIME_ZONE_TO_REGION } from "discourse/plugins/discourse-calendar/lib/regions"; import { TIME_ZONE_TO_REGION } from "../../lib/regions";
export default { export default {
setupComponent(args, component) { setupComponent(args, component) {

View File

@ -7,7 +7,7 @@ import { action, computed, set } from "@ember/object";
import { equal, gte } from "@ember/object/computed"; import { equal, gte } from "@ember/object/computed";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { buildParams, replaceRaw } from "../../lib/raw-event-helper"; import { buildParams, replaceRaw } from "../lib/raw-event-helper";
const DEFAULT_REMINDER = { const DEFAULT_REMINDER = {
type: "notification", type: "notification",

View File

@ -1,4 +1,4 @@
import guessDateFormat from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import guessDateFormat from "../lib/guess-best-date-format";
import { htmlHelper } from "discourse-common/lib/helpers"; import { htmlHelper } from "discourse-common/lib/helpers";
export default htmlHelper((date) => { export default htmlHelper((date) => {

View File

@ -1,6 +1,6 @@
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import eventRelativeDate from "discourse/plugins/discourse-calendar/lib/event-relative-date"; import eventRelativeDate from "../lib/event-relative-date";
import eventLocalDate from "discourse/plugins/discourse-calendar/lib/event-local-date"; import eventLocalDate from "../lib/event-local-date";
function initializeDecorateTopicTitle(api) { function initializeDecorateTopicTitle(api) {
api.decorateTopicTitle((topic, node, topicTitleType) => { api.decorateTopicTitle((topic, node, topicTitleType) => {

View File

@ -8,14 +8,10 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import I18n from "I18n"; import I18n from "I18n";
import { import { colorToHex, contrastColor, stringToColor } from "../lib/colors";
colorToHex,
contrastColor,
stringToColor,
} from "discourse/plugins/discourse-calendar/lib/colors";
import { createPopper } from "@popperjs/core"; import { createPopper } from "@popperjs/core";
import { isNotFullDayEvent } from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import { isNotFullDayEvent } from "../lib/guess-best-date-format";
import { formatEventName } from "discourse/plugins/discourse-calendar/helpers/format-event-name"; import { formatEventName } from "../helpers/format-event-name";
import getURL from "discourse-common/lib/get-url"; import getURL from "discourse-common/lib/get-url";
function loadFullCalendar() { function loadFullCalendar() {

View File

@ -1,5 +1,5 @@
import I18n from "I18n"; import I18n from "I18n";
import guessDateFormat from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import guessDateFormat from "../lib/guess-best-date-format";
import { cookAsync } from "discourse/lib/text"; import { cookAsync } from "discourse/lib/text";
import WidgetGlue from "discourse/widgets/glue"; import WidgetGlue from "discourse/widgets/glue";
import { getRegister } from "discourse-common/lib/get-owner"; import { getRegister } from "discourse-common/lib/get-owner";

View File

@ -1,6 +1,6 @@
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
import { cancel } from "@ember/runloop"; import { cancel } from "@ember/runloop";
import eventRelativeDate from "discourse/plugins/discourse-calendar/lib/event-relative-date"; import eventRelativeDate from "../lib/event-relative-date";
import discourseLater from "discourse-common/lib/later"; import discourseLater from "discourse-common/lib/later";
function computeRelativeEventDates() { function computeRelativeEventDates() {

View File

@ -1,4 +1,4 @@
import guessDateFormat from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import guessDateFormat from "./guess-best-date-format";
export default function eventLocalDate(container) { export default function eventLocalDate(container) {
container.classList.remove("past", "current", "future"); container.classList.remove("past", "current", "future");

View File

@ -1,5 +1,5 @@
import I18n from "I18n"; import I18n from "I18n";
import guessDateFormat from "discourse/plugins/discourse-calendar/lib/guess-best-date-format"; import guessDateFormat from "./guess-best-date-format";
function _computeCurrentEvent(container, endsAt) { function _computeCurrentEvent(container, endsAt) {
const indicator = document.createElement("div"); const indicator = document.createElement("div");

View File

@ -1,6 +1,6 @@
import hbs from "discourse/widgets/hbs-compiler"; import hbs from "discourse/widgets/hbs-compiler";
import { createWidget } from "discourse/widgets/widget"; import { createWidget } from "discourse/widgets/widget";
import roundTime from "discourse/plugins/discourse-calendar/lib/round-time"; import roundTime from "../lib/round-time";
export default createWidget("discourse-group-timezones-time-traveler", { export default createWidget("discourse-group-timezones-time-traveler", {
tagName: "div.group-timezones-time-traveler", tagName: "div.group-timezones-time-traveler",

View File

@ -1,6 +1,6 @@
import hbs from "discourse/widgets/hbs-compiler"; import hbs from "discourse/widgets/hbs-compiler";
import { createWidget } from "discourse/widgets/widget"; import { createWidget } from "discourse/widgets/widget";
import roundTime from "discourse/plugins/discourse-calendar/lib/round-time"; import roundTime from "../lib/round-time";
export default createWidget("discourse-group-timezones", { export default createWidget("discourse-group-timezones", {
tagName: "div.group-timezones", tagName: "div.group-timezones",

View File

@ -1,14 +1,14 @@
import I18n from "I18n"; import I18n from "I18n";
import TextLib, { emojiUnescape } from "discourse/lib/text"; import TextLib, { emojiUnescape } from "discourse/lib/text";
import { exportEntity } from "discourse/lib/export-csv"; import { exportEntity } from "discourse/lib/export-csv";
import cleanTitle from "discourse/plugins/discourse-calendar/lib/clean-title"; import cleanTitle from "../lib/clean-title";
import { dasherize } from "@ember/string"; import { dasherize } from "@ember/string";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import hbs from "discourse/widgets/hbs-compiler"; import hbs from "discourse/widgets/hbs-compiler";
import { createWidget } from "discourse/widgets/widget"; import { createWidget } from "discourse/widgets/widget";
import { routeAction } from "discourse/helpers/route-action"; import { routeAction } from "discourse/helpers/route-action";
import { buildParams, replaceRaw } from "../../lib/raw-event-helper"; import { buildParams, replaceRaw } from "../lib/raw-event-helper";
import { escapeExpression } from "discourse/lib/utilities"; import { escapeExpression } from "discourse/lib/utilities";
export default createWidget("discourse-post-event", { export default createWidget("discourse-post-event", {

View File

@ -150,7 +150,7 @@
} }
.fc-list-item-add-to-calendar { .fc-list-item-add-to-calendar {
color: var(--tertiary); color: var(--tertiary);
font-size: $font-down-1; font-size: var(--font-down-1);
} }
} }
@ -307,7 +307,7 @@ a.holiday {
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
color: inherit; color: inherit;
font-size: $font-down-1; font-size: var(--font-down-1);
.before { .before {
margin-right: auto; margin-right: auto;
@ -358,7 +358,7 @@ a.holiday {
} }
.offset { .offset {
font-size: $font-down-2; font-size: var(--font-down-2);
margin-left: 0.5em; margin-left: 0.5em;
} }
} }

View File

@ -13,7 +13,7 @@
} }
.name { .name {
font-size: $font-down-1; font-size: var(--font-down-1);
} }
&.from { &.from {
@ -69,7 +69,7 @@
border: 0; border: 0;
.name { .name {
font-size: $font-down-1; font-size: var(--font-down-1);
} }
} }
} }

View File

@ -8,7 +8,7 @@
.event-date { .event-date {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
font-size: $font-down-2; font-size: var(--font-down-2);
border: 1px solid var(--primary-medium); border: 1px solid var(--primary-medium);
background: none; background: none;
padding: 0 0.25em; padding: 0 0.25em;
@ -30,7 +30,7 @@
.header-title { .header-title {
.event-date { .event-date {
font-size: $font-down-4; font-size: var(--font-down-4);
color: var(--primary-medium); color: var(--primary-medium);
font-weight: normal; font-weight: normal;
padding: 0.25em; padding: 0.25em;

View File

@ -85,14 +85,14 @@ $interested: #fb985d;
.month { .month {
text-align: center; text-align: center;
color: red; color: red;
font-size: $font-down-1; font-size: var(--font-down-1);
text-transform: uppercase; text-transform: uppercase;
} }
.day { .day {
text-align: center; text-align: center;
font-weight: 500; font-weight: 500;
font-size: $font-up-2; font-size: var(--font-up-2);
} }
} }
@ -111,7 +111,7 @@ $interested: #fb985d;
display: flex; display: flex;
align-items: center; align-items: center;
color: var(--primary-medium); color: var(--primary-medium);
font-size: $font-down-1; font-size: var(--font-down-1);
margin: 0.25em 0; margin: 0.25em 0;
.separator { .separator {
@ -253,7 +253,7 @@ $interested: #fb985d;
border: 1px solid var(--primary-low); border: 1px solid var(--primary-low);
.d-icon { .d-icon {
font-size: $font-down-3; font-size: var(--font-down-3);
} }
} }
} }

View File

@ -124,6 +124,6 @@
} }
.fc-list-item-add-to-calendar { .fc-list-item-add-to-calendar {
color: var(--tertiary); color: var(--tertiary);
font-size: $font-down-1; font-size: var(--font-down-1);
} }
} }

View File

@ -6,7 +6,7 @@
background: none; background: none;
h2.discourse-calendar-title { h2.discourse-calendar-title {
font-size: $font-0; font-size: var(--font-0);
flex-wrap: nowrap; flex-wrap: nowrap;
max-width: 75%; max-width: 75%;
white-space: nowrap; white-space: nowrap;
@ -24,7 +24,7 @@
text-align: center; text-align: center;
padding: 0.25em; padding: 0.25em;
span { span {
font-size: $font-down-1; font-size: var(--font-down-1);
text-align: center; text-align: center;
padding: 0; padding: 0;
} }

View File

@ -24,7 +24,7 @@
} }
.event-invitees-status { .event-invitees-status {
font-size: $font-down-1; font-size: var(--font-down-1);
} }
.event-invitees .event-invitees-avatars .topic-invitee-avatar .avatar-flair { .event-invitees .event-invitees-avatars .topic-invitee-avatar .avatar-flair {

View File

@ -1,20 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
Discourse::Application.routes.draw do
mount ::DiscourseCalendar::Engine, at: "/"
get "/admin/plugins/calendar" => "admin/plugins#index", :constraints => StaffConstraint.new
get "/admin/discourse-calendar/holiday-regions/:region_code/holidays" =>
"admin/discourse_calendar/admin_holidays#index",
:constraints => StaffConstraint.new
post "/admin/discourse-calendar/holidays/disable" =>
"admin/discourse_calendar/admin_holidays#disable",
:constraints => StaffConstraint.new
delete "/admin/discourse-calendar/holidays/enable" =>
"admin/discourse_calendar/admin_holidays#enable",
:constraints => StaffConstraint.new
end
DiscoursePostEvent::Engine.routes.draw do DiscoursePostEvent::Engine.routes.draw do
get "/discourse-post-event/events" => "events#index", :format => :json get "/discourse-post-event/events" => "events#index", :format => :json
get "/discourse-post-event/events/:id" => "events#show" get "/discourse-post-event/events/:id" => "events#show"
@ -30,4 +15,17 @@ DiscoursePostEvent::Engine.routes.draw do
get "/upcoming-events" => "upcoming_events#index" get "/upcoming-events" => "upcoming_events#index"
end end
Discourse::Application.routes.draw { mount ::DiscoursePostEvent::Engine, at: "/" } Discourse::Application.routes.draw do
mount ::DiscourseCalendar::Engine, at: "/"
mount ::DiscoursePostEvent::Engine, at: "/"
scope constraints: StaffConstraint.new do
get "/admin/plugins/calendar" => "admin/plugins#index"
get "/admin/discourse-calendar/holiday-regions/:region_code/holidays" =>
"admin/discourse_calendar/admin_holidays#index"
post "/admin/discourse-calendar/holidays/disable" =>
"admin/discourse_calendar/admin_holidays#disable"
delete "/admin/discourse-calendar/holidays/enable" =>
"admin/discourse_calendar/admin_holidays#enable"
end
end

View File

@ -89,4 +89,3 @@ discourse_post_event:
disable_resorting_on_categories_enabled: disable_resorting_on_categories_enabled:
default: false default: false
client: true client: true

View File

@ -13,11 +13,11 @@ class CalendarSettingsValidator
hour = split.first hour = split.first
return false if hour.length != 2 return false if hour.length != 2
return false unless hour.to_i >= 0 && hour.to_i < 24 return false if hour.to_i < 0 || hour.to_i >= 24
minutes = split.second minutes = split.second
return false if minutes.length != 2 return false if minutes.length != 2
return false unless minutes.to_i >= 0 && minutes.to_i < 60 return false if minutes.to_i < 0 || minutes.to_i >= 60
true true
end end

View File

@ -1,10 +1,10 @@
{ {
"name": "discourse-calendar", "name": "discourse-calendar",
"version": "1.0.0", "version": "0.3.0",
"repository": "git@github.com:discourse/discourse-calendar.git", "repository": "https://github.com/discourse/discourse-calendar",
"author": "Discourse", "author": "Discourse",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"eslint-config-discourse": "^3.4.0" "eslint-config-discourse": "^3.5.0"
} }
} }

View File

@ -5,7 +5,6 @@
# version: 0.3 # version: 0.3
# author: Daniel Waterworth, Joffrey Jaffeux # author: Daniel Waterworth, Joffrey Jaffeux
# url: https://github.com/discourse/discourse-calendar # url: https://github.com/discourse/discourse-calendar
# transpile_js: true
libdir = File.join(File.dirname(__FILE__), "vendor/holidays/lib") libdir = File.join(File.dirname(__FILE__), "vendor/holidays/lib")
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

View File

@ -4,9 +4,6 @@ require "rails_helper"
require "securerandom" require "securerandom"
describe Post do describe Post do
Event ||= DiscoursePostEvent::Event
Invitee ||= DiscoursePostEvent::Invitee
before do before do
freeze_time freeze_time
Jobs.run_immediately! Jobs.run_immediately!
@ -58,8 +55,12 @@ describe Post do
end end
it "sends a post revision to going invitees" do it "sends a post revision to going invitees" do
Invitee.create_attendance!(going_user.id, post_1.id, :going) DiscoursePostEvent::Invitee.create_attendance!(going_user.id, post_1.id, :going)
Invitee.create_attendance!(interested_user.id, post_1.id, :interested) DiscoursePostEvent::Invitee.create_attendance!(
interested_user.id,
post_1.id,
:interested,
)
expect { expect {
revisor = PostRevisor.new(post_1) revisor = PostRevisor.new(post_1)
@ -78,8 +79,12 @@ describe Post do
before { event_1.event_dates.first.update_columns(starts_at: 5.hours.ago) } before { event_1.event_dates.first.update_columns(starts_at: 5.hours.ago) }
it "doesnt send a post revision to anyone" do it "doesnt send a post revision to anyone" do
Invitee.create_attendance!(going_user.id, post_1.id, :going) DiscoursePostEvent::Invitee.create_attendance!(going_user.id, post_1.id, :going)
Invitee.create_attendance!(interested_user.id, event_1.id, :interested) DiscoursePostEvent::Invitee.create_attendance!(
interested_user.id,
event_1.id,
:interested,
)
expect { expect {
revisor = PostRevisor.new(event_1.post) revisor = PostRevisor.new(event_1.post)
@ -104,8 +109,12 @@ describe Post do
original_ends_at: nil, original_ends_at: nil,
) )
Invitee.create_attendance!(going_user.id, event_1.id, :going) DiscoursePostEvent::Invitee.create_attendance!(going_user.id, event_1.id, :going)
Invitee.create_attendance!(interested_user.id, event_1.id, :interested) DiscoursePostEvent::Invitee.create_attendance!(
interested_user.id,
event_1.id,
:interested,
)
event_1.reload event_1.reload
@ -124,7 +133,10 @@ describe Post do
it "it removes status from every invitees" do it "it removes status from every invitees" do
expect(event_1.invitees.pluck(:status)).to match_array( expect(event_1.invitees.pluck(:status)).to match_array(
[Invitee.statuses[:going], Invitee.statuses[:interested]], [
DiscoursePostEvent::Invitee.statuses[:going],
DiscoursePostEvent::Invitee.statuses[:interested],
],
) )
event_1.update_with_params!(original_ends_at: Time.now) event_1.update_with_params!(original_ends_at: Time.now)
@ -158,12 +170,12 @@ describe Post do
context "when updating status to private" do context "when updating status to private" do
it "it changes the status and force invitees" do it "it changes the status and force invitees" do
expect(event_1.raw_invitees).to eq(["trust_level_0"]) expect(event_1.raw_invitees).to eq(["trust_level_0"])
expect(event_1.status).to eq(Event.statuses[:public]) expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:public])
event_1.update_with_params!(status: Event.statuses[:private]) event_1.update_with_params!(status: DiscoursePostEvent::Event.statuses[:private])
expect(event_1.raw_invitees).to eq([]) expect(event_1.raw_invitees).to eq([])
expect(event_1.status).to eq(Event.statuses[:private]) expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:private])
end end
end end
end end
@ -452,7 +464,7 @@ describe Post do
Fabricate( Fabricate(
:event, :event,
post: post_1, post: post_1,
status: Event.statuses[:private], status: DiscoursePostEvent::Event.statuses[:private],
raw_invitees: [group_1.name], raw_invitees: [group_1.name],
original_starts_at: 3.hours.ago, original_starts_at: 3.hours.ago,
original_ends_at: nil, original_ends_at: nil,
@ -464,7 +476,7 @@ describe Post do
Fabricate( Fabricate(
:event, :event,
post: post_1, post: post_1,
status: Event.statuses[:private], status: DiscoursePostEvent::Event.statuses[:private],
raw_invitees: [group_1.name], raw_invitees: [group_1.name],
recurrence: "FREQ=WEEKLY;BYDAY=MO", recurrence: "FREQ=WEEKLY;BYDAY=MO",
original_starts_at: 2.hours.from_now, original_starts_at: 2.hours.from_now,
@ -506,12 +518,12 @@ describe Post do
context "when updating status to public" do context "when updating status to public" do
it "it changes the status and force invitees" do it "it changes the status and force invitees" do
expect(event_1.raw_invitees).to eq([group_1.name]) expect(event_1.raw_invitees).to eq([group_1.name])
expect(event_1.status).to eq(Event.statuses[:private]) expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:private])
event_1.update_with_params!(status: Event.statuses[:public]) event_1.update_with_params!(status: DiscoursePostEvent::Event.statuses[:public])
expect(event_1.raw_invitees).to eq(["trust_level_0"]) expect(event_1.raw_invitees).to eq(["trust_level_0"])
expect(event_1.status).to eq(Event.statuses[:public]) expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:public])
end end
end end

View File

@ -19,16 +19,19 @@ describe Jobs::DiscoursePostEventBulkInvite do
context "with invalid params" do context "with invalid params" do
context "with no invitees given" do context "with no invitees given" do
it "raises an invalid parameters errors" do it "raises an invalid parameters errors" do
expect { subject.execute(current_user_id: 1, event_id: 1) }.to raise_error( expect {
Discourse::InvalidParameters, Jobs::DiscoursePostEventBulkInvite.new.execute(current_user_id: 1, event_id: 1)
) }.to raise_error(Discourse::InvalidParameters)
end end
end end
context "with no current_user_id given" do context "with no current_user_id given" do
it "raises an invalid parameters errors" do it "raises an invalid parameters errors" do
expect { expect {
subject.execute(invitees: [{ identifier: "bob", attendance: "going" }], event_id: 1) Jobs::DiscoursePostEventBulkInvite.new.execute(
invitees: [{ identifier: "bob", attendance: "going" }],
event_id: 1,
)
}.to raise_error(Discourse::InvalidParameters) }.to raise_error(Discourse::InvalidParameters)
end end
end end
@ -36,7 +39,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
context "with no event_id given" do context "with no event_id given" do
it "raises an invalid parameters errors" do it "raises an invalid parameters errors" do
expect { expect {
subject.execute( Jobs::DiscoursePostEventBulkInvite.new.execute(
invitees: [{ identifier: "bob", attendance: "going" }], invitees: [{ identifier: "bob", attendance: "going" }],
current_user_id: 1, current_user_id: 1,
) )
@ -51,7 +54,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
it "raises an error" do it "raises an error" do
expect { expect {
subject.execute( Jobs::DiscoursePostEventBulkInvite.new.execute(
event_id: post_event_1.id, event_id: post_event_1.id,
invitees: [{ identifier: "bob", attendance: "going" }], invitees: [{ identifier: "bob", attendance: "going" }],
current_user_id: lurker.id, current_user_id: lurker.id,
@ -101,7 +104,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
) )
.once .once
subject.execute(valid_params) Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
invitee_klass = DiscoursePostEvent::Invitee invitee_klass = DiscoursePostEvent::Invitee
@ -117,7 +120,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
end end
it "removes the invitee if set to unknown" do it "removes the invitee if set to unknown" do
subject.execute(valid_params) Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
invitee_klass = DiscoursePostEvent::Invitee invitee_klass = DiscoursePostEvent::Invitee
@ -129,7 +132,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
invitee_klass.statuses[:not_going], invitee_klass.statuses[:not_going],
) )
subject.execute( Jobs::DiscoursePostEventBulkInvite.new.execute(
event_id: post_event_1.id, event_id: post_event_1.id,
invitees: [{ "identifier" => group_1.name, "attendance" => "unknown" }], invitees: [{ "identifier" => group_1.name, "attendance" => "unknown" }],
current_user_id: user_1.id, current_user_id: user_1.id,
@ -149,7 +152,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
invitee_klass = DiscoursePostEvent::Invitee invitee_klass = DiscoursePostEvent::Invitee
subject.execute( Jobs::DiscoursePostEventBulkInvite.new.execute(
event_id: post_event_1.id, event_id: post_event_1.id,
invitees: [{ "identifier" => group_1.name }], invitees: [{ "identifier" => group_1.name }],
current_user_id: user_1.id, current_user_id: user_1.id,
@ -183,7 +186,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
) )
.once .once
subject.execute(valid_params) Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
invitee_klass = DiscoursePostEvent::Invitee invitee_klass = DiscoursePostEvent::Invitee

View File

@ -19,7 +19,7 @@ describe Jobs::DiscoursePostEventBumpTopic do
context "when params are present" do context "when params are present" do
it "creates an auto-bump topic timer" do it "creates an auto-bump topic timer" do
freeze_time freeze_time
subject.execute(topic_id: topic_1.id, date: "2019-12-10 5:00") Jobs::DiscoursePostEventBumpTopic.new.execute(topic_id: topic_1.id, date: "2019-12-10 5:00")
timer = TopicTimer.find_by(topic: topic_1) timer = TopicTimer.find_by(topic: topic_1)
expect(timer.status_type).to eq(TopicTimer.types[:bump]) expect(timer.status_type).to eq(TopicTimer.types[:bump])
@ -29,10 +29,12 @@ describe Jobs::DiscoursePostEventBumpTopic do
context "when the topic_id param is missing" do context "when the topic_id param is missing" do
it "does not throw an error if the date param is present" do it "does not throw an error if the date param is present" do
expect { subject.execute(date: "2019-12-10 5:00") }.not_to raise_error expect {
Jobs::DiscoursePostEventBumpTopic.new.execute(date: "2019-12-10 5:00")
}.not_to raise_error
end end
it "does not throw an error if the date param is missing" do it "does not throw an error if the date param is missing" do
expect { subject.execute({}) }.not_to raise_error expect { Jobs::DiscoursePostEventBumpTopic.new.execute({}) }.not_to raise_error
end end
end end
end end

View File

@ -3,8 +3,6 @@
require "rails_helper" require "rails_helper"
describe Jobs::DiscoursePostEventSendReminder do describe Jobs::DiscoursePostEventSendReminder do
Invitee ||= DiscoursePostEvent::Invitee
let(:admin_1) { Fabricate(:user, admin: true) } let(:admin_1) { Fabricate(:user, admin: true) }
let(:going_user) { Fabricate(:user) } let(:going_user) { Fabricate(:user) }
let(:interested_user) { Fabricate(:user) } let(:interested_user) { Fabricate(:user) }
@ -16,12 +14,20 @@ describe Jobs::DiscoursePostEventSendReminder do
let(:reminders) { "notification.5.minutes" } let(:reminders) { "notification.5.minutes" }
def init_invitees def init_invitees
Invitee.create_attendance!(going_user.id, event_1.id, :going) DiscoursePostEvent::Invitee.create_attendance!(going_user.id, event_1.id, :going)
Invitee.create_attendance!(interested_user.id, event_1.id, :interested) DiscoursePostEvent::Invitee.create_attendance!(interested_user.id, event_1.id, :interested)
Invitee.create_attendance!(not_going_user.id, event_1.id, :not_going) DiscoursePostEvent::Invitee.create_attendance!(not_going_user.id, event_1.id, :not_going)
Invitee.create_attendance!(going_user_unread_notification.id, event_1.id, :going) DiscoursePostEvent::Invitee.create_attendance!(
Invitee.create_attendance!(going_user_read_notification.id, event_1.id, :going) going_user_unread_notification.id,
Invitee.create_attendance!(visited_going_user.id, event_1.id, :going) event_1.id,
:going,
)
DiscoursePostEvent::Invitee.create_attendance!(
going_user_read_notification.id,
event_1.id,
:going,
)
DiscoursePostEvent::Invitee.create_attendance!(visited_going_user.id, event_1.id, :going)
[ [
going_user, going_user,
@ -52,9 +58,13 @@ describe Jobs::DiscoursePostEventSendReminder do
describe "#execute" do describe "#execute" do
context "with invalid params" do context "with invalid params" do
it "raises an invalid parameters errors" do it "raises an invalid parameters errors" do
expect { subject.execute(event_id: 1) }.to raise_error(Discourse::InvalidParameters) expect { Jobs::DiscoursePostEventSendReminder.new.execute(event_id: 1) }.to raise_error(
Discourse::InvalidParameters,
)
expect { subject.execute(reminder: "foo") }.to raise_error(Discourse::InvalidParameters) expect { Jobs::DiscoursePostEventSendReminder.new.execute(reminder: "foo") }.to raise_error(
Discourse::InvalidParameters,
)
end end
end end
@ -66,7 +76,12 @@ describe Jobs::DiscoursePostEventSendReminder do
it "is not erroring when post is already deleted" do it "is not erroring when post is already deleted" do
post_1.delete post_1.delete
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to raise_error expect {
Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
}.not_to raise_error
end end
end end
@ -87,32 +102,47 @@ describe Jobs::DiscoursePostEventSendReminder do
it "creates a new notification for going user" do it "creates a new notification for going user" do
expect(going_user.unread_notifications).to eq(0) expect(going_user.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change { expect {
going_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
}.by(1) event_id: event_1.id,
reminder: reminders,
)
}.to change { going_user.reload.unread_notifications }.by(1)
end end
it "doesnt create a new notification for not going user" do it "doesnt create a new notification for not going user" do
expect(not_going_user.unread_notifications).to eq(0) expect(not_going_user.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change { expect {
not_going_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
} event_id: event_1.id,
reminder: reminders,
)
}.not_to change { not_going_user.reload.unread_notifications }
end end
it "doesnt create a new notification if theres already one" do it "doesnt create a new notification if theres already one" do
expect(going_user_unread_notification.unread_notifications).to eq(1) expect(going_user_unread_notification.unread_notifications).to eq(1)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change { expect {
going_user_unread_notification.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
} event_id: event_1.id,
reminder: reminders,
)
}.not_to change { going_user_unread_notification.reload.unread_notifications }
end end
it "delete previous notifications before creating a new one" do it "delete previous notifications before creating a new one" do
subject.execute(event_id: event_1.id, reminder: reminders) Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
going_user.notifications.update_all(read: true) going_user.notifications.update_all(read: true)
subject.execute(event_id: event_1.id, reminder: reminders) Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
expect( expect(
going_user going_user
@ -149,40 +179,58 @@ describe Jobs::DiscoursePostEventSendReminder do
it "creates a new notification for going user" do it "creates a new notification for going user" do
expect(going_user.reload.unread_notifications).to eq(0) expect(going_user.reload.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change { expect {
going_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
}.by(1) event_id: event_1.id,
reminder: reminders,
)
}.to change { going_user.reload.unread_notifications }.by(1)
end end
it "creates a new notification for interested user" do it "creates a new notification for interested user" do
expect(interested_user.reload.unread_notifications).to eq(0) expect(interested_user.reload.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change { expect {
interested_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
}.by(1) event_id: event_1.id,
reminder: reminders,
)
}.to change { interested_user.reload.unread_notifications }.by(1)
end end
it "doesnt create a new notification for not going user" do it "doesnt create a new notification for not going user" do
expect(not_going_user.unread_notifications).to eq(0) expect(not_going_user.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change { expect {
not_going_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
} event_id: event_1.id,
reminder: reminders,
)
}.not_to change { not_going_user.reload.unread_notifications }
end end
it "doesnt create a new notification if theres already one" do it "doesnt create a new notification if theres already one" do
expect(going_user_unread_notification.unread_notifications).to eq(1) expect(going_user_unread_notification.unread_notifications).to eq(1)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change { expect {
going_user_unread_notification.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
} event_id: event_1.id,
reminder: reminders,
)
}.not_to change { going_user_unread_notification.reload.unread_notifications }
end end
it "deletes previous notifications when creating a new one" do it "deletes previous notifications when creating a new one" do
subject.execute(event_id: event_1.id, reminder: reminders) Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
going_user.notifications.update_all(read: true) going_user.notifications.update_all(read: true)
subject.execute(event_id: event_1.id, reminder: reminders) Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
expect( expect(
going_user going_user
@ -205,7 +253,10 @@ describe Jobs::DiscoursePostEventSendReminder do
}.to_json, }.to_json,
) )
subject.execute(event_id: event_1.id, reminder: reminders) Jobs::DiscoursePostEventSendReminder.new.execute(
event_id: event_1.id,
reminder: reminders,
)
messages = messages =
Notification.where( Notification.where(
user: going_user, user: going_user,
@ -221,9 +272,12 @@ describe Jobs::DiscoursePostEventSendReminder do
it "doesnt create a new notification for visiting user" do it "doesnt create a new notification for visiting user" do
expect(visited_going_user.unread_notifications).to eq(0) expect(visited_going_user.unread_notifications).to eq(0)
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change { expect {
visited_going_user.reload.unread_notifications Jobs::DiscoursePostEventSendReminder.new.execute(
} event_id: event_1.id,
reminder: reminders,
)
}.not_to change { visited_going_user.reload.unread_notifications }
end end
end end
end end

View File

@ -23,7 +23,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
frenchy frenchy
freeze_time Time.zone.local(2019, 8, 1) freeze_time Time.zone.local(2019, 8, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.where(user_id: frenchy.id).count).to eq(0) expect(CalendarEvent.where(user_id: frenchy.id).count).to eq(0)
end end
@ -31,7 +31,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "adds all holidays in the next 6 months" do it "adds all holidays in the next 6 months" do
frenchy frenchy
freeze_time Time.zone.local(2019, 8, 1) freeze_time Time.zone.local(2019, 8, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq( expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq(
[ [
@ -47,7 +47,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "checks for observed dates" do it "checks for observed dates" do
aussie aussie
freeze_time Time.zone.local(2020, 1, 20) freeze_time Time.zone.local(2020, 1, 20)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
# The "Australia Day" is always observed on a Monday # The "Australia Day" is always observed on a Monday
expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq( expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq(
@ -62,7 +62,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "only checks for holidays during business days" do it "only checks for holidays during business days" do
frenchy frenchy
freeze_time Time.zone.local(2019, 7, 1) freeze_time Time.zone.local(2019, 7, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
# The "Fête Nationale" is on July 14th but it's on a Sunday in 2019 # The "Fête Nationale" is on July 14th but it's on a Sunday in 2019
expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq( expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq(
@ -106,7 +106,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
}, },
) )
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq([]) expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq([])
end end
@ -114,14 +114,14 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "cleans up holidays from deactivated/silenced/suspended users" do it "cleans up holidays from deactivated/silenced/suspended users" do
frenchy frenchy
freeze_time Time.zone.local(2019, 8, 1) freeze_time Time.zone.local(2019, 8, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.exists?(username: frenchy.username)).to eq(true) expect(CalendarEvent.exists?(username: frenchy.username)).to eq(true)
frenchy.active = false frenchy.active = false
frenchy.save! frenchy.save!
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.exists?(username: frenchy.username)).to eq(false) expect(CalendarEvent.exists?(username: frenchy.username)).to eq(false)
end end
@ -138,7 +138,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "only adds enabled holidays to the calendar" do it "only adds enabled holidays to the calendar" do
frenchy frenchy
freeze_time Time.zone.local(2019, 7, 1) freeze_time Time.zone.local(2019, 7, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq( expect(CalendarEvent.pluck(:region, :description, :start_date, :username)).to eq(
[ [
@ -152,7 +152,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "doesn't add disabled holidays to the calendar" do it "doesn't add disabled holidays to the calendar" do
frenchy frenchy
freeze_time Time.zone.local(2019, 7, 1) freeze_time Time.zone.local(2019, 7, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
expect(CalendarEvent.pluck(:description)).not_to include(france_assomption[:holiday_name]) expect(CalendarEvent.pluck(:description)).not_to include(france_assomption[:holiday_name])
expect(CalendarEvent.pluck(:description)).not_to include(france_toussaint[:holiday_name]) expect(CalendarEvent.pluck(:description)).not_to include(france_toussaint[:holiday_name])
@ -163,7 +163,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "uses the user TZ when available" do it "uses the user TZ when available" do
frenchy.user_option.update!(timezone: "Europe/Paris") frenchy.user_option.update!(timezone: "Europe/Paris")
freeze_time Time.zone.local(2019, 8, 1) freeze_time Time.zone.local(2019, 8, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
calendar_event = CalendarEvent.first calendar_event = CalendarEvent.first
expect(calendar_event.region).to eq("fr") expect(calendar_event.region).to eq("fr")
@ -181,7 +181,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
it "uses the user TZ when available" do it "uses the user TZ when available" do
frenchy.user_option.update!(timezone: "Europe/Paris") frenchy.user_option.update!(timezone: "Europe/Paris")
freeze_time Time.zone.local(2019, 8, 1) freeze_time Time.zone.local(2019, 8, 1)
subject.execute(nil) DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
calendar_event = CalendarEvent.first calendar_event = CalendarEvent.first
expect(calendar_event.region).to eq("fr") expect(calendar_event.region).to eq("fr")

View File

@ -27,7 +27,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
raw: "Summer ☀️ Solstice [date=#{Date.current.year + 1}-06-21]", raw: "Summer ☀️ Solstice [date=#{Date.current.year + 1}-06-21]",
) )
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post_with_one_date.id)).to eq(false) expect(Post.exists?(post_with_one_date.id)).to eq(false)
expect(Post.exists?(post_with_two_dates.id)).to eq(false) expect(Post.exists?(post_with_two_dates.id)).to eq(false)
@ -53,7 +53,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
description: "Matariki", description: "Matariki",
) )
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(CalendarEvent.exists?(matariki.id)).to eq(true) expect(CalendarEvent.exists?(matariki.id)).to eq(true)
end end
@ -62,7 +62,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
post = create_post(raw: "Discourse 💬 Launch 🚀 on [date=2013-02-05]") post = create_post(raw: "Discourse 💬 Launch 🚀 on [date=2013-02-05]")
CalendarEvent.create!(topic: post.topic, post: post, start_date: Date.new(2013, 2, 5)) CalendarEvent.create!(topic: post.topic, post: post, start_date: Date.new(2013, 2, 5))
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post.id)).to eq(true) expect(Post.exists?(post.id)).to eq(true)
end end
@ -74,7 +74,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
raw: 'WWW - Weekly Wednesday Watercooler [date=2022-01-05 recurring="1.week"] 🐸', raw: 'WWW - Weekly Wednesday Watercooler [date=2022-01-05 recurring="1.week"] 🐸',
) )
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post.id)).to eq(true) expect(Post.exists?(post.id)).to eq(true)
end end
@ -88,7 +88,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
calendar_topic.update!(archived: true) calendar_topic.update!(archived: true)
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post.id)).to eq(true) expect(Post.exists?(post.id)).to eq(true)
end end
@ -102,7 +102,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
calendar_topic.update!(closed: true) calendar_topic.update!(closed: true)
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post.id)).to eq(true) expect(Post.exists?(post.id)).to eq(true)
end end
@ -153,7 +153,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
freeze_time Time.parse("2018-10-01 00:00:00 UTC") freeze_time Time.parse("2018-10-01 00:00:00 UTC")
subject.execute(nil) DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
expect(Post.exists?(post.id)).to eq(false) expect(Post.exists?(post.id)).to eq(false)
expect(Post.exists?(reply_without_event.id)).to eq(false) expect(Post.exists?(reply_without_event.id)).to eq(false)

View File

@ -17,12 +17,12 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]' raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic) post = create_post(raw: raw, topic: calendar_post.topic)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
expect(DiscourseCalendar.users_on_holiday).to eq([post.user.username]) expect(DiscourseCalendar.users_on_holiday).to eq([post.user.username])
freeze_time Time.utc(2018, 6, 7, 18, 40) freeze_time Time.utc(2018, 6, 7, 18, 40)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
expect(DiscourseCalendar.users_on_holiday).to eq([]) expect(DiscourseCalendar.users_on_holiday).to eq([])
end end
@ -36,7 +36,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
raw2 = 'Rome [date="2018-06-05"]' # the whole day raw2 = 'Rome [date="2018-06-05"]' # the whole day
post2 = create_post(raw: raw2, topic: calendar_post.topic) post2 = create_post(raw: raw2, topic: calendar_post.topic)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
expect( expect(
UserCustomField.exists?( UserCustomField.exists?(
name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD, name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD,
@ -51,7 +51,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
).to be_truthy ).to be_truthy
freeze_time Time.utc(2018, 6, 6, 10, 00) freeze_time Time.utc(2018, 6, 6, 10, 00)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
expect( expect(
UserCustomField.exists?( UserCustomField.exists?(
name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD, name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD,
@ -66,7 +66,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
).to be_falsey ).to be_falsey
freeze_time Time.utc(2018, 6, 7, 10, 00) freeze_time Time.utc(2018, 6, 7, 10, 00)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
expect( expect(
UserCustomField.exists?( UserCustomField.exists?(
name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD, name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD,
@ -88,7 +88,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]' raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic) post = create_post(raw: raw, topic: calendar_post.topic)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
status = post.user.user_status status = post.user.user_status
@ -105,7 +105,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]' raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic) post = create_post(raw: raw, topic: calendar_post.topic)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
expect(post.user.user_status).to be_nil expect(post.user.user_status).to be_nil
@ -120,7 +120,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
custom_status = { description: "I am working on holiday", emoji: "construction_worker_man" } custom_status = { description: "I am working on holiday", emoji: "construction_worker_man" }
post.user.set_status!(custom_status[:description], custom_status[:emoji]) post.user.set_status!(custom_status[:description], custom_status[:emoji])
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
status = post.user.user_status status = post.user.user_status
@ -151,7 +151,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
) )
freeze_time tomorrow + 2.day freeze_time tomorrow + 2.day
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
status = post.user.user_status status = post.user.user_status
@ -168,7 +168,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]' raw = 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-06-06" time="10:20:00"]'
post = create_post(raw: raw, topic: calendar_post.topic) post = create_post(raw: raw, topic: calendar_post.topic)
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
expect(post.user.user_status).to be_present expect(post.user.user_status).to be_present
@ -180,7 +180,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
{ raw: 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-12-10" time="10:20:00"]' }, { raw: 'Rome [date="2018-06-05" time="10:20:00"] to [date="2018-12-10" time="10:20:00"]' },
revised_at: Time.now, revised_at: Time.now,
) )
subject.execute(nil) DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
post.user.reload post.user.reload
expect(post.user.user_status).to be_present expect(post.user.user_status).to be_present

View File

@ -5,7 +5,7 @@ describe DiscoursePostEvent::EventFinder do
fab!(:current_user) { Fabricate(:user) } fab!(:current_user) { Fabricate(:user) }
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
subject { DiscoursePostEvent::EventFinder } subject(:finder) { DiscoursePostEvent::EventFinder }
before do before do
Jobs.run_immediately! Jobs.run_immediately!
@ -24,7 +24,7 @@ describe DiscoursePostEvent::EventFinder do
let!(:event) { Fabricate(:event, post: post1) } let!(:event) { Fabricate(:event, post: post1) }
it "returns the event" do it "returns the event" do
expect(subject.search(current_user)).to match_array([event]) expect(finder.search(current_user)).to match_array([event])
end end
end end
@ -41,7 +41,7 @@ describe DiscoursePostEvent::EventFinder do
let!(:event) { Fabricate(:event, post: post1) } let!(:event) { Fabricate(:event, post: post1) }
it "returns the event" do it "returns the event" do
expect(subject.search(current_user)).to match_array([event]) expect(finder.search(current_user)).to match_array([event])
end end
end end
@ -59,7 +59,7 @@ describe DiscoursePostEvent::EventFinder do
let!(:event) { Fabricate(:event, post: post1) } let!(:event) { Fabricate(:event, post: post1) }
it "doesnt return the event" do it "doesnt return the event" do
expect(subject.search(current_user)).to match_array([]) expect(finder.search(current_user)).to match_array([])
end end
end end
@ -83,7 +83,7 @@ describe DiscoursePostEvent::EventFinder do
let!(:event2) { Fabricate(:event, post: post2) } let!(:event2) { Fabricate(:event, post: post2) }
it "returns only the specified event" do it "returns only the specified event" do
expect(subject.search(current_user, { post_id: post2.id })).to match_array([event2]) expect(finder.search(current_user, { post_id: post2.id })).to match_array([event2])
end end
end end
@ -122,10 +122,8 @@ describe DiscoursePostEvent::EventFinder do
end end
it "returns correct events" do it "returns correct events" do
expect(subject.search(current_user, { expired: false })).to eq( expect(finder.search(current_user, { expired: false })).to eq([current_event, future_event])
[current_event, future_event], expect(finder.search(current_user, { expired: true })).to eq([older_event, old_event])
)
expect(subject.search(current_user, { expired: true })).to eq([older_event, old_event])
end end
context "when a past event has been edited to be in the future" do context "when a past event has been edited to be in the future" do
@ -140,10 +138,10 @@ describe DiscoursePostEvent::EventFinder do
end end
it "returns correct events" do it "returns correct events" do
expect(subject.search(current_user, { expired: false })).to eq( expect(finder.search(current_user, { expired: false })).to eq(
[current_event, future_event], [current_event, future_event],
) )
expect(subject.search(current_user, { expired: true })).to eq([older_event, old_event]) expect(finder.search(current_user, { expired: true })).to eq([older_event, old_event])
end end
end end
@ -159,10 +157,10 @@ describe DiscoursePostEvent::EventFinder do
end end
it "returns correct events" do it "returns correct events" do
expect(subject.search(current_user, { expired: false })).to eq( expect(finder.search(current_user, { expired: false })).to eq(
[current_event, future_event], [current_event, future_event],
) )
expect(subject.search(current_user, { expired: true })).to eq([older_event, old_event]) expect(finder.search(current_user, { expired: true })).to eq([older_event, old_event])
end end
end end
end end

View File

@ -7,17 +7,17 @@ def build_post(user, raw)
end end
describe DiscoursePostEvent::EventParser do describe DiscoursePostEvent::EventParser do
subject { DiscoursePostEvent::EventParser } subject(:parser) { DiscoursePostEvent::EventParser }
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
it "works with no event" do it "works with no event" do
events = subject.extract_events(build_post(user, "this could be a nice event")) events = parser.extract_events(build_post(user, "this could be a nice event"))
expect(events.length).to eq(0) expect(events.length).to eq(0)
end end
it "finds one event" do it "finds one event" do
events = subject.extract_events(build_post(user, '[event start="foo" end="bar"]\n[/event]')) events = parser.extract_events(build_post(user, '[event start="foo" end="bar"]\n[/event]'))
expect(events.length).to eq(1) expect(events.length).to eq(1)
end end
@ -30,33 +30,32 @@ describe DiscoursePostEvent::EventParser do
[/event] [/event]
TXT TXT
events = subject.extract_events(post_event) events = parser.extract_events(post_event)
expect(events.length).to eq(2) expect(events.length).to eq(2)
end end
it "parses options" do it "parses options" do
events = subject.extract_events(build_post(user, '[event start="foo" end="bar"]\n[/event]')) events = parser.extract_events(build_post(user, '[event start="foo" end="bar"]\n[/event]'))
expect(events[0][:start]).to eq("foo") expect(events[0][:start]).to eq("foo")
expect(events[0][:end]).to eq("bar") expect(events[0][:end]).to eq("bar")
end end
it "works with escaped string" do it "works with escaped string" do
events = events =
subject.extract_events( parser.extract_events(
build_post(user, "I am going to get that fixed.\n\n[event start=\"bar\"]\n[/event]"), build_post(user, "I am going to get that fixed.\n\n[event start=\"bar\"]\n[/event]"),
) )
expect(events[0][:start]).to eq("bar") expect(events[0][:start]).to eq("bar")
end end
it "parses options where value has spaces" do it "parses options where value has spaces" do
events = events = parser.extract_events(build_post(user, '[event start="foo" name="bar baz"]\n[/event]'))
subject.extract_events(build_post(user, '[event start="foo" name="bar baz"]\n[/event]'))
expect(events[0][:name]).to eq("bar baz") expect(events[0][:name]).to eq("bar baz")
end end
it "doesnt parse invalid options" do it "doesnt parse invalid options" do
events = events =
subject.extract_events( parser.extract_events(
build_post( build_post(
user, user,
"I am going to get that fixed.\n\n[event start=\"foo\" something=\"bar\"]\n[/event]", "I am going to get that fixed.\n\n[event start=\"foo\" something=\"bar\"]\n[/event]",
@ -65,7 +64,7 @@ describe DiscoursePostEvent::EventParser do
expect(events[0][:something]).to be(nil) expect(events[0][:something]).to be(nil)
events = events =
subject.extract_events( parser.extract_events(
build_post(user, "I am going to get that fixed.\n\n[event something=\"bar\"]\n[/event]"), build_post(user, "I am going to get that fixed.\n\n[event something=\"bar\"]\n[/event]"),
) )
expect(events).to eq([]) expect(events).to eq([])
@ -79,7 +78,7 @@ describe DiscoursePostEvent::EventParser do
``` ```
TXT TXT
events = subject.extract_events(post_event) events = parser.extract_events(post_event)
expect(events).to eq([]) expect(events).to eq([])
end end
@ -89,13 +88,13 @@ describe DiscoursePostEvent::EventParser do
[event start="2020"][/event] [event start="2020"][/event]
TXT TXT
events = subject.extract_events(post_event) events = parser.extract_events(post_event)
expect(events).to eq([]) expect(events).to eq([])
end end
it "doesnt escape event name" do it "doesnt escape event name" do
events = events =
subject.extract_events( parser.extract_events(
build_post(user, '[event start="foo" name="bar <script> baz"]\n[/event]'), build_post(user, '[event start="foo" name="bar <script> baz"]\n[/event]'),
) )
expect(events[0][:name]).to eq("bar <script> baz") expect(events[0][:name]).to eq("bar <script> baz")
@ -110,7 +109,7 @@ describe DiscoursePostEvent::EventParser do
[/event] [/event]
TXT TXT
events = subject.extract_events(post_event) events = parser.extract_events(post_event)
expect(events[0][:"foo-bar"]).to eq("1") expect(events[0][:"foo-bar"]).to eq("1")
expect(events[0][:"bar"]).to eq("2") expect(events[0][:"bar"]).to eq("2")
end end
@ -121,7 +120,7 @@ describe DiscoursePostEvent::EventParser do
[/event] [/event]
TXT TXT
events = subject.extract_events(post_event) events = parser.extract_events(post_event)
expect(events[0][:"baz"]).to eq(nil) expect(events[0][:"baz"]).to eq(nil)
end end
end end

View File

@ -5,7 +5,7 @@ require "rails_helper"
describe UserSerializer do describe UserSerializer do
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
subject { described_class.new(user, scope: guardian).as_json } subject(:json) { described_class.new(user, scope: guardian).as_json }
before do before do
SiteSetting.calendar_enabled = true SiteSetting.calendar_enabled = true
@ -16,7 +16,7 @@ describe UserSerializer do
fab!(:guardian) { Fabricate(:user).guardian } fab!(:guardian) { Fabricate(:user).guardian }
it "does not return user region" do it "does not return user region" do
expect(subject[:user][:custom_fields]).to be_blank expect(json[:user][:custom_fields]).to be_blank
end end
end end
@ -24,7 +24,7 @@ describe UserSerializer do
fab!(:guardian) { user.guardian } fab!(:guardian) { user.guardian }
it "returns user region" do it "returns user region" do
expect(subject[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk") expect(json[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk")
end end
end end
@ -32,7 +32,7 @@ describe UserSerializer do
fab!(:guardian) { Fabricate(:admin).guardian } fab!(:guardian) { Fabricate(:admin).guardian }
it "returns user region" do it "returns user region" do
expect(subject[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk") expect(json[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk")
end end
end end
end end

View File

@ -1,71 +1,50 @@
import componentTest, { import { module, test } from "qunit";
setupRenderingTest, import { setupRenderingTest } from "discourse/tests/helpers/component-test";
} from "discourse/tests/helpers/component-test"; import { render } from "@ember/test-helpers";
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers"; import { hbs } from "ember-cli-htmlbars";
import hbs from "htmlbars-inline-precompile";
discourseModule( module("Integration | Component | admin-holidays-list-item", function (hooks) {
"Integration | Component | admin-holidays-list-item", setupRenderingTest(hooks);
function (hooks) {
setupRenderingTest(hooks);
const template = hbs`{{admin-holidays-list-item test("when a holiday is disabled, it displays an enable button and adds a disabled CSS class", async function (assert) {
holiday=holiday this.set("holiday", {
region_code=region_code date: "2022-01-01",
isHolidayDisabled=holiday.disabled name: "New Year's Day",
}}`; disabled: true,
});
this.set("region_code", "sg");
componentTest( await render(hbs`
"when a holiday is disabled, it displays an enable button and adds a disabled CSS class", <AdminHolidaysListItem
{ @holiday={{this.holiday}}
template, @region_code={{this.region_code}}
@isHolidayDisabled={{this.holiday.disabled}}
/>
`);
beforeEach() { assert.dom("button").hasText("Enable", "it displays an enable button");
this.set("holiday", { assert.dom("tr").hasClass("disabled", "it adds a 'disabled' CSS class");
date: "2022-01-01", });
name: "New Year's Day",
disabled: true,
});
this.set("region_code", "sg");
},
async test(assert) { test("when a holiday is enabled, it displays a disable button and does not add a disabled CSS class", async function (assert) {
assert.equal( this.set("holiday", {
query("button").innerText.trim(), date: "2022-01-01",
"Enable", name: "New Year's Day",
"it displays an enable button" disabled: false,
); });
assert.ok(query(".disabled"), "it adds a 'disabled' CSS class"); this.set("region_code", "au");
},
}
);
componentTest( await render(hbs`
"when a holiday is enabled, it displays a disable button and does not add a disabled CSS class", <AdminHolidaysListItem
{ @holiday={{this.holiday}}
template, @region_code={{this.region_code}}
@isHolidayDisabled={{this.holiday.disabled}}
/>
`);
beforeEach() { assert.dom("button").hasText("Disable", "it displays a disable button");
this.set("holiday", { assert
date: "2022-01-01", .dom("tr")
name: "New Year's Day", .doesNotHaveClass("disabled", "it does not add a 'disabled' CSS class");
disabled: false, });
}); });
this.set("region_code", "au");
},
async test(assert) {
assert.equal(
query("button").innerText.trim(),
"Disable",
"it displays a disable button"
);
assert.notOk(
query(".disabled"),
"it does not add a 'disabled' CSS class"
);
},
}
);
}
);

View File

@ -1,47 +1,34 @@
import componentTest, { import { module, test } from "qunit";
setupRenderingTest, import { setupRenderingTest } from "discourse/tests/helpers/component-test";
} from "discourse/tests/helpers/component-test"; import { render } from "@ember/test-helpers";
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers"; import { hbs } from "ember-cli-htmlbars";
import hbs from "htmlbars-inline-precompile";
discourseModule( module("Integration | Component | admin-holidays-list", function (hooks) {
"Integration | Component | admin-holidays-list", setupRenderingTest(hooks);
function (hooks) {
setupRenderingTest(hooks);
componentTest("displaying a list of the provided holidays", { test("displaying a list of the provided holidays", async function (assert) {
template: hbs`{{admin-holidays-list holidays=holidays}}`, this.set("holidays", [
{ date: "2022-01-01", name: "New Year's Day" },
{ date: "2022-01-17", name: "Martin Luther King, Jr. Day" },
]);
beforeEach() { await render(hbs`<AdminHolidaysList @holidays={{this.holidays}} />`);
this.set("holidays", [
{ date: "2022-01-01", name: "New Year's Day" },
{ date: "2022-01-17", name: "Martin Luther King, Jr. Day" },
]);
},
async test(assert) { assert
assert.strictEqual( .dom("table tbody tr:nth-child(1) td:nth-child(1)")
query("table tbody tr:nth-child(1) td:nth-child(1)").innerText.trim(), .hasText("2022-01-01", "it displays the first holiday date");
"2022-01-01", assert
"it displays the first holiday date" .dom("table tbody tr:nth-child(1) td:nth-child(2)")
); .hasText("New Year's Day", "it displays the first holiday name");
assert.strictEqual(
query("table tbody tr:nth-child(1) td:nth-child(2)").innerText.trim(),
"New Year's Day",
"it displays the first holiday name"
);
assert.strictEqual( assert
query("table tbody tr:nth-child(2) td:nth-child(1)").innerText.trim(), .dom("table tbody tr:nth-child(2) td:nth-child(1)")
"2022-01-17", .hasText("2022-01-17", "it displays the second holiday date");
"it displays the second holiday date" assert
); .dom("table tbody tr:nth-child(2) td:nth-child(2)")
assert.strictEqual( .hasText(
query("table tbody tr:nth-child(2) td:nth-child(2)").innerText.trim(), "Martin Luther King, Jr. Day",
"Martin Luther King, Jr. Day", "it displays the second holiday name"
"it displays the second holiday name" );
); });
}, });
});
}
);

View File

@ -1,54 +1,41 @@
import componentTest, { import { module, test } from "qunit";
setupRenderingTest, import { setupRenderingTest } from "discourse/tests/helpers/component-test";
} from "discourse/tests/helpers/component-test"; import { render } from "@ember/test-helpers";
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers"; import { hbs } from "ember-cli-htmlbars";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import hbs from "htmlbars-inline-precompile";
discourseModule("Integration | Component | region-input", function (hooks) { module("Integration | Component | region-input", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
componentTest("displaying the 'None' region option", { test("displaying the 'None' region option", async function (assert) {
template: hbs`{{region-input allowNoneRegion=true}}`, this.siteSettings.available_locales = JSON.stringify([
{ name: "English", value: "en" },
]);
beforeEach() { await render(hbs`<RegionInput @allowNoneRegion={{true}} />>`);
this.siteSettings.available_locales = JSON.stringify([ await selectKit().expand();
{ name: "English", value: "en" },
]);
},
async test(assert) { assert
await selectKit().expand(); .dom(".region-input ul li.select-kit-row:first-child")
.hasText(
assert.equal(
query(
".region-input ul li.select-kit-row:first-child"
).innerText.trim(),
"None", "None",
"it displays the 'None' option when allowNoneRegion is set to true" "it displays the 'None' option when allowNoneRegion is set to true"
); );
},
}); });
componentTest("hiding the 'None' region option", { test("hiding the 'None' region option", async function (assert) {
template: hbs`{{region-input allowNoneRegion=false}}`, this.siteSettings.available_locales = JSON.stringify([
{ name: "English", value: "en" },
]);
beforeEach() { await render(hbs`<RegionInput @allowNoneRegion={{false}} />`);
this.siteSettings.available_locales = JSON.stringify([ await selectKit().expand();
{ name: "English", value: "en" },
]);
},
async test(assert) { assert
await selectKit().expand(); .dom(".region-input ul li.select-kit-row:first-child")
.hasText(
assert.notEqual( "Argentina",
query(
".region-input ul li.select-kit-row:first-child"
).innerText.trim(),
"None",
"it does not display the 'None' option when allowNoneRegion is set to false" "it does not display the 'None' option when allowNoneRegion is set to false"
); );
},
}); });
}); });

1285
yarn.lock

File diff suppressed because it is too large Load Diff