2020-11-22 15:50:07 -05:00
|
|
|
/*
|
2021-01-06 15:37:59 -05:00
|
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
2020-11-22 15:50:07 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2020-10-06 06:43:17 -04:00
|
|
|
describe('Export', () => {
|
2021-01-11 17:22:11 -05:00
|
|
|
const testTitle = 'testContent'
|
2021-02-03 16:13:04 -05:00
|
|
|
const testContent = `---\ntitle: ${ testTitle }\n---\nThis is some test content`
|
2021-01-11 17:22:11 -05:00
|
|
|
|
2020-10-06 06:43:17 -04:00
|
|
|
beforeEach(() => {
|
2021-03-09 17:00:14 -05:00
|
|
|
cy.loadConfig()
|
2021-02-01 16:55:49 -05:00
|
|
|
cy.visitTestEditor()
|
2021-01-15 16:54:43 -05:00
|
|
|
cy.codemirrorFill(testContent)
|
2020-10-06 06:43:17 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Markdown', () => {
|
2021-01-24 15:39:47 -05:00
|
|
|
cy.get('[data-cy="menu-export"]')
|
2020-10-06 06:43:17 -04:00
|
|
|
.click()
|
2021-01-24 15:39:47 -05:00
|
|
|
cy.get('[data-cy="menu-export-markdown"]')
|
2020-10-06 06:43:17 -04:00
|
|
|
.click()
|
|
|
|
cy.get('a[download]')
|
|
|
|
.then((anchor) => (
|
|
|
|
new Cypress.Promise((resolve: any, _: any) => {
|
|
|
|
// Use XHR to get the blob that corresponds to the object URL.
|
2021-01-11 17:22:11 -05:00
|
|
|
const xhr = new XMLHttpRequest()
|
|
|
|
xhr.open('GET', anchor.prop('href'), true)
|
|
|
|
xhr.responseType = 'blob'
|
2020-10-06 06:43:17 -04:00
|
|
|
|
|
|
|
// Once loaded, use FileReader to get the string back from the blob.
|
|
|
|
xhr.onload = () => {
|
|
|
|
if (xhr.status === 200) {
|
2021-01-11 17:22:11 -05:00
|
|
|
const blob = xhr.response
|
|
|
|
const reader = new FileReader()
|
2020-10-06 06:43:17 -04:00
|
|
|
reader.onload = () => {
|
|
|
|
// Once we have a string, resolve the promise to let
|
|
|
|
// the Cypress chain continue, e.g. to assert on the result.
|
2021-01-11 17:22:11 -05:00
|
|
|
resolve(reader.result)
|
|
|
|
}
|
|
|
|
reader.readAsText(blob)
|
2020-10-06 06:43:17 -04:00
|
|
|
}
|
2021-01-11 17:22:11 -05:00
|
|
|
}
|
|
|
|
xhr.send()
|
2020-10-06 06:43:17 -04:00
|
|
|
})
|
|
|
|
))
|
|
|
|
// Now the regular Cypress assertions should work.
|
2021-01-11 17:22:11 -05:00
|
|
|
.should('equal', testContent)
|
2020-10-06 06:43:17 -04:00
|
|
|
})
|
|
|
|
})
|