|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe "keyboard shortcuts" do |
| 4 | + after { visit(logout_path) } |
| 5 | + |
| 6 | + def create_stories_and_visit |
| 7 | + create(:story, title: "First Story", body: "First Body") |
| 8 | + create(:story, title: "Second Story", body: "Second Body") |
| 9 | + visit(news_path) |
| 10 | + end |
| 11 | + |
| 12 | + it "opens a story with j" do |
| 13 | + login_as(default_user) |
| 14 | + create_stories_and_visit |
| 15 | + |
| 16 | + send_keys("j") |
| 17 | + |
| 18 | + expect(page).to have_css("li.story.open") |
| 19 | + end |
| 20 | + |
| 21 | + it "navigates up with k" do |
| 22 | + login_as(default_user) |
| 23 | + create_stories_and_visit |
| 24 | + |
| 25 | + send_keys("j", "j", "k") |
| 26 | + |
| 27 | + expect(page).to have_css("li.story.open", count: 1) |
| 28 | + end |
| 29 | + |
| 30 | + it "moves cursor without opening with n" do |
| 31 | + login_as(default_user) |
| 32 | + create_stories_and_visit |
| 33 | + |
| 34 | + send_keys("n") |
| 35 | + |
| 36 | + expect(page).to have_css("li.story.cursor:not(.open)") |
| 37 | + end |
| 38 | + |
| 39 | + it "moves cursor without opening with p" do |
| 40 | + login_as(default_user) |
| 41 | + create_stories_and_visit |
| 42 | + send_keys("n", "n") |
| 43 | + |
| 44 | + send_keys("p") |
| 45 | + |
| 46 | + expect(page).to have_css("li.story.cursor:not(.open)") |
| 47 | + end |
| 48 | + |
| 49 | + it "toggles a story open and closed with o" do |
| 50 | + login_as(default_user) |
| 51 | + create_stories_and_visit |
| 52 | + send_keys("o") |
| 53 | + |
| 54 | + send_keys("o") |
| 55 | + |
| 56 | + expect(page).to have_no_css("li.story.open") |
| 57 | + end |
| 58 | + |
| 59 | + def create_story_and_visit(title:) |
| 60 | + create(:story, title:) |
| 61 | + visit(news_path) |
| 62 | + end |
| 63 | + |
| 64 | + it "stars the current story with s" do |
| 65 | + login_as(default_user) |
| 66 | + create_story_and_visit(title: "My Story") |
| 67 | + send_keys("j", "s") |
| 68 | + |
| 69 | + visit(starred_path) |
| 70 | + |
| 71 | + expect(page).to have_content("My Story") |
| 72 | + end |
| 73 | +end |
0 commit comments