2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-16 07:48:57 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe SiteSerializer do
|
|
|
|
let(:guardian) { Guardian.new }
|
2020-08-19 15:05:04 -04:00
|
|
|
let(:category) { Fabricate(:category) }
|
2019-03-16 07:48:57 -04:00
|
|
|
|
|
|
|
it "includes category custom fields only if its preloaded" do
|
|
|
|
category.custom_fields["enable_marketplace"] = true
|
|
|
|
category.save_custom_fields
|
|
|
|
|
|
|
|
data = MultiJson.dump(described_class.new(Site.new(guardian), scope: guardian, root: false))
|
|
|
|
expect(data).not_to include("enable_marketplace")
|
|
|
|
|
|
|
|
Site.preloaded_category_custom_fields << "enable_marketplace"
|
|
|
|
|
|
|
|
data = MultiJson.dump(described_class.new(Site.new(guardian), scope: guardian, root: false))
|
|
|
|
expect(data).to include("enable_marketplace")
|
|
|
|
end
|
2020-08-19 15:05:04 -04:00
|
|
|
|
|
|
|
it "returns correct notification level for categories" do
|
|
|
|
SiteSetting.mute_all_categories_by_default = true
|
|
|
|
SiteSetting.default_categories_regular = category.id.to_s
|
|
|
|
|
|
|
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
categories = serialized[:categories]
|
|
|
|
expect(categories[0][:notification_level]).to eq(0)
|
|
|
|
expect(categories[-1][:notification_level]).to eq(1)
|
|
|
|
end
|
2020-08-28 10:36:52 -04:00
|
|
|
|
|
|
|
it "includes user-selectable color schemes" do
|
2020-10-14 10:18:02 -04:00
|
|
|
# it includes seeded color schemes
|
2020-08-28 10:36:52 -04:00
|
|
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
2020-10-15 14:05:48 -04:00
|
|
|
expect(serialized[:user_color_schemes].count).to eq(3)
|
2020-08-28 10:36:52 -04:00
|
|
|
|
2020-10-15 14:05:48 -04:00
|
|
|
scheme_names = serialized[:user_color_schemes].map { |x| x[:name] }
|
|
|
|
expect(scheme_names).to include(I18n.t("color_schemes.dark"))
|
|
|
|
expect(scheme_names).to include(I18n.t("color_schemes.wcag"))
|
|
|
|
expect(scheme_names).to include(I18n.t("color_schemes.wcag_dark"))
|
|
|
|
|
|
|
|
dark_scheme = ColorScheme.create_from_base(name: "AnotherDarkScheme", base_scheme_id: "Dark")
|
2020-08-28 10:36:52 -04:00
|
|
|
dark_scheme.user_selectable = true
|
|
|
|
dark_scheme.save!
|
|
|
|
|
|
|
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
2020-10-15 14:05:48 -04:00
|
|
|
expect(serialized[:user_color_schemes].count).to eq(4)
|
2020-08-28 10:36:52 -04:00
|
|
|
expect(serialized[:user_color_schemes][0][:is_dark]).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes default dark mode scheme" do
|
|
|
|
scheme = ColorScheme.last
|
|
|
|
SiteSetting.default_dark_mode_color_scheme_id = scheme.id
|
|
|
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
default_dark_scheme =
|
|
|
|
expect(serialized[:default_dark_color_scheme]["name"]).to eq(scheme.name)
|
|
|
|
|
|
|
|
SiteSetting.default_dark_mode_color_scheme_id = -1
|
|
|
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
expect(serialized[:default_dark_color_scheme]).to eq(nil)
|
|
|
|
end
|
2019-03-16 07:48:57 -04:00
|
|
|
end
|