<commit_before>require 'spec_helper'

describe "getting a bunch of screenshots", js: true do

  def screenshot(path)
    page.driver.browser.manage.window.resize_to(1024,640)
    page.save_screenshot(path)
    i = Magick::ImageList.new(path)
    small = i.resize_to_fit(1024 / 1.5)
    small.write(path)
    #exec("open #{path}")
  end

  before :each do
    ApplicationController.any_instance.stub(force_ssl?: false)
  end

  context "no users" do
    it "sign up page" do
      visit new_admin_registration_path
      screenshot("app/assets/images/screenshot1.png")
    end
  end

  context "users" do
    before :each do
      @admin = Admin.create!(email: '<EMAIL>', password: '<PASSWORD>')
    end

    it "landing page" do
      visit new_admin_session_path
      fill_in "Email", with: "<EMAIL>"
      fill_in "Password", with: "<PASSWORD>"
      click_button "Login"
      screenshot("app/assets/images/screenshot2.png")
    end
  end

end<commit_msg>Take screenshot of email that's been delivered and opened<commit_after>require 'spec_helper'

describe "getting a bunch of screenshots", js: true do

  def screenshot(path)
    page.driver.browser.manage.window.resize_to(1024,640)
    page.save_screenshot(path)
    i = Magick::ImageList.new(path)
    small = i.resize_to_fit(1024 / 1.5)
    small.write(path)
    #exec("open #{path}")
  end

  before :each do
    ApplicationController.any_instance.stub(force_ssl?: false)
  end

  context "no users" do
    it "sign up page" do
      visit new_admin_registration_path
      screenshot("app/assets/images/screenshot1.png")
    end
  end

  context "users" do
    before :each do
      Admin.create!(email: '<EMAIL>', password: '<PASSWORD>')
      visit new_admin_session_path
      fill_in "Email", with: "<EMAIL>"
      fill_in "Password", with: "<PASSWORD>"
      click_button "Login"
    end

    it "landing page" do
      screenshot("app/assets/images/screenshot2.png")
    end

    context "an email" do
      before :each do
        mail = Mail.new do
          text_part do
            body "This can be anything because it isn't actually seen in the screenshot"
          end

          html_part do
            content_type 'text/html; charset=UTF-8'
            body <<-EOF 
<div>
  It's pretty good to be able to wake up and go for a walk in place like this five minutes from where you live.
</div>
<div>
  <br>
</div>
<img src="https://pbs.twimg.com/media/BGUKkJ2CEAAIQWI.jpg:large" alt="Inline image 1" width="564" height="423">
<div>
  <br>
</div>
<div>
  I know this an automated email and all but can you please take a look at the
  <a href="http://github.com/mlandauer/cuttlefish">latest code on Github</a>?
  Thanks!
</div>
<br>
<div>
  <br>
</div>
-- <br>
<div>
  Your friendly Cuttlefish<br>
  <br>
  <a href="mailto:<EMAIL>"><EMAIL></a>
</div>
            EOF
          end
        end
        @email = Email.create!(from: "<EMAIL>", to: "<EMAIL>", data: mail.encoded)
        @delivery = @email.deliveries.first
        @delivery.update_attributes(sent: true)
        FactoryGirl.create(:postfix_log_line, delivery: @delivery,
            time: 5.minutes.ago, dsn: "2.0.0", extended_status: "sent (250 2.0.0 r6ay1l02Y4aTF9m016ayyY mail accepted for delivery)")
        FactoryGirl.create(:open_event, delivery: @delivery, created_at: 2.minutes.ago, user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31",
          ip: "1.2.3.4")
      end

      it "email" do
        visit delivery_path(@delivery)
        click_link "Delivered"
        click_link "Opened"
        # Wait until jquery animation finishes
        page.evaluate_script('$(":animated").length') == 0 
        screenshot("app/assets/images/screenshot3.png")
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.1219832109129066, 'fraction_numerical': 0.0236096537250787, 'mean_word_length': 2.914784394250513, 'pattern_counts': {'":': 1, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4134127', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1286, 'n_words': 339}