From b5eb3465307344b2ed91fcc74baf842d53ffa74f Mon Sep 17 00:00:00 2001 From: Michael Taranto Date: Mon, 29 Jul 2019 14:21:47 +1000 Subject: [PATCH] fix: Resolve prettier formatting error (#77) --- cypress/integration/smokeTest.spec.js | 13 ++++++++++++- cypress/support/index.js | 14 ++++++++------ cypress/support/utils.js | 24 +++++++++++++++++++----- package.json | 2 +- src/Playroom/Playroom.js | 2 +- yarn.lock | 5 +++++ 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/cypress/integration/smokeTest.spec.js b/cypress/integration/smokeTest.spec.js index db9971b1..f0679057 100644 --- a/cypress/integration/smokeTest.spec.js +++ b/cypress/integration/smokeTest.spec.js @@ -1,7 +1,9 @@ import { + formatCode, typeCode, assertFrameContains, - assertCodePaneContains + assertCodePaneContains, + assertCodePaneLineCount } from '../support/utils'; describe('Smoke test', () => { @@ -18,4 +20,13 @@ describe('Smoke test', () => { assertFrameContains('Foo'); assertCodePaneContains(''); }); + + it('formats', () => { + cy.visit( + 'http://localhost:9000/#?code=PEZvbz48Rm9vPjxCYXIvPjwvRm9vPjwvRm9vPg' + ).reload(); + assertCodePaneLineCount(1); + formatCode(); + assertCodePaneLineCount(6); + }); }); diff --git a/cypress/support/index.js b/cypress/support/index.js index 696cff11..db0714d1 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -1,7 +1,9 @@ -beforeEach(async () => { - cy.visit('http://localhost:9000'); - - const win = await cy.window(); - const { storageKey } = win.__playroomConfig__; - indexedDB.deleteDatabase(storageKey); +beforeEach(() => { + cy.visit('http://localhost:9000') + .window() + .then(win => { + const { storageKey } = win.__playroomConfig__; + indexedDB.deleteDatabase(storageKey); + }) + .visit('http://localhost:9000'); }); diff --git a/cypress/support/utils.js b/cypress/support/utils.js index cbee089b..7146d624 100644 --- a/cypress/support/utils.js +++ b/cypress/support/utils.js @@ -1,21 +1,35 @@ +const getCodeEditor = () => cy.get('.CodeMirror'); + export const typeCode = code => - cy - .get('.CodeMirror') + getCodeEditor() .click() .focused() .clear({ force: true }) .type(code, { force: true, delay: 100 }) .wait(1000); +export const formatCode = () => + getCodeEditor() + .click() + .focused() + .type(`${navigator.platform.match('Mac') ? '{cmd}' : '{ctrl}'}s`) + .wait(1000); + export const assertFrameContains = async text => { const iframe = await cy.get('iframe').first(); - return iframe + iframe .contents() .find('body') .contains(text); }; -export const assertCodePaneContains = async text => { - return cy.get('.react-codemirror2').contains(text); +export const assertCodePaneContains = text => { + getCodeEditor().contains(text); +}; + +export const assertCodePaneLineCount = lines => { + getCodeEditor().within(() => + cy.get('.CodeMirror-line').should('have.length', lines) + ); }; diff --git a/package.json b/package.json index 8b94fe7a..d9ed0589 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "less": "^3.8.1", "less-loader": "^4.1.0", "localforage": "^1.7.2", - "lodash": "^4.17.11", + "lodash": "^4.17.15", "mini-css-extract-plugin": "^0.4.3", "opn": "^5.4.0", "parse-prop-types": "^0.3.0", diff --git a/src/Playroom/Playroom.js b/src/Playroom/Playroom.js index 5019b7c9..d2a21e5e 100644 --- a/src/Playroom/Playroom.js +++ b/src/Playroom/Playroom.js @@ -197,7 +197,7 @@ export default class Playroom extends Component { const { formattedCode, line, ch } = formatCode({ code, - cursor: this.editorInstance.codeMirror.getCursor() + cursor: this.editorInstance.getCursor() }); this.setState({ code: formattedCode }); diff --git a/yarn.lock b/yarn.lock index 0cb3e73a..4af59022 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6322,6 +6322,11 @@ lodash@4.17.11, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.2 version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" +lodash@^4.17.15: + version "4.17.15" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" + integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + log-symbols@2.2.0, log-symbols@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"