2024-01-12 10:19:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe 'Custom CSS' do
|
2024-01-12 10:19:25 +01:00
|
|
|
include RoutingHelper
|
|
|
|
|
|
|
|
describe 'GET /custom.css' do
|
|
|
|
context 'without any CSS or User Roles' do
|
|
|
|
it 'returns empty stylesheet' do
|
|
|
|
get '/custom.css'
|
|
|
|
|
2024-12-06 19:55:47 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_cacheable_headers
|
|
|
|
.and have_attributes(
|
|
|
|
content_type: match('text/css')
|
|
|
|
)
|
|
|
|
expect(response.body.presence)
|
|
|
|
.to be_nil
|
2024-01-12 10:19:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with CSS settings' do
|
|
|
|
before do
|
|
|
|
Setting.custom_css = expected_css
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns stylesheet from settings' do
|
|
|
|
get '/custom.css'
|
|
|
|
|
2024-12-06 19:55:47 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_cacheable_headers
|
|
|
|
.and have_attributes(
|
|
|
|
content_type: match('text/css')
|
|
|
|
)
|
|
|
|
expect(response.body.strip)
|
|
|
|
.to eq(expected_css)
|
2024-01-12 10:19:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def expected_css
|
|
|
|
<<~CSS.strip
|
|
|
|
body { background-color: red; }
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with highlighted colored UserRole records' do
|
|
|
|
before do
|
|
|
|
_highlighted_colored = Fabricate :user_role, highlighted: true, color: '#336699', id: '123_123_123'
|
|
|
|
_highlighted_no_color = Fabricate :user_role, highlighted: true, color: ''
|
|
|
|
_no_highlight_with_color = Fabricate :user_role, highlighted: false, color: ''
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns stylesheet from settings' do
|
|
|
|
get '/custom.css'
|
|
|
|
|
2024-12-06 19:55:47 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_cacheable_headers
|
|
|
|
.and have_attributes(
|
|
|
|
content_type: match('text/css')
|
|
|
|
)
|
|
|
|
expect(response.body.strip)
|
|
|
|
.to eq(expected_css)
|
2024-01-12 10:19:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def expected_css
|
|
|
|
<<~CSS.strip
|
|
|
|
.user-role-123123123 {
|
|
|
|
--user-role-accent: #336699;
|
|
|
|
}
|
|
|
|
CSS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|