Last active
February 21, 2021 15:26
-
-
Save val99erie/f8aee574dd28904e279f7563fb4b8ea0 to your computer and use it in GitHub Desktop.
A Rails system spec. The user has tasks on their dashboard, similar to a to-do list. They can click a check button to complete a task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'rails_helper' | |
require 'support/login' | |
RSpec.describe "Finishing tasks from dashboard:", type: :system, js: true do | |
let(:project) { Project.create!(title: 'Test Project') } | |
let!(:task_1) { project.tasks.create!(title: 'T111') } | |
let!(:task_2) { project.tasks.create!(title: 'T222') } | |
let(:new_task) { Task.find_by_title('T333') } | |
before { login_user } | |
it 'completes tasks' do | |
expect(Task.count).to eq 2 | |
visit dashboard_path | |
# I should see the tasks on the dashboard | |
expect(page).to have_content 'T111' | |
expect(page).to have_content 'T222' | |
# Click the 'done' link for 'T111' | |
find("a[href='#{complete_task_path(task_1)}']").click | |
# Task 'T111' should no longer be on the page | |
expect(page).to_not have_content 'T111' | |
expect(page).to have_content 'T222' | |
# I should still be on the dashboard | |
expect(page).to have_current_path(dashboard_path) | |
# Create a new task from the dashboard | |
find('.add-task-popup').click | |
fill_in('Title', with: 'T333') | |
click_on 'Create Task' | |
# I should see the newly-created task | |
expect(page).to_not have_content 'T111' | |
expect(page).to have_content 'T222' | |
expect(page).to have_content 'T333' | |
# Click the 'done' link for 'T333' | |
find("a[href='#{complete_task_path(new_task)}']").click | |
# Make sure 'T333' disappears from the page. | |
# This test proves that when a new task gets added | |
# to the page via JavaScript, the task completion | |
# listeners are properly wired up. (If the listeners | |
# aren't working right, then you'd have to reload the | |
# page before you see the task disapper.) | |
expect(page).to_not have_content 'T111' | |
expect(page).to have_content 'T222' | |
expect(page).to_not have_content 'T333' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment