mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: Add Styling step to wizard (#14132)
Refactors three wizard steps (colors, fonts, homepage style) into one new step called Styling.
This commit is contained in:
@@ -167,105 +167,145 @@ describe Wizard::StepUpdater do
|
||||
end
|
||||
end
|
||||
|
||||
context "fonts step" do
|
||||
context "styling step" do
|
||||
it "updates fonts" do
|
||||
updater = wizard.create_updater('fonts', body_font: 'open_sans', heading_font: 'oswald')
|
||||
updater = wizard.create_updater('styling', body_font: 'open_sans', heading_font: 'oswald')
|
||||
updater.update
|
||||
expect(updater.success?).to eq(true)
|
||||
expect(wizard.completed_steps?('fonts')).to eq(true)
|
||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||
expect(SiteSetting.base_font).to eq('open_sans')
|
||||
expect(SiteSetting.heading_font).to eq('oswald')
|
||||
end
|
||||
end
|
||||
|
||||
context "colors step" do
|
||||
context "with an existing color scheme" do
|
||||
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
||||
context "colors" do
|
||||
context "with an existing color scheme" do
|
||||
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
||||
|
||||
it "updates the scheme" do
|
||||
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
||||
updater.update
|
||||
expect(updater.success?).to eq(true)
|
||||
expect(wizard.completed_steps?('colors')).to eq(true)
|
||||
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
||||
end
|
||||
end
|
||||
|
||||
context "with an existing default theme" do
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
|
||||
before do
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it "should not update the default theme when no option has been selected" do
|
||||
expect do
|
||||
wizard.create_updater('colors', {}).update
|
||||
end.to_not change { SiteSetting.default_theme_id }
|
||||
end
|
||||
|
||||
it "should update the color scheme of the default theme" do
|
||||
updater = wizard.create_updater('colors', theme_previews: 'Neutral')
|
||||
expect { updater.update }.not_to change { Theme.count }
|
||||
theme.reload
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('Neutral')
|
||||
end
|
||||
end
|
||||
|
||||
context "without an existing theme" do
|
||||
before do
|
||||
Theme.delete_all
|
||||
end
|
||||
|
||||
context 'dark theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
||||
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
|
||||
theme = Theme.last
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
it "updates the scheme" do
|
||||
updater = wizard.create_updater('styling', color_scheme: 'Dark', body_font: 'arial', heading_font: 'arial', homepage_style: 'latest')
|
||||
updater.update
|
||||
expect(updater.success?).to eq(true)
|
||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
||||
end
|
||||
end
|
||||
|
||||
context 'light theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('colors',
|
||||
theme_previews: ColorScheme::LIGHT_THEME_ID
|
||||
context "with an existing default theme" do
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
|
||||
before do
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it "should update the color scheme of the default theme" do
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: 'Neutral',
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: 'latest'
|
||||
)
|
||||
expect { updater.update }.not_to change { Theme.count }
|
||||
theme.reload
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('Neutral')
|
||||
end
|
||||
end
|
||||
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
context "without an existing theme" do
|
||||
before do
|
||||
Theme.delete_all
|
||||
end
|
||||
|
||||
theme = Theme.last
|
||||
context 'dark theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: 'Dark',
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: 'latest'
|
||||
)
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
|
||||
expect(theme.color_scheme).to eq(ColorScheme.find_by(name:
|
||||
ColorScheme::LIGHT_THEME_ID
|
||||
))
|
||||
theme = Theme.last
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
||||
end
|
||||
end
|
||||
|
||||
context 'light theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: ColorScheme::LIGHT_THEME_ID,
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: 'latest'
|
||||
)
|
||||
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
|
||||
theme = Theme.last
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
|
||||
expect(theme.color_scheme).to eq(ColorScheme.find_by(name:
|
||||
ColorScheme::LIGHT_THEME_ID
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without an existing scheme" do
|
||||
it "creates the scheme" do
|
||||
ColorScheme.destroy_all
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: 'Dark',
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: 'latest'
|
||||
)
|
||||
updater.update
|
||||
expect(updater.success?).to eq(true)
|
||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||
|
||||
color_scheme = ColorScheme.where(via_wizard: true).first
|
||||
expect(color_scheme).to be_present
|
||||
expect(color_scheme.colors).to be_present
|
||||
|
||||
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
||||
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without an existing scheme" do
|
||||
it "creates the scheme" do
|
||||
ColorScheme.destroy_all
|
||||
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
||||
context "homepage style" do
|
||||
it "updates the fields correctly" do
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: 'Dark',
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: "categories_and_top_topics"
|
||||
)
|
||||
updater.update
|
||||
expect(updater.success?).to eq(true)
|
||||
expect(wizard.completed_steps?('colors')).to eq(true)
|
||||
|
||||
color_scheme = ColorScheme.where(via_wizard: true).first
|
||||
expect(color_scheme).to be_present
|
||||
expect(color_scheme.colors).to be_present
|
||||
expect(updater).to be_success
|
||||
expect(wizard.completed_steps?('styling')).to eq(true)
|
||||
expect(SiteSetting.top_menu).to eq('categories|latest|new|unread|top')
|
||||
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
||||
|
||||
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
||||
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
||||
updater = wizard.create_updater('styling',
|
||||
color_scheme: 'Dark',
|
||||
body_font: 'arial',
|
||||
heading_font: 'arial',
|
||||
homepage_style: "latest"
|
||||
)
|
||||
updater.update
|
||||
expect(updater).to be_success
|
||||
expect(SiteSetting.top_menu).to eq('latest|new|unread|top|categories')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "logos step" do
|
||||
@@ -307,23 +347,6 @@ describe Wizard::StepUpdater do
|
||||
end
|
||||
end
|
||||
|
||||
context "homepage step" do
|
||||
it "updates the fields correctly" do
|
||||
updater = wizard.create_updater('homepage', homepage_style: "categories_and_top_topics")
|
||||
updater.update
|
||||
|
||||
expect(updater).to be_success
|
||||
expect(wizard.completed_steps?('homepage')).to eq(true)
|
||||
expect(SiteSetting.top_menu).to eq('categories|latest|new|unread|top')
|
||||
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
||||
|
||||
updater = wizard.create_updater('homepage', homepage_style: "latest")
|
||||
updater.update
|
||||
expect(updater).to be_success
|
||||
expect(SiteSetting.top_menu).to eq('latest|new|unread|top|categories')
|
||||
end
|
||||
end
|
||||
|
||||
context "invites step" do
|
||||
let(:invites) {
|
||||
return [{ email: 'regular@example.com', role: 'regular' },
|
||||
|
||||
@@ -41,12 +41,64 @@ describe Wizard::Builder do
|
||||
expect(invites_step.disabled).to be_truthy
|
||||
end
|
||||
|
||||
context 'fonts step' do
|
||||
let(:fonts_step) { wizard.steps.find { |s| s.id == 'fonts' } }
|
||||
let(:field) { fonts_step.fields.first }
|
||||
context 'styling step' do
|
||||
let(:styling_step) { wizard.steps.find { |s| s.id == 'styling' } }
|
||||
let(:font_field) { styling_step.fields[1] }
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
let(:colors_field) { styling_step.fields.first }
|
||||
|
||||
it 'should set the right font' do
|
||||
expect(field.choices.size).to eq(DiscourseFonts.fonts.size)
|
||||
it 'has the full list of available fonts' do
|
||||
expect(font_field.choices.size).to eq(DiscourseFonts.fonts.size)
|
||||
end
|
||||
|
||||
context "colors" do
|
||||
describe "when the default theme has not been override" do
|
||||
before do
|
||||
SiteSetting.find_by(name: "default_theme_id").destroy!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(colors_field.required).to eq(true)
|
||||
expect(colors_field.value).to eq(ColorScheme::LIGHT_THEME_ID)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been override and the color scheme doesn't have a base scheme" do
|
||||
let(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: nil) }
|
||||
|
||||
before do
|
||||
SiteSetting.default_theme_id = theme.id
|
||||
theme.update(color_scheme: color_scheme)
|
||||
end
|
||||
|
||||
it 'fallbacks to the color scheme name' do
|
||||
expect(colors_field.required).to eq(false)
|
||||
expect(colors_field.value).to eq(color_scheme.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been overridden by a theme without a color scheme" do
|
||||
before do
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(colors_field.required).to eq(false)
|
||||
expect(colors_field.value).to eq("Light")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been overridden by a theme with a color scheme" do
|
||||
before do
|
||||
theme.update(color_scheme_id: ColorScheme.find_by_name("Dark").id)
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(colors_field.required).to eq(false)
|
||||
expect(colors_field.value).to eq("Dark")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -155,57 +207,4 @@ describe Wizard::Builder do
|
||||
end
|
||||
end
|
||||
|
||||
context "colors step" do
|
||||
fab!(:theme) { Fabricate(:theme) }
|
||||
let(:colors_step) { wizard.steps.find { |s| s.id == 'colors' } }
|
||||
let(:field) { colors_step.fields.first }
|
||||
|
||||
describe "when the default theme has not been override" do
|
||||
before do
|
||||
SiteSetting.find_by(name: "default_theme_id").destroy!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(field.required).to eq(true)
|
||||
expect(field.value).to eq(ColorScheme::LIGHT_THEME_ID)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been override and the color scheme doesn't have a base scheme" do
|
||||
let(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: nil) }
|
||||
|
||||
before do
|
||||
SiteSetting.default_theme_id = theme.id
|
||||
theme.update(color_scheme: color_scheme)
|
||||
end
|
||||
|
||||
it 'fallbacks to the color scheme name' do
|
||||
expect(field.required).to eq(false)
|
||||
expect(field.value).to eq(color_scheme.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been overridden by a theme without a color scheme" do
|
||||
before do
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(field.required).to eq(false)
|
||||
expect(field.value).to eq("Light")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the default theme has been overridden by a theme with a color scheme" do
|
||||
before do
|
||||
theme.update(color_scheme_id: ColorScheme.find_by_name("Dark").id)
|
||||
theme.set_default!
|
||||
end
|
||||
|
||||
it 'should set the right default values' do
|
||||
expect(field.required).to eq(false)
|
||||
expect(field.value).to eq("Dark")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user