Skip to content

Commit

Permalink
[test] round trip tests for doctype and xml declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
marmoure committed Nov 12, 2024
1 parent 0f93cd9 commit 7549d01
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions packages/prosemirror-lwdita-demo/cypress/e2e/round-trip.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!
Copyright (C) 2020 Evolved Binary
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

describe('Round Trip', () => {
it('should be able to round trip a document', () => {
// set up the entry xdita
const mockXML = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD LIGHTWEIGHT DITA Topic//EN" "lw-topic.dtd">
<topic id="petal">
<title>What is Petal?</title>
</topic>
`;
window.localStorage.setItem('file', mockXML);
cy.visit('http://localhost:1234/')
.get('#saveFile')
.click()
.readFile('cypress/downloads/Petal.xml')
// compare the output to the input
.should('equal', mockXML);
});

it('should be able to round trip a document without doctype header', () => {
// set up the entry xdita
const mockXML = `
<topic id="petal">
<title>What is Petal?</title>
</topic>
`;
// set up the default doctype header
const doctype = `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE topic PUBLIC "-//OASIS//DTD LIGHTWEIGHT DITA Topic//EN" "lw-topic.dtd">`;
window.localStorage.setItem('file', mockXML);
cy.visit('http://localhost:1234/')
.get('#saveFile')
.click()
.readFile('cypress/downloads/Petal.xml')
// compare the output to the input
.should('equal', doctype + mockXML);
});

it('should be able to round trip a document with a custom doctype header', () => {
// set up the entry xdita
const mockXML = `<?xml version="1.4" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD Custom DITA Topic//EN" "custom.dtd">
<topic id="petal">
<title>What is Petal?</title>
</topic>
`;
// set up the default doctype header
window.localStorage.setItem('file', mockXML);
cy.visit('http://localhost:1234/')
.get('#saveFile')
.click()
.readFile('cypress/downloads/Petal.xml')
// compare the output to the input
.should('equal', mockXML);
});
});

0 comments on commit 7549d01

Please sign in to comment.