2019-04-30 08:27:42 +08:00
# frozen_string_literal: true
2016-02-14 02:29:53 +08:00
require 'rails_helper'
RSpec . describe MetadataController do
2018-11-14 15:03:02 +08:00
let ( :upload ) { Fabricate ( :upload ) }
2018-06-14 11:13:28 +08:00
describe 'manifest.webmanifest' do
2016-02-14 02:29:53 +08:00
it 'returns the right output' do
title = 'MyApp'
SiteSetting . title = title
2018-11-14 15:03:02 +08:00
SiteSetting . large_icon = upload
2017-11-03 13:19:31 +08:00
2018-06-14 11:13:28 +08:00
get " /manifest.webmanifest "
2018-06-07 13:08:28 +08:00
expect ( response . status ) . to eq ( 200 )
2018-06-14 11:13:28 +08:00
expect ( response . content_type ) . to eq ( 'application/manifest+json' )
2017-11-03 13:19:31 +08:00
manifest = JSON . parse ( response . body )
expect ( manifest [ " name " ] ) . to eq ( title )
2018-11-14 15:03:02 +08:00
expect ( manifest [ " icons " ] . first [ " src " ] ) . to eq (
UrlHelper . absolute ( upload . url )
)
2016-02-14 02:29:53 +08:00
end
2018-05-18 03:10:35 +08:00
it 'can guess mime types' do
2018-11-14 15:03:02 +08:00
upload = Fabricate ( :upload ,
original_filename : 'test.jpg' ,
extension : 'jpg'
)
SiteSetting . large_icon = upload
2018-06-14 11:13:28 +08:00
get " /manifest.webmanifest "
2018-11-14 15:03:02 +08:00
2018-06-07 13:08:28 +08:00
expect ( response . status ) . to eq ( 200 )
2018-05-18 03:10:35 +08:00
manifest = JSON . parse ( response . body )
2018-05-18 05:43:22 +08:00
expect ( manifest [ " icons " ] . first [ " type " ] ) . to eq ( " image/jpeg " )
2018-05-18 03:10:35 +08:00
end
it 'defaults to png' do
2018-11-14 15:03:02 +08:00
SiteSetting . large_icon = upload
2018-06-14 11:13:28 +08:00
get " /manifest.webmanifest "
2018-06-07 13:08:28 +08:00
expect ( response . status ) . to eq ( 200 )
2018-05-18 03:10:35 +08:00
manifest = JSON . parse ( response . body )
expect ( manifest [ " icons " ] . first [ " type " ] ) . to eq ( " image/png " )
end
2018-10-27 00:47:22 +08:00
it 'defaults to display standalone for Android' do
get " /manifest.webmanifest " , params : { } , headers : { 'USER-AGENT' = > 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 Mobile Safari/537.36' }
manifest = JSON . parse ( response . body )
expect ( manifest [ " display " ] ) . to eq ( " standalone " )
end
it 'defaults to display browser for iPhone' do
get " /manifest.webmanifest " , params : { } , headers : { 'USER-AGENT' = > 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' }
manifest = JSON . parse ( response . body )
expect ( manifest [ " display " ] ) . to eq ( " browser " )
end
it 'can be changed to display standalone for iPhones using a site setting' do
SiteSetting . pwa_display_browser_regex = " a^ " # this never matches
get " /manifest.webmanifest " , params : { } , headers : { 'USER-AGENT' = > 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' }
manifest = JSON . parse ( response . body )
expect ( manifest [ " display " ] ) . to eq ( " standalone " )
end
2018-11-28 21:55:52 +08:00
it 'uses the short_title if it is set' do
get " /manifest.webmanifest "
expect ( response . status ) . to eq ( 200 )
manifest = JSON . parse ( response . body )
expect ( manifest ) . to_not have_key ( " short_name " )
SiteSetting . short_title = " foo "
get " /manifest.webmanifest "
expect ( response . status ) . to eq ( 200 )
manifest = JSON . parse ( response . body )
expect ( manifest [ " short_name " ] ) . to eq ( " foo " )
end
2016-02-14 02:29:53 +08:00
end
describe 'opensearch.xml' do
it 'returns the right output' do
title = 'MyApp'
SiteSetting . title = title
2018-11-14 15:03:02 +08:00
SiteSetting . favicon = upload
2018-06-07 13:08:28 +08:00
get " /opensearch.xml "
2018-11-14 15:03:02 +08:00
2018-06-07 13:08:28 +08:00
expect ( response . status ) . to eq ( 200 )
2016-02-14 02:29:53 +08:00
expect ( response . body ) . to include ( title )
expect ( response . body ) . to include ( " /search?q={searchTerms} " )
expect ( response . body ) . to include ( 'image/png' )
2018-11-14 15:03:02 +08:00
expect ( response . body ) . to include ( UrlHelper . absolute ( upload . url ) )
2016-02-14 02:29:53 +08:00
expect ( response . content_type ) . to eq ( 'application/xml' )
end
end
end