|
1 | 1 | RSpec.describe Relaton::Cli::XmlToHtmlRenderer do |
| 2 | + |
| 3 | + let(:document) do |
| 4 | + parse_html(html) |
| 5 | + end |
| 6 | + |
| 7 | + let(:renderer) do |
| 8 | + Relaton::Cli::XmlToHtmlRenderer.new( |
| 9 | + liquid_dir: "templates", |
| 10 | + stylesheet: "spec/assets/index-style.css", |
| 11 | + ) |
| 12 | + end |
| 13 | + |
2 | 14 | describe ".render" do |
3 | | - it "generates the HTML output" do |
4 | | - html = Relaton::Cli::XmlToHtmlRenderer.new( |
5 | | - liquid_dir: "templates", |
6 | | - stylesheet: "spec/assets/index-style.css", |
7 | | - ).render(File.read("spec/assets/index.xml")) |
8 | | - |
9 | | - expect(html).to include("<html") |
10 | | - expect(html).to include("<div class=\"document\"") |
11 | | - expect(html).to include("CC/Amd 86003") |
12 | | - expect(html).to include("CalConnect Inc\.") |
13 | | - expect(html).to include("I AM A SAMPLE STYLESHEET") |
14 | | - expect(html).to include("CalConnect Standards Registry") |
15 | | - expect(html).to match(/<h3>[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+</) |
16 | | - expect(html).to match(/<h3>[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+</) |
17 | | - expect(html).to match(/<div class="doc-stage proposal">[\R\s]+proposal[\R\s]+<\/div>/) |
18 | | - expect(html).to include("http://calconnect.org/pubdocs/CD0507%20CalDAV") |
| 15 | + context "with a document containing a stylesheet" do |
| 16 | + let(:html) do |
| 17 | + renderer.render(File.read("spec/assets/index.xml")) |
| 18 | + end |
| 19 | + |
| 20 | + it "generates the HTML output" do |
| 21 | + expect(html).to include("<html") |
| 22 | + expect(html).to include("<div class=\"document\"") |
| 23 | + expect(html).to include("CC/Amd 86003") |
| 24 | + expect(html).to include("CalConnect Inc\.") |
| 25 | + expect(html).to include("I AM A SAMPLE STYLESHEET") |
| 26 | + expect(html).to include("CalConnect Standards Registry") |
| 27 | + expect(html).to match(/<h3>[^{]+Date and time -- Timezone -- Timezone Manageme[^}]+</) |
| 28 | + expect(html).to match(/<h3>[^{]+Date and time -- Calendars -- Gregorian calendar[^}]+</) |
| 29 | + expect(html).to match(/<div class="doc-stage proposal">[\R\s]+proposal[\R\s]+<\/div>/) |
| 30 | + expect(html).to include("http://calconnect.org/pubdocs/CD0507%20CalDAV") |
| 31 | + end |
19 | 32 | end |
| 33 | + |
| 34 | + context "with a document containing other collections" do |
| 35 | + let(:html) do |
| 36 | + renderer.render(File.read("spec/assets/with-collections.xml")) |
| 37 | + end |
| 38 | + |
| 39 | + it "renders links with relative paths" do |
| 40 | + document.div(class: "document").a.all.each do |a| |
| 41 | + expect(Pathname.new(a[:href])).to be_relative |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "for the only rendered document" do |
| 46 | + subject(:section) do |
| 47 | + document.div(class: 'document')[1] |
| 48 | + end |
| 49 | + |
| 50 | + it "renders with stage" do |
| 51 | + expect(section).to have_css(".doc-stage") |
| 52 | + expect(section.div(class: "doc-info")[:class]).to match 'draft' |
| 53 | + expect(section.div(class: "doc-stage")[:class]).to match 'draft' |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context "for the rendered collections" do |
| 58 | + it "renders without stage" do |
| 59 | + (2..3).map do |i| |
| 60 | + document.div(class: 'document')[i] |
| 61 | + end.each do |e| |
| 62 | + expect(e).to_not have_css(".doc-info") |
| 63 | + expect(e).to_not have_css(".doc-stage") |
| 64 | + end |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + end |
| 69 | + |
20 | 70 | end |
21 | 71 |
|
22 | 72 | describe "#uri_for_extension" do |
23 | 73 | it "replace file extension with the provided one" do |
24 | | - xmltohtml = Relaton::Cli::XmlToHtmlRenderer.new( |
25 | | - stylesheet: "spec/assets/index-style.css", liquid_dir: "templates", |
26 | | - ) |
27 | | - |
28 | 74 | expect( |
29 | | - xmltohtml.uri_for_extension("index.xml", "html"), |
| 75 | + renderer.uri_for_extension("index.xml", "html"), |
30 | 76 | ).to eq("index.html") |
31 | 77 | end |
32 | 78 | end |
|
0 commit comments