mirror of
https://github.com/neocities/neocities.git
synced 2025-08-05 01:01:30 +02:00
fix tag tests, start on education site creation, updated test code
This commit is contained in:
parent
f00e5d0757
commit
49defcd0c7
14 changed files with 627 additions and 623 deletions
61
tests/acceptance/education_tests.rb
Normal file
61
tests/acceptance/education_tests.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require_relative './environment.rb'
|
||||
|
||||
Capybara.register_driver :poltergeist do |app|
|
||||
Capybara::Poltergeist::Driver.new(app, js_errors: false)
|
||||
end
|
||||
|
||||
describe 'signup' do
|
||||
include Capybara::DSL
|
||||
|
||||
def fill_in_valid
|
||||
@site = Fabricate.attributes_for(:site)
|
||||
@class_tag = SecureRandom.uuid.gsub('-', '')[0..Tag::NAME_LENGTH_MAX-1]
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
fill_in 'email', with: @site[:email]
|
||||
fill_in 'new_tags_string', with: @class_tag
|
||||
end
|
||||
|
||||
before do
|
||||
Capybara.default_driver = :poltergeist
|
||||
Capybara.reset_sessions!
|
||||
visit '/education'
|
||||
page.must_have_content 'Neocities' # Used to force load wait
|
||||
end
|
||||
|
||||
after do
|
||||
Capybara.default_driver = :rack_test
|
||||
end
|
||||
|
||||
it 'succeeds with valid data' do
|
||||
fill_in_valid
|
||||
click_button 'Create My Site'
|
||||
page.must_have_content 'Welcome to Neocities'
|
||||
|
||||
index_file_path = File.join Site::SITE_FILES_ROOT, @site[:username], 'index.html'
|
||||
File.exist?(index_file_path).must_equal true
|
||||
|
||||
site = Site[username: @site[:username]]
|
||||
site.site_files.length.must_equal 4
|
||||
site.site_changed.must_equal false
|
||||
site.site_updated_at.must_equal nil
|
||||
site.is_education.must_equal true
|
||||
site.tags.length.must_equal 1
|
||||
site.tags.first.name.must_equal @class_tag
|
||||
end
|
||||
|
||||
it 'fails to create for existing site' do
|
||||
@existing_site = Fabricate :site
|
||||
fill_in_valid
|
||||
fill_in :username, with: @existing_site.username
|
||||
click_button 'Create My Site'
|
||||
page.must_have_content 'already taken'
|
||||
end
|
||||
|
||||
it 'fails for multiple tags' do
|
||||
fill_in_valid
|
||||
fill_in :new_tags_string, with: 'derp, ie'
|
||||
click_button 'Create My Site'
|
||||
page.must_have_content 'Must only have one tag'
|
||||
end
|
||||
end
|
|
@ -4,4 +4,6 @@ Capybara.app = Sinatra::Application
|
|||
|
||||
def teardown
|
||||
Capybara.reset_sessions!
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.default_wait_time = 5
|
||||
|
|
|
@ -30,6 +30,7 @@ describe 'signup' do
|
|||
Capybara.default_driver = :poltergeist
|
||||
Capybara.reset_sessions!
|
||||
visit_signup
|
||||
page.must_have_content 'Neocities' # Used to force load wait
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -48,19 +49,15 @@ describe 'signup' do
|
|||
site.site_files.length.must_equal 4
|
||||
site.site_changed.must_equal false
|
||||
site.site_updated_at.must_equal nil
|
||||
site.is_education.must_equal false
|
||||
|
||||
site.ip.must_equal Site.hash_ip('127.0.0.1')
|
||||
end
|
||||
|
||||
it 'fails to create for existing site' do
|
||||
@existing_site = Fabricate :site
|
||||
fill_in_valid
|
||||
click_signup_button
|
||||
page.must_have_content 'Welcome to Neocities'
|
||||
Capybara.reset_sessions!
|
||||
visit_signup
|
||||
sleep 0.3
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
fill_in 'username', with: @existing_site.username
|
||||
click_signup_button
|
||||
page.must_have_content 'already taken'
|
||||
end
|
||||
|
@ -113,9 +110,6 @@ describe 'signup' do
|
|||
page.must_have_content /email.+exists/
|
||||
end
|
||||
|
||||
puts "$$$$$$$$$$$$$$$$$$$$$$ TODO FIX TAGS TESTS"
|
||||
|
||||
=begin
|
||||
it 'succeeds with no tags' do
|
||||
fill_in_valid
|
||||
fill_in 'new_tags_string', with: ''
|
||||
|
@ -139,7 +133,7 @@ puts "$$$$$$$$$$$$$$$$$$$$$$ TODO FIX TAGS TESTS"
|
|||
Site.last.tags.collect {|t| t.name}.must_equal ['derpie', 'shoujo']
|
||||
end
|
||||
|
||||
it 'fails with invalid tag chars' do
|
||||
it 'fails with invalid tag chars' do
|
||||
fill_in_valid
|
||||
fill_in 'new_tags_string', with: '$POLICE OFFICER$$$$$, derp'
|
||||
click_signup_button
|
||||
|
@ -179,9 +173,10 @@ puts "$$$$$$$$$$$$$$$$$$$$$$ TODO FIX TAGS TESTS"
|
|||
fill_in 'new_tags_string', with: 'one, one'
|
||||
click_signup_button
|
||||
|
||||
site = Site.last
|
||||
page.must_have_content /Welcome to Neocities/
|
||||
|
||||
site = Site[username: @site[:username]]
|
||||
site.tags.length.must_equal 1
|
||||
site.tags.first.name.must_equal 'one'
|
||||
end
|
||||
=end
|
||||
end
|
||||
|
|
|
@ -167,14 +167,6 @@ describe 'api upload' do
|
|||
'/' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:error_type].must_equal 'invalid_file_type'
|
||||
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload', {
|
||||
'' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
end
|
||||
|
||||
it 'fails for file with no extension' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue