# -*- encoding: UTF-8 -*- require 'test_helper' require 'webmock/minitest' module Wovnrb class ReplacerBaseTest < WovnMiniTest def test_wovn_ignore store = Store.instance replacer = ReplacerBase.new(store) dom = Wovnrb.to_dom('
') actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0]) assert(actual) end def test_wovn_ignore_parent store = Store.instance replacer = ReplacerBase.new(store) dom = Wovnrb.to_dom('
') actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0]) assert(actual) end def test_wovn_ignore_without_attribute store = Store.instance replacer = ReplacerBase.new(store) dom = Wovnrb.to_dom('
') actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0]) assert_equal(false, actual) end def test_wovn_ignore_class store = Store.instance store.settings('ignore_class' => ['base_ignore']) replacer = ReplacerBase.new(store) dom = Wovnrb.to_dom('
') actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0]) assert(actual) end def test_wovn_ignore_multiple_classes store = Store.instance store.settings('ignore_class' => ['base_ignore', 'base_ignore2']) replacer = ReplacerBase.new(store) html = <

HTML dom = Wovnrb.to_dom(html) assert(replacer.send(:wovn_ignore?, dom.xpath('//div')[0])) assert(replacer.send(:wovn_ignore?, dom.xpath('//span')[0])) assert_equal(false, replacer.send(:wovn_ignore?, dom.xpath('//p')[0])) end def test_replace_text store = Store.instance replacer = ReplacerBase.new(store) actual = replacer.send(:replace_text, 'Hello', 'こんにちは') assert_equal('こんにちは', actual) end def test_replace_text_with_space store = Store.instance replacer = ReplacerBase.new(store) actual = replacer.send(:replace_text, ' Hello ', 'こんにちは') assert_equal(' こんにちは ', actual) end def test_replace_text_with_line_break store = Store.instance replacer = ReplacerBase.new(store) actual = replacer.send(:replace_text, " Hello \n Hello ", 'こんにちは') assert_equal(' こんにちは ', actual) end def test_add_comment_node store = Store.instance replacer = ReplacerBase.new(store) html = Nokogiri::HTML5('

Test Content

') h1 = html.xpath("//h1[@id='test-node']")[0] assert_equal('Test Content', h1.inner_html) h1.xpath('//text()').each do |node| text_content = node.content if text_content == 'Test Content' replacer.send(:add_comment_node, node, 'test content') end end assert_equal("Test Content", h1.inner_html) end end end