1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20240408

This commit is contained in:
KMY 2024-04-08 07:44:47 +09:00
commit 45c5c7b055
27 changed files with 326 additions and 121 deletions

View file

@ -0,0 +1,91 @@
# frozen_string_literal: true
require 'rails_helper'
describe ThemeHelper do
describe 'theme_style_tags' do
let(:result) { helper.theme_style_tags(theme) }
context 'when using system theme' do
let(:theme) { 'system' }
it 'returns the mastodon-light and default stylesheets with correct color schemes' do
expect(html_links.first.attributes.symbolize_keys)
.to include(
href: have_attributes(value: match(/mastodon-light/)),
media: have_attributes(value: 'not all and (prefers-color-scheme: dark)')
)
expect(html_links.last.attributes.symbolize_keys)
.to include(
href: have_attributes(value: match(/default/)),
media: have_attributes(value: '(prefers-color-scheme: dark)')
)
end
end
context 'when using other theme' do
let(:theme) { 'contrast' }
it 'returns the theme stylesheet without color scheme information' do
expect(html_links.first.attributes.symbolize_keys)
.to include(
href: have_attributes(value: match(/contrast/)),
media: have_attributes(value: 'all')
)
end
end
end
describe 'theme_color_tags' do
let(:result) { helper.theme_color_tags(theme) }
context 'when using system theme' do
let(:theme) { 'system' }
it 'returns the mastodon-light and default stylesheets with correct color schemes' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:dark]),
media: have_attributes(value: '(prefers-color-scheme: dark)')
)
expect(html_theme_colors.last.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:light]),
media: have_attributes(value: '(prefers-color-scheme: light)')
)
end
end
context 'when using mastodon-light theme' do
let(:theme) { 'mastodon-light' }
it 'returns the theme stylesheet without color scheme information' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:light])
)
end
end
context 'when using other theme' do
let(:theme) { 'contrast' }
it 'returns the theme stylesheet without color scheme information' do
expect(html_theme_colors.first.attributes.symbolize_keys)
.to include(
content: have_attributes(value: Themes::THEME_COLORS[:dark])
)
end
end
end
private
def html_links
Nokogiri::HTML5.fragment(result).css('link')
end
def html_theme_colors
Nokogiri::HTML5.fragment(result).css('meta[name=theme-color]')
end
end

View file

@ -3,7 +3,7 @@
require 'rails_helper'
describe Admin::Metrics::Dimension::LanguagesDimension do
subject(:dimension) { described_class.new(start_at, end_at, limit, params) }
subject { described_class.new(start_at, end_at, limit, params) }
let(:start_at) { 2.days.ago }
let(:end_at) { Time.now.utc }
@ -11,8 +11,21 @@ describe Admin::Metrics::Dimension::LanguagesDimension do
let(:params) { ActionController::Parameters.new }
describe '#data' do
it 'runs data query without error' do
expect { dimension.data }.to_not raise_error
let(:alice) { Fabricate(:user, locale: 'en', current_sign_in_at: 1.day.ago) }
let(:bob) { Fabricate(:user, locale: 'en', current_sign_in_at: 30.days.ago) }
before do
alice.update(current_sign_in_at: 1.day.ago)
bob.update(current_sign_in_at: 30.days.ago)
end
it 'returns locales with sign in counts' do
expect(subject.data.size)
.to eq(1)
expect(subject.data.map(&:symbolize_keys))
.to contain_exactly(
include(key: 'en', value: '1')
)
end
end
end

View file

@ -247,6 +247,12 @@ describe UserMailer do
describe '#welcome' do
let(:mail) { described_class.welcome(receiver) }
before do
# This is a bit hacky and low-level but this allows stubbing trending tags
tag_ids = Fabricate.times(5, :tag).pluck(:id)
allow(Trends.tags).to receive(:query).and_return(instance_double(Trends::Query, allowed: Tag.where(id: tag_ids)))
end
it 'renders welcome mail' do
expect(mail)
.to be_present

View file

@ -38,6 +38,12 @@ RSpec.describe User do
user.save(validate: false)
expect(user.valid?).to be true
end
it 'is valid with a localhost e-mail address' do
user = Fabricate.build(:user, email: 'admin@localhost')
user.valid?
expect(user.valid?).to be true
end
end
describe 'Normalizations' do

View file

@ -137,6 +137,18 @@ RSpec.describe '/api/web/embed' do
end
end
context 'when sanitizing the fragment fails' do
let(:call_result) { { html: 'ok' } }
before { allow(Sanitize).to receive(:fragment).and_raise(ArgumentError) }
it 'returns http not found' do
subject
expect(response).to have_http_status(404)
end
end
context 'when failing to fetch OEmbed' do
let(:call_result) { nil }

View file

@ -3,13 +3,14 @@
require 'rails_helper'
describe 'Using OAuth from an external app' do
let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/', scopes: 'read') }
let(:client_app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/health', scopes: 'read') }
context 'when the user is already logged in' do
let!(:user) { Fabricate(:user) }
before do
sign_in user, scope: :user
visit new_user_session_path
fill_in_auth_details(user.email, user.password)
end
it 'when accepting the authorization request' do
@ -164,20 +165,19 @@ describe 'Using OAuth from an external app' do
expect(Doorkeeper::AccessGrant.exists?(application: client_app, resource_owner_id: user.id)).to be false
end
end
private
def fill_in_auth_details(email, password)
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
end
def fill_in_otp_details(value)
fill_in 'user_otp_attempt', with: value
click_on I18n.t('auth.login')
end
# TODO: external auth
end
private
def fill_in_auth_details(email, password)
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
end
def fill_in_otp_details(value)
fill_in 'user_otp_attempt', with: value
click_on I18n.t('auth.login')
end
end