DEV: Clean up the plugin (#426)
This commit is contained in:
parent
6309490901
commit
6761e2c84f
|
|
@ -1,7 +1,3 @@
|
|||
.DS_Store
|
||||
gems/
|
||||
/node_modules
|
||||
.on-save.json
|
||||
node_modules
|
||||
yarn-error.log
|
||||
.rubocop-https---raw-githubusercontent-com-discourse-*
|
||||
/gems
|
||||
/auto_generated
|
||||
|
|
|
|||
2
.streerc
2
.streerc
|
|
@ -1,3 +1,3 @@
|
|||
--print-width=100
|
||||
--plugins=plugin/trailing_comma
|
||||
--plugins=plugin/trailing_comma,disable_ternary
|
||||
--ignore-files=vendor/*
|
||||
1
Gemfile
1
Gemfile
|
|
@ -5,4 +5,5 @@ source "https://rubygems.org"
|
|||
group :development do
|
||||
gem "rubocop-discourse"
|
||||
gem "syntax_tree"
|
||||
gem "syntax_tree-disable_ternary"
|
||||
end
|
||||
|
|
|
|||
46
Gemfile.lock
46
Gemfile.lock
|
|
@ -2,35 +2,46 @@ GEM
|
|||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
json (2.6.2)
|
||||
parallel (1.22.1)
|
||||
parser (3.1.2.1)
|
||||
json (2.6.3)
|
||||
language_server-protocol (3.17.0.3)
|
||||
parallel (1.23.0)
|
||||
parser (3.2.2.3)
|
||||
ast (~> 2.4.1)
|
||||
prettier_print (1.2.0)
|
||||
racc
|
||||
prettier_print (1.2.1)
|
||||
racc (1.7.1)
|
||||
rainbow (3.1.1)
|
||||
regexp_parser (2.6.0)
|
||||
rexml (3.2.5)
|
||||
rubocop (1.36.0)
|
||||
regexp_parser (2.8.1)
|
||||
rexml (3.2.6)
|
||||
rubocop (1.55.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (>= 3.17.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.1.2.1)
|
||||
parser (>= 3.2.2.3)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.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)
|
||||
unicode-display_width (>= 1.4.0, < 3.0)
|
||||
rubocop-ast (1.21.0)
|
||||
parser (>= 3.1.1.0)
|
||||
rubocop-discourse (3.0)
|
||||
unicode-display_width (>= 2.4.0, < 3.0)
|
||||
rubocop-ast (1.29.0)
|
||||
parser (>= 3.2.1.0)
|
||||
rubocop-capybara (2.18.0)
|
||||
rubocop (~> 1.41)
|
||||
rubocop-discourse (3.3.0)
|
||||
rubocop (>= 1.1.0)
|
||||
rubocop-rspec (>= 2.0.0)
|
||||
rubocop-rspec (2.13.2)
|
||||
rubocop-factory_bot (2.23.1)
|
||||
rubocop (~> 1.33)
|
||||
ruby-progressbar (1.11.0)
|
||||
syntax_tree (5.1.0)
|
||||
rubocop-rspec (2.23.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)
|
||||
unicode-display_width (2.3.0)
|
||||
syntax_tree-disable_ternary (1.0.0)
|
||||
unicode-display_width (2.4.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
|
@ -38,6 +49,7 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
rubocop-discourse
|
||||
syntax_tree
|
||||
syntax_tree-disable_ternary
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
|
|
|
|||
18
README.md
18
README.md
|
|
@ -1,38 +1,38 @@
|
|||
## Discourse Calendar
|
||||
# Discourse Calendar
|
||||
|
||||
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)
|
||||
|
||||
### 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_started` this DiscourseEvent will be triggered when an event starts
|
||||
- `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.
|
||||
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.
|
||||
|
||||
Generate updated holidays as follows.
|
||||
|
||||
```sh
|
||||
cd vendor/holidays
|
||||
|
||||
# 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).
|
||||
|
||||
```sh
|
||||
# Collect all holiday regions into assets/javascripts/lib/regions.js
|
||||
bundle exec rake javascript:update_constants
|
||||
bin/rails javascript:update_constants
|
||||
```
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<AdminHolidaysListItem
|
||||
@holiday={{holiday}}
|
||||
@isHolidayDisabled={{holiday.disabled}}
|
||||
@region_code={{region_code}}
|
||||
@region_code={{@region_code}}
|
||||
/>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
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 ComboBoxComponent from "select-kit/components/combo-box";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Promise } from "rsvp";
|
||||
import { isNotFullDayEvent } from "discourse/plugins/discourse-calendar/lib/guess-best-date-format";
|
||||
import { formatEventName } from "discourse/plugins/discourse-calendar/helpers/format-event-name";
|
||||
import { isNotFullDayEvent } from "../lib/guess-best-date-format";
|
||||
import { formatEventName } from "../helpers/format-event-name";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
import Component from "@ember/component";
|
||||
import { schedule } from "@ember/runloop";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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 {
|
||||
setupComponent(args, component) {
|
||||
|
|
@ -7,7 +7,7 @@ import { action, computed, set } from "@ember/object";
|
|||
import { equal, gte } from "@ember/object/computed";
|
||||
import { extractError } from "discourse/lib/ajax-error";
|
||||
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 = {
|
||||
type: "notification",
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
export default htmlHelper((date) => {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import eventRelativeDate from "discourse/plugins/discourse-calendar/lib/event-relative-date";
|
||||
import eventLocalDate from "discourse/plugins/discourse-calendar/lib/event-local-date";
|
||||
import eventRelativeDate from "../lib/event-relative-date";
|
||||
import eventLocalDate from "../lib/event-local-date";
|
||||
|
||||
function initializeDecorateTopicTitle(api) {
|
||||
api.decorateTopicTitle((topic, node, topicTitleType) => {
|
||||
|
|
@ -8,14 +8,10 @@ import { withPluginApi } from "discourse/lib/plugin-api";
|
|||
import { ajax } from "discourse/lib/ajax";
|
||||
import Category from "discourse/models/category";
|
||||
import I18n from "I18n";
|
||||
import {
|
||||
colorToHex,
|
||||
contrastColor,
|
||||
stringToColor,
|
||||
} from "discourse/plugins/discourse-calendar/lib/colors";
|
||||
import { colorToHex, contrastColor, stringToColor } from "../lib/colors";
|
||||
import { createPopper } from "@popperjs/core";
|
||||
import { isNotFullDayEvent } from "discourse/plugins/discourse-calendar/lib/guess-best-date-format";
|
||||
import { formatEventName } from "discourse/plugins/discourse-calendar/helpers/format-event-name";
|
||||
import { isNotFullDayEvent } from "../lib/guess-best-date-format";
|
||||
import { formatEventName } from "../helpers/format-event-name";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
|
||||
function loadFullCalendar() {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
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 WidgetGlue from "discourse/widgets/glue";
|
||||
import { getRegister } from "discourse-common/lib/get-owner";
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { isTesting } from "discourse-common/config/environment";
|
||||
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";
|
||||
|
||||
function computeRelativeEventDates() {
|
||||
|
|
@ -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) {
|
||||
container.classList.remove("past", "current", "future");
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
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) {
|
||||
const indicator = document.createElement("div");
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import hbs from "discourse/widgets/hbs-compiler";
|
||||
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", {
|
||||
tagName: "div.group-timezones-time-traveler",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import hbs from "discourse/widgets/hbs-compiler";
|
||||
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", {
|
||||
tagName: "div.group-timezones",
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import I18n from "I18n";
|
||||
import TextLib, { emojiUnescape } from "discourse/lib/text";
|
||||
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 EmberObject from "@ember/object";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import hbs from "discourse/widgets/hbs-compiler";
|
||||
import { createWidget } from "discourse/widgets/widget";
|
||||
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";
|
||||
|
||||
export default createWidget("discourse-post-event", {
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@
|
|||
}
|
||||
.fc-list-item-add-to-calendar {
|
||||
color: var(--tertiary);
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +307,7 @@ a.holiday {
|
|||
align-items: center;
|
||||
justify-content: space-between;
|
||||
color: inherit;
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
|
||||
.before {
|
||||
margin-right: auto;
|
||||
|
|
@ -358,7 +358,7 @@ a.holiday {
|
|||
}
|
||||
|
||||
.offset {
|
||||
font-size: $font-down-2;
|
||||
font-size: var(--font-down-2);
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
}
|
||||
|
||||
.name {
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
}
|
||||
|
||||
&.from {
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
border: 0;
|
||||
|
||||
.name {
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
.event-date {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
font-size: $font-down-2;
|
||||
font-size: var(--font-down-2);
|
||||
border: 1px solid var(--primary-medium);
|
||||
background: none;
|
||||
padding: 0 0.25em;
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
.header-title {
|
||||
.event-date {
|
||||
font-size: $font-down-4;
|
||||
font-size: var(--font-down-4);
|
||||
color: var(--primary-medium);
|
||||
font-weight: normal;
|
||||
padding: 0.25em;
|
||||
|
|
|
|||
|
|
@ -85,14 +85,14 @@ $interested: #fb985d;
|
|||
.month {
|
||||
text-align: center;
|
||||
color: red;
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.day {
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
font-size: $font-up-2;
|
||||
font-size: var(--font-up-2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ $interested: #fb985d;
|
|||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--primary-medium);
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
margin: 0.25em 0;
|
||||
|
||||
.separator {
|
||||
|
|
@ -253,7 +253,7 @@ $interested: #fb985d;
|
|||
border: 1px solid var(--primary-low);
|
||||
|
||||
.d-icon {
|
||||
font-size: $font-down-3;
|
||||
font-size: var(--font-down-3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,6 @@
|
|||
}
|
||||
.fc-list-item-add-to-calendar {
|
||||
color: var(--tertiary);
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
background: none;
|
||||
|
||||
h2.discourse-calendar-title {
|
||||
font-size: $font-0;
|
||||
font-size: var(--font-0);
|
||||
flex-wrap: nowrap;
|
||||
max-width: 75%;
|
||||
white-space: nowrap;
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
text-align: center;
|
||||
padding: 0.25em;
|
||||
span {
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
text-align: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
}
|
||||
|
||||
.event-invitees-status {
|
||||
font-size: $font-down-1;
|
||||
font-size: var(--font-down-1);
|
||||
}
|
||||
|
||||
.event-invitees .event-invitees-avatars .topic-invitee-avatar .avatar-flair {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,5 @@
|
|||
# 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
|
||||
get "/discourse-post-event/events" => "events#index", :format => :json
|
||||
get "/discourse-post-event/events/:id" => "events#show"
|
||||
|
|
@ -30,4 +15,17 @@ DiscoursePostEvent::Engine.routes.draw do
|
|||
get "/upcoming-events" => "upcoming_events#index"
|
||||
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
|
||||
|
|
|
|||
|
|
@ -89,4 +89,3 @@ discourse_post_event:
|
|||
disable_resorting_on_categories_enabled:
|
||||
default: false
|
||||
client: true
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ class CalendarSettingsValidator
|
|||
|
||||
hour = split.first
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "discourse-calendar",
|
||||
"version": "1.0.0",
|
||||
"repository": "git@github.com:discourse/discourse-calendar.git",
|
||||
"version": "0.3.0",
|
||||
"repository": "https://github.com/discourse/discourse-calendar",
|
||||
"author": "Discourse",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint-config-discourse": "^3.4.0"
|
||||
"eslint-config-discourse": "^3.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
# version: 0.3
|
||||
# author: Daniel Waterworth, Joffrey Jaffeux
|
||||
# url: https://github.com/discourse/discourse-calendar
|
||||
# transpile_js: true
|
||||
|
||||
libdir = File.join(File.dirname(__FILE__), "vendor/holidays/lib")
|
||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ require "rails_helper"
|
|||
require "securerandom"
|
||||
|
||||
describe Post do
|
||||
Event ||= DiscoursePostEvent::Event
|
||||
Invitee ||= DiscoursePostEvent::Invitee
|
||||
|
||||
before do
|
||||
freeze_time
|
||||
Jobs.run_immediately!
|
||||
|
|
@ -58,8 +55,12 @@ describe Post do
|
|||
end
|
||||
|
||||
it "sends a post revision to going invitees" do
|
||||
Invitee.create_attendance!(going_user.id, post_1.id, :going)
|
||||
Invitee.create_attendance!(interested_user.id, post_1.id, :interested)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(going_user.id, post_1.id, :going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(
|
||||
interested_user.id,
|
||||
post_1.id,
|
||||
:interested,
|
||||
)
|
||||
|
||||
expect {
|
||||
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) }
|
||||
|
||||
it "doesn’t send a post revision to anyone" do
|
||||
Invitee.create_attendance!(going_user.id, post_1.id, :going)
|
||||
Invitee.create_attendance!(interested_user.id, event_1.id, :interested)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(going_user.id, post_1.id, :going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(
|
||||
interested_user.id,
|
||||
event_1.id,
|
||||
:interested,
|
||||
)
|
||||
|
||||
expect {
|
||||
revisor = PostRevisor.new(event_1.post)
|
||||
|
|
@ -104,8 +109,12 @@ describe Post do
|
|||
original_ends_at: nil,
|
||||
)
|
||||
|
||||
Invitee.create_attendance!(going_user.id, event_1.id, :going)
|
||||
Invitee.create_attendance!(interested_user.id, event_1.id, :interested)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(going_user.id, event_1.id, :going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(
|
||||
interested_user.id,
|
||||
event_1.id,
|
||||
:interested,
|
||||
)
|
||||
|
||||
event_1.reload
|
||||
|
||||
|
|
@ -124,7 +133,10 @@ describe Post do
|
|||
|
||||
it "it removes status from every invitees" do
|
||||
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)
|
||||
|
|
@ -158,12 +170,12 @@ describe Post do
|
|||
context "when updating status to private" do
|
||||
it "it changes the status and force invitees" do
|
||||
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.status).to eq(Event.statuses[:private])
|
||||
expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:private])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -452,7 +464,7 @@ describe Post do
|
|||
Fabricate(
|
||||
:event,
|
||||
post: post_1,
|
||||
status: Event.statuses[:private],
|
||||
status: DiscoursePostEvent::Event.statuses[:private],
|
||||
raw_invitees: [group_1.name],
|
||||
original_starts_at: 3.hours.ago,
|
||||
original_ends_at: nil,
|
||||
|
|
@ -464,7 +476,7 @@ describe Post do
|
|||
Fabricate(
|
||||
:event,
|
||||
post: post_1,
|
||||
status: Event.statuses[:private],
|
||||
status: DiscoursePostEvent::Event.statuses[:private],
|
||||
raw_invitees: [group_1.name],
|
||||
recurrence: "FREQ=WEEKLY;BYDAY=MO",
|
||||
original_starts_at: 2.hours.from_now,
|
||||
|
|
@ -506,12 +518,12 @@ describe Post do
|
|||
context "when updating status to public" do
|
||||
it "it changes the status and force invitees" do
|
||||
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.status).to eq(Event.statuses[:public])
|
||||
expect(event_1.status).to eq(DiscoursePostEvent::Event.statuses[:public])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -19,16 +19,19 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
context "with invalid params" do
|
||||
context "with no invitees given" do
|
||||
it "raises an invalid parameters errors" do
|
||||
expect { subject.execute(current_user_id: 1, event_id: 1) }.to raise_error(
|
||||
Discourse::InvalidParameters,
|
||||
)
|
||||
expect {
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(current_user_id: 1, event_id: 1)
|
||||
}.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
|
||||
context "with no current_user_id given" do
|
||||
it "raises an invalid parameters errors" do
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
@ -36,7 +39,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
context "with no event_id given" do
|
||||
it "raises an invalid parameters errors" do
|
||||
expect {
|
||||
subject.execute(
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(
|
||||
invitees: [{ identifier: "bob", attendance: "going" }],
|
||||
current_user_id: 1,
|
||||
)
|
||||
|
|
@ -51,7 +54,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
|
||||
it "raises an error" do
|
||||
expect {
|
||||
subject.execute(
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(
|
||||
event_id: post_event_1.id,
|
||||
invitees: [{ identifier: "bob", attendance: "going" }],
|
||||
current_user_id: lurker.id,
|
||||
|
|
@ -101,7 +104,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
)
|
||||
.once
|
||||
|
||||
subject.execute(valid_params)
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
|
||||
|
||||
invitee_klass = DiscoursePostEvent::Invitee
|
||||
|
||||
|
|
@ -117,7 +120,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
end
|
||||
|
||||
it "removes the invitee if set to unknown" do
|
||||
subject.execute(valid_params)
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
|
||||
|
||||
invitee_klass = DiscoursePostEvent::Invitee
|
||||
|
||||
|
|
@ -129,7 +132,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
invitee_klass.statuses[:not_going],
|
||||
)
|
||||
|
||||
subject.execute(
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(
|
||||
event_id: post_event_1.id,
|
||||
invitees: [{ "identifier" => group_1.name, "attendance" => "unknown" }],
|
||||
current_user_id: user_1.id,
|
||||
|
|
@ -149,7 +152,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
|
||||
invitee_klass = DiscoursePostEvent::Invitee
|
||||
|
||||
subject.execute(
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(
|
||||
event_id: post_event_1.id,
|
||||
invitees: [{ "identifier" => group_1.name }],
|
||||
current_user_id: user_1.id,
|
||||
|
|
@ -183,7 +186,7 @@ describe Jobs::DiscoursePostEventBulkInvite do
|
|||
)
|
||||
.once
|
||||
|
||||
subject.execute(valid_params)
|
||||
Jobs::DiscoursePostEventBulkInvite.new.execute(valid_params)
|
||||
|
||||
invitee_klass = DiscoursePostEvent::Invitee
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ describe Jobs::DiscoursePostEventBumpTopic do
|
|||
context "when params are present" do
|
||||
it "creates an auto-bump topic timer" do
|
||||
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)
|
||||
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
|
||||
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe Jobs::DiscoursePostEventSendReminder do
|
||||
Invitee ||= DiscoursePostEvent::Invitee
|
||||
|
||||
let(:admin_1) { Fabricate(:user, admin: true) }
|
||||
let(:going_user) { Fabricate(:user) }
|
||||
let(:interested_user) { Fabricate(:user) }
|
||||
|
|
@ -16,12 +14,20 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
let(:reminders) { "notification.5.minutes" }
|
||||
|
||||
def init_invitees
|
||||
Invitee.create_attendance!(going_user.id, event_1.id, :going)
|
||||
Invitee.create_attendance!(interested_user.id, event_1.id, :interested)
|
||||
Invitee.create_attendance!(not_going_user.id, event_1.id, :not_going)
|
||||
Invitee.create_attendance!(going_user_unread_notification.id, event_1.id, :going)
|
||||
Invitee.create_attendance!(going_user_read_notification.id, event_1.id, :going)
|
||||
Invitee.create_attendance!(visited_going_user.id, event_1.id, :going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(going_user.id, event_1.id, :going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(interested_user.id, event_1.id, :interested)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(not_going_user.id, event_1.id, :not_going)
|
||||
DiscoursePostEvent::Invitee.create_attendance!(
|
||||
going_user_unread_notification.id,
|
||||
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,
|
||||
|
|
@ -52,9 +58,13 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
describe "#execute" do
|
||||
context "with invalid params" 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
|
||||
|
||||
|
|
@ -66,7 +76,12 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
it "is not erroring when post is already deleted" do
|
||||
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
|
||||
|
||||
|
|
@ -87,32 +102,47 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
it "creates a new notification for going user" do
|
||||
expect(going_user.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change {
|
||||
going_user.reload.unread_notifications
|
||||
}.by(1)
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.to change { going_user.reload.unread_notifications }.by(1)
|
||||
end
|
||||
|
||||
it "doesn’t create a new notification for not going user" do
|
||||
expect(not_going_user.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change {
|
||||
not_going_user.reload.unread_notifications
|
||||
}
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.not_to change { not_going_user.reload.unread_notifications }
|
||||
end
|
||||
|
||||
it "doesn’t create a new notification if there’s already one" do
|
||||
expect(going_user_unread_notification.unread_notifications).to eq(1)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change {
|
||||
going_user_unread_notification.reload.unread_notifications
|
||||
}
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.not_to change { going_user_unread_notification.reload.unread_notifications }
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
subject.execute(event_id: event_1.id, reminder: reminders)
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
|
||||
expect(
|
||||
going_user
|
||||
|
|
@ -149,40 +179,58 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
it "creates a new notification for going user" do
|
||||
expect(going_user.reload.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change {
|
||||
going_user.reload.unread_notifications
|
||||
}.by(1)
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.to change { going_user.reload.unread_notifications }.by(1)
|
||||
end
|
||||
|
||||
it "creates a new notification for interested user" do
|
||||
expect(interested_user.reload.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.to change {
|
||||
interested_user.reload.unread_notifications
|
||||
}.by(1)
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.to change { interested_user.reload.unread_notifications }.by(1)
|
||||
end
|
||||
|
||||
it "doesn’t create a new notification for not going user" do
|
||||
expect(not_going_user.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change {
|
||||
not_going_user.reload.unread_notifications
|
||||
}
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.not_to change { not_going_user.reload.unread_notifications }
|
||||
end
|
||||
|
||||
it "doesn’t create a new notification if there’s already one" do
|
||||
expect(going_user_unread_notification.unread_notifications).to eq(1)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change {
|
||||
going_user_unread_notification.reload.unread_notifications
|
||||
}
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.not_to change { going_user_unread_notification.reload.unread_notifications }
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
subject.execute(event_id: event_1.id, reminder: reminders)
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
|
||||
expect(
|
||||
going_user
|
||||
|
|
@ -205,7 +253,10 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
}.to_json,
|
||||
)
|
||||
|
||||
subject.execute(event_id: event_1.id, reminder: reminders)
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
messages =
|
||||
Notification.where(
|
||||
user: going_user,
|
||||
|
|
@ -221,9 +272,12 @@ describe Jobs::DiscoursePostEventSendReminder do
|
|||
it "doesn’t create a new notification for visiting user" do
|
||||
expect(visited_going_user.unread_notifications).to eq(0)
|
||||
|
||||
expect { subject.execute(event_id: event_1.id, reminder: reminders) }.not_to change {
|
||||
visited_going_user.reload.unread_notifications
|
||||
}
|
||||
expect {
|
||||
Jobs::DiscoursePostEventSendReminder.new.execute(
|
||||
event_id: event_1.id,
|
||||
reminder: reminders,
|
||||
)
|
||||
}.not_to change { visited_going_user.reload.unread_notifications }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
|
||||
frenchy
|
||||
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)
|
||||
end
|
||||
|
|
@ -31,7 +31,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "adds all holidays in the next 6 months" do
|
||||
frenchy
|
||||
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(
|
||||
[
|
||||
|
|
@ -47,7 +47,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "checks for observed dates" do
|
||||
aussie
|
||||
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
|
||||
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
|
||||
frenchy
|
||||
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
|
||||
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([])
|
||||
end
|
||||
|
|
@ -114,14 +114,14 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "cleans up holidays from deactivated/silenced/suspended users" do
|
||||
frenchy
|
||||
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)
|
||||
|
||||
frenchy.active = false
|
||||
frenchy.save!
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
|
||||
|
||||
expect(CalendarEvent.exists?(username: frenchy.username)).to eq(false)
|
||||
end
|
||||
|
|
@ -138,7 +138,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "only adds enabled holidays to the calendar" do
|
||||
frenchy
|
||||
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(
|
||||
[
|
||||
|
|
@ -152,7 +152,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "doesn't add disabled holidays to the calendar" do
|
||||
frenchy
|
||||
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_toussaint[:holiday_name])
|
||||
|
|
@ -163,7 +163,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "uses the user TZ when available" do
|
||||
frenchy.user_option.update!(timezone: "Europe/Paris")
|
||||
freeze_time Time.zone.local(2019, 8, 1)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
|
||||
|
||||
calendar_event = CalendarEvent.first
|
||||
expect(calendar_event.region).to eq("fr")
|
||||
|
|
@ -181,7 +181,7 @@ describe DiscourseCalendar::CreateHolidayEvents do
|
|||
it "uses the user TZ when available" do
|
||||
frenchy.user_option.update!(timezone: "Europe/Paris")
|
||||
freeze_time Time.zone.local(2019, 8, 1)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::CreateHolidayEvents.new.execute(nil)
|
||||
|
||||
calendar_event = CalendarEvent.first
|
||||
expect(calendar_event.region).to eq("fr")
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
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_two_dates.id)).to eq(false)
|
||||
|
|
@ -53,7 +53,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
description: "Matariki",
|
||||
)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
|
||||
|
||||
expect(CalendarEvent.exists?(matariki.id)).to eq(true)
|
||||
end
|
||||
|
|
@ -62,7 +62,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
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))
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
|
||||
|
||||
expect(Post.exists?(post.id)).to eq(true)
|
||||
end
|
||||
|
|
@ -74,7 +74,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
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)
|
||||
end
|
||||
|
|
@ -88,7 +88,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
|
||||
calendar_topic.update!(archived: true)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
|
||||
|
||||
expect(Post.exists?(post.id)).to eq(true)
|
||||
end
|
||||
|
|
@ -102,7 +102,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
|
||||
calendar_topic.update!(closed: true)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::DeleteExpiredEventPosts.new.execute(nil)
|
||||
|
||||
expect(Post.exists?(post.id)).to eq(true)
|
||||
end
|
||||
|
|
@ -153,7 +153,7 @@ describe DiscourseCalendar::DeleteExpiredEventPosts do
|
|||
|
||||
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?(reply_without_event.id)).to eq(false)
|
||||
|
|
|
|||
|
|
@ -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"]'
|
||||
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])
|
||||
|
||||
freeze_time Time.utc(2018, 6, 7, 18, 40)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
expect(DiscourseCalendar.users_on_holiday).to eq([])
|
||||
end
|
||||
|
|
@ -36,7 +36,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
|
|||
raw2 = 'Rome [date="2018-06-05"]' # the whole day
|
||||
post2 = create_post(raw: raw2, topic: calendar_post.topic)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
expect(
|
||||
UserCustomField.exists?(
|
||||
name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD,
|
||||
|
|
@ -51,7 +51,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
|
|||
).to be_truthy
|
||||
|
||||
freeze_time Time.utc(2018, 6, 6, 10, 00)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
expect(
|
||||
UserCustomField.exists?(
|
||||
name: DiscourseCalendar::HOLIDAY_CUSTOM_FIELD,
|
||||
|
|
@ -66,7 +66,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
|
|||
).to be_falsey
|
||||
|
||||
freeze_time Time.utc(2018, 6, 7, 10, 00)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
expect(
|
||||
UserCustomField.exists?(
|
||||
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"]'
|
||||
post = create_post(raw: raw, topic: calendar_post.topic)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
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"]'
|
||||
post = create_post(raw: raw, topic: calendar_post.topic)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
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" }
|
||||
post.user.set_status!(custom_status[:description], custom_status[:emoji])
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
status = post.user.user_status
|
||||
|
|
@ -151,7 +151,7 @@ describe DiscourseCalendar::UpdateHolidayUsernames do
|
|||
)
|
||||
|
||||
freeze_time tomorrow + 2.day
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
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"]'
|
||||
post = create_post(raw: raw, topic: calendar_post.topic)
|
||||
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
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"]' },
|
||||
revised_at: Time.now,
|
||||
)
|
||||
subject.execute(nil)
|
||||
DiscourseCalendar::UpdateHolidayUsernames.new.execute(nil)
|
||||
|
||||
post.user.reload
|
||||
expect(post.user.user_status).to be_present
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ describe DiscoursePostEvent::EventFinder do
|
|||
fab!(:current_user) { Fabricate(:user) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
subject { DiscoursePostEvent::EventFinder }
|
||||
subject(:finder) { DiscoursePostEvent::EventFinder }
|
||||
|
||||
before do
|
||||
Jobs.run_immediately!
|
||||
|
|
@ -24,7 +24,7 @@ describe DiscoursePostEvent::EventFinder do
|
|||
let!(:event) { Fabricate(:event, post: post1) }
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ describe DiscoursePostEvent::EventFinder do
|
|||
let!(:event) { Fabricate(:event, post: post1) }
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ describe DiscoursePostEvent::EventFinder do
|
|||
let!(:event) { Fabricate(:event, post: post1) }
|
||||
|
||||
it "doesn’t return the event" do
|
||||
expect(subject.search(current_user)).to match_array([])
|
||||
expect(finder.search(current_user)).to match_array([])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ describe DiscoursePostEvent::EventFinder do
|
|||
let!(:event2) { Fabricate(:event, post: post2) }
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -122,10 +122,8 @@ describe DiscoursePostEvent::EventFinder do
|
|||
end
|
||||
|
||||
it "returns correct events" do
|
||||
expect(subject.search(current_user, { expired: false })).to eq(
|
||||
[current_event, future_event],
|
||||
)
|
||||
expect(subject.search(current_user, { expired: true })).to eq([older_event, old_event])
|
||||
expect(finder.search(current_user, { expired: false })).to eq([current_event, future_event])
|
||||
expect(finder.search(current_user, { expired: true })).to eq([older_event, old_event])
|
||||
end
|
||||
|
||||
context "when a past event has been edited to be in the future" do
|
||||
|
|
@ -140,10 +138,10 @@ describe DiscoursePostEvent::EventFinder do
|
|||
end
|
||||
|
||||
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],
|
||||
)
|
||||
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
|
||||
|
||||
|
|
@ -159,10 +157,10 @@ describe DiscoursePostEvent::EventFinder do
|
|||
end
|
||||
|
||||
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],
|
||||
)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ def build_post(user, raw)
|
|||
end
|
||||
|
||||
describe DiscoursePostEvent::EventParser do
|
||||
subject { DiscoursePostEvent::EventParser }
|
||||
subject(:parser) { DiscoursePostEvent::EventParser }
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -30,33 +30,32 @@ describe DiscoursePostEvent::EventParser do
|
|||
[/event]
|
||||
TXT
|
||||
|
||||
events = subject.extract_events(post_event)
|
||||
events = parser.extract_events(post_event)
|
||||
expect(events.length).to eq(2)
|
||||
end
|
||||
|
||||
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][:end]).to eq("bar")
|
||||
end
|
||||
|
||||
it "works with escaped string" do
|
||||
events =
|
||||
subject.extract_events(
|
||||
parser.extract_events(
|
||||
build_post(user, "I am going to get that fixed.\n\n[event start=\"bar\"]\n[/event]"),
|
||||
)
|
||||
expect(events[0][:start]).to eq("bar")
|
||||
end
|
||||
|
||||
it "parses options where value has spaces" do
|
||||
events =
|
||||
subject.extract_events(build_post(user, '[event start="foo" name="bar baz"]\n[/event]'))
|
||||
events = parser.extract_events(build_post(user, '[event start="foo" name="bar baz"]\n[/event]'))
|
||||
expect(events[0][:name]).to eq("bar baz")
|
||||
end
|
||||
|
||||
it "doesn’t parse invalid options" do
|
||||
events =
|
||||
subject.extract_events(
|
||||
parser.extract_events(
|
||||
build_post(
|
||||
user,
|
||||
"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)
|
||||
|
||||
events =
|
||||
subject.extract_events(
|
||||
parser.extract_events(
|
||||
build_post(user, "I am going to get that fixed.\n\n[event something=\"bar\"]\n[/event]"),
|
||||
)
|
||||
expect(events).to eq([])
|
||||
|
|
@ -79,7 +78,7 @@ describe DiscoursePostEvent::EventParser do
|
|||
```
|
||||
TXT
|
||||
|
||||
events = subject.extract_events(post_event)
|
||||
events = parser.extract_events(post_event)
|
||||
|
||||
expect(events).to eq([])
|
||||
end
|
||||
|
|
@ -89,13 +88,13 @@ describe DiscoursePostEvent::EventParser do
|
|||
[event start="2020"][/event]
|
||||
TXT
|
||||
|
||||
events = subject.extract_events(post_event)
|
||||
events = parser.extract_events(post_event)
|
||||
expect(events).to eq([])
|
||||
end
|
||||
|
||||
it "doesn’t escape event name" do
|
||||
events =
|
||||
subject.extract_events(
|
||||
parser.extract_events(
|
||||
build_post(user, '[event start="foo" name="bar <script> baz"]\n[/event]'),
|
||||
)
|
||||
expect(events[0][:name]).to eq("bar <script> baz")
|
||||
|
|
@ -110,7 +109,7 @@ describe DiscoursePostEvent::EventParser do
|
|||
[/event]
|
||||
TXT
|
||||
|
||||
events = subject.extract_events(post_event)
|
||||
events = parser.extract_events(post_event)
|
||||
expect(events[0][:"foo-bar"]).to eq("1")
|
||||
expect(events[0][:"bar"]).to eq("2")
|
||||
end
|
||||
|
|
@ -121,7 +120,7 @@ describe DiscoursePostEvent::EventParser do
|
|||
[/event]
|
||||
TXT
|
||||
|
||||
events = subject.extract_events(post_event)
|
||||
events = parser.extract_events(post_event)
|
||||
expect(events[0][:"baz"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ require "rails_helper"
|
|||
describe UserSerializer do
|
||||
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
|
||||
SiteSetting.calendar_enabled = true
|
||||
|
|
@ -16,7 +16,7 @@ describe UserSerializer do
|
|||
fab!(:guardian) { Fabricate(:user).guardian }
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ describe UserSerializer do
|
|||
fab!(:guardian) { user.guardian }
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ describe UserSerializer do
|
|||
fab!(:guardian) { Fabricate(:admin).guardian }
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,71 +1,50 @@
|
|||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
|
||||
discourseModule(
|
||||
"Integration | Component | admin-holidays-list-item",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
module("Integration | Component | admin-holidays-list-item", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
const template = hbs`{{admin-holidays-list-item
|
||||
holiday=holiday
|
||||
region_code=region_code
|
||||
isHolidayDisabled=holiday.disabled
|
||||
}}`;
|
||||
test("when a holiday is disabled, it displays an enable button and adds a disabled CSS class", async function (assert) {
|
||||
this.set("holiday", {
|
||||
date: "2022-01-01",
|
||||
name: "New Year's Day",
|
||||
disabled: true,
|
||||
});
|
||||
this.set("region_code", "sg");
|
||||
|
||||
componentTest(
|
||||
"when a holiday is disabled, it displays an enable button and adds a disabled CSS class",
|
||||
{
|
||||
template,
|
||||
await render(hbs`
|
||||
<AdminHolidaysListItem
|
||||
@holiday={{this.holiday}}
|
||||
@region_code={{this.region_code}}
|
||||
@isHolidayDisabled={{this.holiday.disabled}}
|
||||
/>
|
||||
`);
|
||||
|
||||
beforeEach() {
|
||||
this.set("holiday", {
|
||||
date: "2022-01-01",
|
||||
name: "New Year's Day",
|
||||
disabled: true,
|
||||
});
|
||||
this.set("region_code", "sg");
|
||||
},
|
||||
assert.dom("button").hasText("Enable", "it displays an enable button");
|
||||
assert.dom("tr").hasClass("disabled", "it adds a 'disabled' CSS class");
|
||||
});
|
||||
|
||||
async test(assert) {
|
||||
assert.equal(
|
||||
query("button").innerText.trim(),
|
||||
"Enable",
|
||||
"it displays an enable button"
|
||||
);
|
||||
assert.ok(query(".disabled"), "it adds a 'disabled' CSS class");
|
||||
},
|
||||
}
|
||||
);
|
||||
test("when a holiday is enabled, it displays a disable button and does not add a disabled CSS class", async function (assert) {
|
||||
this.set("holiday", {
|
||||
date: "2022-01-01",
|
||||
name: "New Year's Day",
|
||||
disabled: false,
|
||||
});
|
||||
this.set("region_code", "au");
|
||||
|
||||
componentTest(
|
||||
"when a holiday is enabled, it displays a disable button and does not add a disabled CSS class",
|
||||
{
|
||||
template,
|
||||
await render(hbs`
|
||||
<AdminHolidaysListItem
|
||||
@holiday={{this.holiday}}
|
||||
@region_code={{this.region_code}}
|
||||
@isHolidayDisabled={{this.holiday.disabled}}
|
||||
/>
|
||||
`);
|
||||
|
||||
beforeEach() {
|
||||
this.set("holiday", {
|
||||
date: "2022-01-01",
|
||||
name: "New Year's Day",
|
||||
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"
|
||||
);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.dom("button").hasText("Disable", "it displays a disable button");
|
||||
assert
|
||||
.dom("tr")
|
||||
.doesNotHaveClass("disabled", "it does not add a 'disabled' CSS class");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,47 +1,34 @@
|
|||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
|
||||
discourseModule(
|
||||
"Integration | Component | admin-holidays-list",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
module("Integration | Component | admin-holidays-list", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
componentTest("displaying a list of the provided holidays", {
|
||||
template: hbs`{{admin-holidays-list holidays=holidays}}`,
|
||||
test("displaying a list of the provided holidays", async function (assert) {
|
||||
this.set("holidays", [
|
||||
{ date: "2022-01-01", name: "New Year's Day" },
|
||||
{ date: "2022-01-17", name: "Martin Luther King, Jr. Day" },
|
||||
]);
|
||||
|
||||
beforeEach() {
|
||||
this.set("holidays", [
|
||||
{ date: "2022-01-01", name: "New Year's Day" },
|
||||
{ date: "2022-01-17", name: "Martin Luther King, Jr. Day" },
|
||||
]);
|
||||
},
|
||||
await render(hbs`<AdminHolidaysList @holidays={{this.holidays}} />`);
|
||||
|
||||
async test(assert) {
|
||||
assert.strictEqual(
|
||||
query("table tbody tr:nth-child(1) td:nth-child(1)").innerText.trim(),
|
||||
"2022-01-01",
|
||||
"it displays the first holiday date"
|
||||
);
|
||||
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
|
||||
.dom("table tbody tr:nth-child(1) td:nth-child(1)")
|
||||
.hasText("2022-01-01", "it displays the first holiday date");
|
||||
assert
|
||||
.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(2) td:nth-child(1)").innerText.trim(),
|
||||
"2022-01-17",
|
||||
"it displays the second holiday date"
|
||||
);
|
||||
assert.strictEqual(
|
||||
query("table tbody tr:nth-child(2) td:nth-child(2)").innerText.trim(),
|
||||
"Martin Luther King, Jr. Day",
|
||||
"it displays the second holiday name"
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
assert
|
||||
.dom("table tbody tr:nth-child(2) td:nth-child(1)")
|
||||
.hasText("2022-01-17", "it displays the second holiday date");
|
||||
assert
|
||||
.dom("table tbody tr:nth-child(2) td:nth-child(2)")
|
||||
.hasText(
|
||||
"Martin Luther King, Jr. Day",
|
||||
"it displays the second holiday name"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,54 +1,41 @@
|
|||
import componentTest, {
|
||||
setupRenderingTest,
|
||||
} from "discourse/tests/helpers/component-test";
|
||||
import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
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);
|
||||
|
||||
componentTest("displaying the 'None' region option", {
|
||||
template: hbs`{{region-input allowNoneRegion=true}}`,
|
||||
test("displaying the 'None' region option", async function (assert) {
|
||||
this.siteSettings.available_locales = JSON.stringify([
|
||||
{ name: "English", value: "en" },
|
||||
]);
|
||||
|
||||
beforeEach() {
|
||||
this.siteSettings.available_locales = JSON.stringify([
|
||||
{ name: "English", value: "en" },
|
||||
]);
|
||||
},
|
||||
await render(hbs`<RegionInput @allowNoneRegion={{true}} />>`);
|
||||
await selectKit().expand();
|
||||
|
||||
async test(assert) {
|
||||
await selectKit().expand();
|
||||
|
||||
assert.equal(
|
||||
query(
|
||||
".region-input ul li.select-kit-row:first-child"
|
||||
).innerText.trim(),
|
||||
assert
|
||||
.dom(".region-input ul li.select-kit-row:first-child")
|
||||
.hasText(
|
||||
"None",
|
||||
"it displays the 'None' option when allowNoneRegion is set to true"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
componentTest("hiding the 'None' region option", {
|
||||
template: hbs`{{region-input allowNoneRegion=false}}`,
|
||||
test("hiding the 'None' region option", async function (assert) {
|
||||
this.siteSettings.available_locales = JSON.stringify([
|
||||
{ name: "English", value: "en" },
|
||||
]);
|
||||
|
||||
beforeEach() {
|
||||
this.siteSettings.available_locales = JSON.stringify([
|
||||
{ name: "English", value: "en" },
|
||||
]);
|
||||
},
|
||||
await render(hbs`<RegionInput @allowNoneRegion={{false}} />`);
|
||||
await selectKit().expand();
|
||||
|
||||
async test(assert) {
|
||||
await selectKit().expand();
|
||||
|
||||
assert.notEqual(
|
||||
query(
|
||||
".region-input ul li.select-kit-row:first-child"
|
||||
).innerText.trim(),
|
||||
"None",
|
||||
assert
|
||||
.dom(".region-input ul li.select-kit-row:first-child")
|
||||
.hasText(
|
||||
"Argentina",
|
||||
"it does not display the 'None' option when allowNoneRegion is set to false"
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue