Skip to content

Commit

Permalink
WIP: Upload test
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Feb 6, 2023
1 parent c44fb2f commit 6223877
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/factories/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :task do
display_name { '1st USA olympiad task number 1' }
file_names { ['task1.md'] }
end
end
42 changes: 42 additions & 0 deletions spec/features/upload_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'rails_helper'

RSpec.describe 'Upload', ui: true do
let(:upload_path) { "/contests/#{contest.id}/upload/new" }
let(:file_path) { "/contests/#{contest.id}/upload" }

let(:contest) { create(:contest) }
let!(:task) { create(:task, contest:) }
let(:user) { create(:user, contest:) }

before { visit upload_path }

describe 'solution for task' do
before do
fill_inputs 'upload', user.slice(:secret)
click_button 'commit'
end

context 'with valid file' do
before do
# TODO: FIX upload[solutions_attributes][0][file]
attach_file 'upload[solutions_attributes][0][file]', 'spec/support/fixtures/tasks_solutions/task1_ok/task1.md'
click_button 'commit'
end

it { expect(page).to have_content "#{task.display_name}: успішно завантажений на сервер" }
end

context 'with empty file' do
before do
# TODO: FIX upload[solutions_attributes][0][file]
attach_file 'upload[solutions_attributes][0][file]', 'spec/support/fixtures/tasks_solutions/task1_empty/task1.md'
click_button 'commit'
end

it {
expect(page).to have_content \
"#{task.display_name}: Помилка! Файл не може бути порожнім (0 байт). Можливо, файл відкрито у програмі MS Office."
}
end
end
end
Empty file.
1 change: 1 addition & 0 deletions spec/support/fixtures/tasks_solutions/task1_ok/task1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Some task solution

0 comments on commit 6223877

Please sign in to comment.