require "application_system_test_case"

class PostsTest < ApplicationSystemTestCase
  # Not work, only work in admin namespace. todo
  setup do
    @post = posts(:one)
  end

  test "visiting the index" do
    visit posts_path
    assert_selector "h1", text: "Posts"
  end

  test "should create post" do
    visit posts_path
    click_on "New post"

    fill_in "Category", with: @post.category
    fill_in "Content", with: @post.content
    check "Is draft" if @post.is_draft
    fill_in "Title", with: @post.title
    click_on "Create Post"

    assert_text "Post was successfully created"
    click_on "Back"
  end

  test "should update Post" do
    visit post_path(@post)
    click_on "Edit this post", match: :first

    fill_in "Category", with: @post.category
    fill_in "Content", with: @post.content
    check "Is draft" if @post.is_draft
    fill_in "Title", with: @post.title
    click_on "Update Post"

    assert_text "Post was successfully updated"
    click_on "Back"
  end

  test "should destroy Post" do
    visit post_path(@post)
    click_on "Destroy this post", match: :first

    assert_text "Post was successfully destroyed"
  end
end
