Feature: Pages
  In order to ensure pages are not tampered with
  As an admin, designer or author
  I will be restricted based on my role

  Background:
    Given I have the site: "test site" set up
    And I have a custom model named "Projects" with
      | label       | type      | required        |
      | Name        | string    | true            |
      | Description | text      | false           |
    And I have a designer and an author
    And a page named "hello-world" with the template:
    """
    Hello World
    """

  Scenario: As an unauthenticated user
    Given I am not authenticated
    When I go to pages
    Then I should see "Log in"

  # listing pages

  Scenario: Accessing pages as an Admin
    Given I am an authenticated "admin"
    When I go to pages
    Then I should see "new page"
    And I should see "new model"
    And I should see "Projects"
    And I should see "edit model"
    And I should see delete page buttons

  Scenario: Accessing pages as a Designer
    Given I am an authenticated "designer"
    When I go to pages
    Then I should see "new page"
    And I should see "new model"
    And I should see "Projects"
    And I should see "edit model"
    And I should see delete page buttons

  Scenario: Accessing pages as an Author
    Given I am an authenticated "author"
    When I go to pages
    Then I should not see "new page"
    And I should not see "new model"
    And I should see "Projects"
    And I should not see "edit model"
    And I should not see delete page buttons

  # new page

  Scenario: Accessing new page as an Admin
    Given I am an authenticated "admin"
    When I go to the new page
    Then I should see "New page"

  Scenario: Accessing new page as a Designer
    Given I am an authenticated "designer"
    When I go to the new page
    Then I should see "New page"

  Scenario: Accessing new page as an Author
    Given I am an authenticated "author"
    When I go to the new page
    Then I should be on the pages list
    And I should see the access denied message

  # edit page

  Scenario: Accessing edit page as an Admin
    Given I am an authenticated "admin"
    When I go to the "hello-world" edition page
    Then I should see "some title"
    And I should see "General information"
    And I should see "SEO settings"
    And I should see "Advanced options"
    And I should see "Template"

  Scenario: Accessing edit page as a Designer
    Given I am an authenticated "designer"
    When I go to the "hello-world" edition page
    Then I should see "some title"
    And I should see "General information"
    And I should see "SEO settings"
    And I should see "Advanced options"
    And I should see "Template"

  Scenario: Accessing edit page as an Author
    Given I am an authenticated "author"
    When I go to the "hello-world" edition page
    Then I should see "some title"
    And I should not see "General Information"
    And I should see "SEO settings"
    And I should not see "Advanced options"
    And I should not see "Template"