Skip to content

Commit

Permalink
Slate, webpack, toastify and cypress (#6852)
Browse files Browse the repository at this point in the history
* chore: upgrade slate editor to 0.9

* chore: upgrade slate editor to 0.9

* chore: update cypress to 12, update configs and tests to work with it

* chore: replace redux-notifications with toastify

* chore: lint & test recent changes

* chore: upgrade slate editor to 0.9

* chore: update webpack to 5

* chore: upgrade slate editor to 0.9

* chore: lint & test recent changes

* chore: update code to ts4

* chore: lint proxy server and lint some code

* chore: lint & set node version in workflow

* fix: update ObjectControl and ListControl proptypes

* fix: add table renderers and serializers

* feat: add history to visual and raw editor

* feat: add thematic break

* fix: add image renderer and fix thematic-break

* chore: cleanup old slate code

* test: deploy rc
  • Loading branch information
demshy committed Jul 27, 2023
1 parent e0c5eba commit b806c55
Show file tree
Hide file tree
Showing 192 changed files with 9,271 additions and 7,566 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
},
],
'unicorn/prefer-string-slice': 'error',
'react/no-unknown-property': ['error', { ignore: ['css', 'bold', 'italic', 'delete'] }],
},
plugins: ['babel', '@emotion', 'cypress', 'unicorn'],
settings: {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '*'
node-version: 18
check-latest: true
if: ${{ needs.changes.outputs.cms == 'true' }}
- name: log versions
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '*'
node-version: 18
check-latest: true
cache: yarn
if: ${{ needs.changes.outputs.cms == 'true' }}
Expand Down
15 changes: 9 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path');
const { extendDefaultPlugins } = require('svgo');

const appVersion = require('./packages/netlify-cms-app/package.json').version;
const coreVersion = require('./packages/netlify-cms-core/package.json').version;
Expand Down Expand Up @@ -28,12 +27,16 @@ const defaultPlugins = [
];

const svgo = {
plugins: extendDefaultPlugins([
plugins: [
{
name: 'removeViewBox',
active: false,
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
]),
],
};

function presets() {
Expand Down Expand Up @@ -83,7 +86,7 @@ function plugins() {
}

if (!isProduction) {
return [...defaultPlugins, 'react-hot-loader/babel'];
return [...defaultPlugins];
}

return defaultPlugins;
Expand Down
20 changes: 20 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineConfig } from 'cypress';

export default defineConfig({
projectId: '1c35bs',
retries: {
runMode: 4,
openMode: 0,
},
e2e: {
video: false,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require('./cypress/plugins/index.js')(on, config);
},
baseUrl: 'http://localhost:8080',
specPattern: 'cypress/e2e/*spec*.js',
},
});
9 changes: 0 additions & 9 deletions cypress.json

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const updateTranslation = () => {

enterTranslation('de de');
});
flushClockAndSave();
cy.contains('button', 'Save').click();
};

export const assertTranslation = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { workflowStatus } from '../../utils/constants';
function uploadMediaFile() {
assertNoImagesInLibrary();

const fixture = 'media/netlify.png';
cy.get('input[type="file"]').attachFile(fixture);
const fixture = 'cypress/fixtures/media/netlify.png';
cy.get('input[type="file"]').selectFile(fixture, { force: true });
cy.contains('span', 'Uploading...').should('not.exist');

assertImagesInLibrary();
Expand All @@ -41,6 +41,7 @@ function deleteImage() {
}

function chooseSelectedMediaFile() {
cy.contains('button', 'Choose selected').should('not.be.disabled');
cy.contains('button', 'Choose selected').click();
}

Expand All @@ -49,6 +50,7 @@ function chooseAnImage() {
}

function waitForEntryToLoad() {
cy.contains('button', 'Saving...').should('not.exist');
cy.contains('div', 'Loading entry...').should('not.exist');
}

Expand All @@ -71,6 +73,8 @@ function newPostWithImage(entry) {

function publishPostWithImage(entry) {
newPostWithImage(entry);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(500);
exitEditor();
goToWorkflow();
updateWorkflowStatus(entry, workflowStatus.draft, workflowStatus.ready);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ en:
template: post
date: 1970-01-01T00:00:00.000Z
title: first title
body: first body
description: first description
category: first category
tags:
- tag1
body: first body
de:
date: 1970-01-01T00:00:00.000Z
title: de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ describe('Markdown widget', () => {
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend: 'test' });
cy.loginAndNewPost();

});

beforeEach(() => {
cy.loginAndNewPost();
cy.clearMarkdownEditorContent();
});

after(() => {
cy.task('teardownBackend', { backend: 'test' });
});

describe('pressing backspace', () => {
// describe('pressing backspace', () => {
it('sets non-default block to default when empty', () => {
cy.focused()
.clickHeadingOneButton()
Expand Down Expand Up @@ -88,6 +89,6 @@ describe('Markdown widget', () => {
.confirmMarkdownEditorContent(`
<p>foobarbaz</p>
`);
});
// });
});
});
135 changes: 135 additions & 0 deletions cypress/e2e/markdown_widget_code_block_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { oneLineTrim, stripIndent } from 'common-tags';
import '../utils/dismiss-local-backup';

describe('Markdown widget code block', () => {
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend: 'test' });
});

