@statement_attachments
Feature: Accounting Statement Attachments

  # ACC-756, ACC-885, ACC-759, ACC-760
  @ows_accounting
  @frontend_accounting
  Scenario: User can see Statement Attachments for selected period
    Given I am on the Accounting::StatementsPage
    Then the page should include Statement Attachments column
    When I click 'View' button of a period without Statement Attachments
    Then Statement Attachments page should be displayed with all appropriate fields

  # ACC-756, ACC-757, ACC-885
  @ows_accounting
  @frontend_accounting
  Scenario: D3 user can see Statement Attachments for selected period
    Given I am on the AccountingD3::StatementsPage
    Then the page should include Statement Attachments column
    When I click 'View' button of a period without Statement Attachments
    Then Statement Attachments page should be displayed with all appropriate fields

  # ACC-754
  @ows_accounting
  @frontend_accounting
  Scenario: Subaccount user cannot see Statement Attachments column
    Given I am on the AccountingSub::StatementsPage
    Then the page should not include Statement Attachments column

  # ACC-768, ACC-772, ACC-758
  @ows_accounting
  @frontend_accounting
  Scenario: User should be able to download Statement Attachments
    Given I am on the AccountingD3::StatementsPage
    And I use D3 accounting user
    When I click 'View' button for the last period
    And I upload a XLS file to S3 bucket for the selected period
    Then a new record should be created in statement_attachments_success table for XLS file
    When I refresh the page
    And I click 'Get download link' for the last file
    Then the link text should be changed to 'Download'
    When I download the Statement Attachment file
    Then the downloaded file should exactly the same as the just uploaded one

  # ACC-764, ACC-765, ACC-749, ACC-766, ACC-908, ACC-747, ACC-737, ACC-763
  @ows_accounting
  @frontend_accounting
  Scenario Outline: User should be able to see uploaded files on Statement Attachments page
    Given I am on the AccountingD3::StatementsPage
    And I use D3 accounting user
    When I click 'View' button for the last period
    And I upload a <file_type> file to S3 bucket for the selected period
    Then a new record should be created in statement_attachments_success table for <file_type> file
    And I refresh the page
    Then the file should be displayed on the page
    And I should see the upload date "%Y-%m-%d"
    And I should see the file name "auto_test_<file_type>"
    And I should see the file type "<file_type>"
    And I should see the status "Get download link"

    Examples:
      | file_type |
      | PDF       |
      | PNG       |
      | JPG       |
      | XLS       |
      | XLSX      |
      | DOC       |
      | DOCX      |

  # ACC-741, ACC-750, ACC-744
  @ows_accounting
  @frontend_accounting
  Scenario Outline: User should not be able to upload files with invalid extensions
    Given I am on the Accounting::StatementsPage
    When I click 'View' button for the last period
    And I upload a <file_type> file to S3 bucket for the selected period
    Then a new record should be created in statement_attachments_error table for <file_type> file
    And I refresh the page
    Then the file should not be displayed on the page

    Examples:
      | file_type |
      | WAV       |
      | ZIP       |
      | TXT       |

  # ACC-741, ACC-748
  @ows_accounting
  @frontend_accounting
  Scenario Outline: User should not be able to upload a file with invalid name
    When I upload <file_name> file to to qa-statement-attachments S3 bucket directory
    Then a new record should be created in statement_attachments_error table for <file_name> file

    Examples:
      | file_name       |
      | L10303.pdf      |
      | LTEST_229.png   |
      | 229.xls         |
      | L10303_2229.doc |

  # ACC-867
  @ows_accounting
  @frontend_accounting
  Scenario: Attachments file name should contain period id for quarterly label
    Given I am on the Accounting::StatementsPage
    When I click 'View' button for the last period
    And I upload a PNG file to S3 bucket for the selected period
    Then a new record should be created in statement_attachments_success table for PNG file
    And I should see the file name with the selected period id

  # ACC-775
  @ows_accounting
  @frontend_accounting
  Scenario: Statement attachment file should not be displayed on the page if it was removed from S3
    Given I am on the AccountingD3::StatementsPage
    And I use D3 accounting user
    When I click 'View' button for the last period
    And I upload a PDF file to S3 bucket for the selected period
    Then a new record should be created in statement_attachments_success table for PDF file
    When I remove the uploaded PDF file from the qa bucket
    Then the file should not be displayed on the page
