hedgedoc/cypress/integration/export.spec.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
2020-10-06 06:43:17 -04:00
describe('Export', () => {
const testTitle = 'testContent'
const testContent = `---\ntitle: ${testTitle}\n---\nThis is some test content`
2020-10-06 06:43:17 -04:00
beforeEach(() => {
cy.visit('/n/test')
cy.get('.btn.active.btn-outline-secondary > i.fa-columns')
.should('exist')
cy.get('.CodeMirror')
.click()
.get('textarea')
.fill(testContent)
2020-10-06 06:43:17 -04:00
})
it('Markdown', () => {
cy.get('#editor-menu-export')
.click()
cy.get('a.dropdown-item > i.fa-file-text')
.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.
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) {
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.
resolve(reader.result)
}
reader.readAsText(blob)
2020-10-06 06:43:17 -04:00
}
}
xhr.send()
2020-10-06 06:43:17 -04:00
})
))
// Now the regular Cypress assertions should work.
.should('equal', testContent)
2020-10-06 06:43:17 -04:00
})
})