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