beforeEach(() => {
cy.loginAndNewPost();
cy.clearMarkdownEditorContent();
});

after(() => {
cy.task('teardownBackend', { backend: 'test' });
});
describe('code block', () => {
it('outputs code', () => {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy
.insertCodeBlock()
.type('foo')
.enter()
.type('bar')
.confirmMarkdownEditorContent(
`
${codeBlock(`
foo
bar
`)}
`,
)
.wait(500)
.clickModeToggle().confirmMarkdownEditorContent(`
${codeBlockRaw(`
foo
bar
`)}
`);
});
});
});

function codeBlockRaw(content) {
return ['```', ...stripIndent(content).split('\n'), '```']
.map(
line => oneLineTrim`
<div>
<span>
<span>
<span>${line}</span>
</span>
</span>
</div>
`,
)
.join('');
}

function codeBlock(content) {
const lines = stripIndent(content)
.split('\n')
.map(
(line, idx) => `
<div>
<div>
<div>${idx + 1}</div>
</div>
<pre><span>${line}</span></pre>
</div>
`,
)
.join('');

return oneLineTrim`
<div>
<div></div>
<div>
<div><label>Code Block </label>
<div><button><span><svg>
<path></path>
</svg></span></button>
<div>
<div>
<div><textarea></textarea></div>
<div>
<div></div>
</div>
<div>
<div></div>
</div>
<div></div>
<div></div>
<div>
<div>
<div>
<div>
<div>
<div>
<pre><span>xxxxxxxxxx</span></pre>
</div>
<div></div>
<div></div>
<div>
<div> </div>
</div>
<div>
${lines}
</div>
</div>
</div>
</div>
</div>
<div></div>
<div>
<div></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<span>
<span>
<span></span>
</span>
</span>
</div>
</div>
<div></div>
</div>
`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ describe('Markdown widget breaks', () => {
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend: 'test' });
cy.loginAndNewPost();

});

beforeEach(() => {
cy.loginAndNewPost();
cy.clearMarkdownEditorContent();
});

Expand Down Expand Up @@ -88,7 +89,7 @@ describe('Markdown widget breaks', () => {
.enter({ shift: true })
.confirmMarkdownEditorContent(`
<p>
<br>
</p>
`);
});
Expand All @@ -97,10 +98,7 @@ describe('Markdown widget breaks', () => {
.enter({ shift: true, times: 4 })
.confirmMarkdownEditorContent(`
<p>
<br>
<br>
<br>
<br>
</p>
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import {HOT_KEY_MAP} from "../utils/constants";
const headingNumberToWord = ['', 'one', 'two', 'three', 'four', 'five', 'six'];
const isMac = Cypress.platform === 'darwin';
const modifierKey = isMac ? '{meta}' : '{ctrl}';
// eslint-disable-next-line func-style
const replaceMod = (str) => str.replace(/mod\+/g, modifierKey).replace(/shift\+/g, '{shift}');

describe('Markdown widget', () => {
describe('Markdown widget hotkeys', () => {
describe('hot keys', () => {
before(() => {
Cypress.config('defaultCommandTimeout', 4000);
cy.task('setupBackend', { backend: 'test' });
cy.loginAndNewPost();

});

beforeEach(() => {
cy.loginAndNewPost();
cy.clearMarkdownEditorContent();
cy.focused()
.type('foo')
Expand Down Expand Up @@ -77,15 +77,18 @@ describe('Markdown widget', () => {

describe('link', () => {
before(() => {
cy.window().then((win) => {
cy.stub(win, 'prompt').returns('https://google.com');
});

});
it('pressing mod+k transforms the text to a link', () => {
cy.get('@selection')
cy.window().then((win) => {
cy.get('@selection')
.type(replaceMod(HOT_KEY_MAP['link']))
.confirmMarkdownEditorContent('<p><a>foo</a></p>')
cy.stub(win, 'prompt').returns('https://google.com');
cy.confirmMarkdownEditorContent('<p><a>foo</a></p>')
.type(replaceMod(HOT_KEY_MAP['link']));
});


});
});

Expand Down
Loading

0 comments on commit b806c55

Please sign in to comment.