Skip to content

Commit

Permalink
Preview popup loader (#3157)
Browse files Browse the repository at this point in the history
* Added test for Preview popup document.write

* Render a loader in the Preview popup

* Added minimal styling to popup preview

* Remove React.renderToString()

* Remove <style> type; call document.close()

* Use flexbox; change HTML/CSS string format

* Combine html & css variables

* Mock document.close() in test

* Styled preview popup text
  • Loading branch information
jack-lewin authored and aduth committed Nov 1, 2017
1 parent 0c58880 commit 22af16c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions editor/header/preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ export class PreviewButton extends Component {
'about:blank',
this.getWindowTarget()
);

const markup = `
<div>
<p>Please wait&hellip;</p>
<p>Generating preview.</p>
</div>
<style>
div {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
p {
text-align: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
</style>`;

this.previewWindow.document.write( markup );
this.previewWindow.document.close();
}

render() {
Expand Down
10 changes: 9 additions & 1 deletion editor/header/preview-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ describe( 'PreviewButton', () => {
const autosave = jest.fn();
const preventDefault = jest.fn();
const windowOpen = window.open;
window.open = jest.fn();
window.open = jest.fn( () => {
return {
document: {
write: jest.fn(),
close: jest.fn(),
},
};
} );

const wrapper = shallow(
<PreviewButton { ...props } autosave={ autosave } />
Expand All @@ -66,6 +73,7 @@ describe( 'PreviewButton', () => {
expect( preventDefault ).toHaveBeenCalled();
expect( wrapper.state( 'isAwaitingSave' ) ).toBe( true );
expect( window.open ).toHaveBeenCalled();
expect( wrapper.instance().previewWindow.document.write ).toHaveBeenCalled();
} else {
expect( autosave ).not.toHaveBeenCalled();
expect( preventDefault ).not.toHaveBeenCalled();
Expand Down

0 comments on commit 22af16c

Please sign in to comment.