Skip to content
Extraits de code Groupes Projets
publishing_cuke_helpers.rb 3,53 ko
Newer Older
  • Learn to ignore specific revisions
  • Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
    module PublishingCukeHelpers
    
      def write_in_publisher(txt)
        fill_in 'status_message_fake_text', with: txt
      end
    
    
      def append_to_publisher(txt, input_selector='#status_message_fake_text')
    
    Jonne Haß's avatar
    Jonne Haß a validé
        elem = find(input_selector)
    
        elem.native.send_keys(' ' + txt)
    
        # make sure the other text field got the new contents
    
    Jonne Haß's avatar
    Jonne Haß a validé
        expect(find("#status_message_text", visible: false)).to have_value txt
    
      def upload_file_with_publisher(path)
        page.execute_script(%q{$("input[name='file']").css("opacity", '1');})
        with_scope("#publisher_textarea_wrapper") do
          attach_file("file", Rails.root.join(path).to_s)
    
          # wait for the image to be ready
    
          page.assert_selector(".publisher_photo.loading", count: 0)
        end
      end
    
    
    Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
      def make_post(text)
    
        write_in_publisher(text)
        submit_publisher
      end
    
      def submit_publisher
        txt = find('#publisher #status_message_fake_text').value
        find('#publisher .creation').click
    
        # wait for the content to appear
    
        expect(find('#main_stream')).to have_content(txt)
    
    Dennis Collinson's avatar
    Dennis Collinson a validé
      end
    
      def click_and_post(text)
        click_publisher
        make_post(text)
    
    Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
      end
    
      def click_publisher
        page.execute_script('
    
    Jonne Haß's avatar
    Jonne Haß a validé
         $("#publisher").removeClass("closed");
         $("#publisher").find("#status_message_fake_text").focus();
    
      def publisher_submittable?
    
        submit_btn = find("#publisher button#submit")
    
        !submit_btn[:disabled]
      end
    
    
      def expand_first_post
    
    Jonne Haß's avatar
    Jonne Haß a validé
        within(".stream_element", match: :first) do
          find(".expander").click
    
          expect(page).to have_no_css(".expander")
    
    Jonne Haß's avatar
    Jonne Haß a validé
        end
    
      end
    
      def first_post_collapsed?
    
        expect(find(".stream_element .collapsible", match: :first)).to have_css(".expander")
        expect(page).to have_css(".stream_element .collapsible.collapsed", match: :first)
    
      end
    
      def first_post_expanded?
    
        expect(page).to have_no_css(".stream_element .expander", match: :first)
        expect(page).to have_no_css(".stream_element .collapsible.collapsed", match: :first)
        expect(page).to have_css(".stream_element .collapsible.opened", match: :first)
    
    Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
      def first_post_text
    
    Jonne Haß's avatar
    Jonne Haß a validé
        find(".stream_element .post-content", match: :first).text
    
      def frame_numbers_content(position)
    
        find(".stream-frame:nth-child(#{position}) .content")
    
      end
    
      def find_frame_by_text(text)
    
        find(".stream-frame:contains('#{text}')")
    
      def stream_element_numbers_content(position)
        find(".stream_element:nth-child(#{position}) .post-content")
    
    Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
      end
    
      def find_post_by_text(text)
    
        expect(page).to have_text(text)
    
    Jonne Haß's avatar
    Jonne Haß a validé
        find(".stream_element", text: text)
    
      def within_post(post_text)
        within find_post_by_text(post_text) do
          yield
        end
      end
    
      def like_stream_post(post_text)
    
          find(:css, 'a.like').click
    
      def like_show_page_post
        within("#single-post-actions") do
          find(:css, 'a.like').click
    
        end
      end
    
      def stream_posts
        all('.stream_element')
      end
    
      def comment_on_post(post_text, comment_text)
        within_post(post_text) do
          focus_comment_box
          make_comment(comment_text)
        end
    
    Jonne Haß's avatar
    Jonne Haß a validé
        step %Q(I should see "#{comment_text}" within ".comment")
    
      def comment_on_show_page(comment_text)
    
        within("#single-post-interactions") do
          make_comment(comment_text)
    
        end
      end
    
      def make_comment(text, elem="text")
        fill_in elem, :with => text
    
    Jonne Haß's avatar
    Jonne Haß a validé
        click_button "Comment"
    
      def focus_comment_box(elem="a.focus_comment_textarea")
        find(elem).click
    
    Maxwell Salzberg's avatar
    Maxwell Salzberg a validé
      def assert_nsfw(text)
        post = find_post_by_text(text)
    
        expect(post.find(".nsfw-shield")).to be_present
    
    World(PublishingCukeHelpers)