Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slate, webpack, toastify and cypress #6852

Merged
merged 25 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a634489
chore: upgrade slate editor to 0.9
demshy Jul 21, 2023
0942b04
chore: upgrade slate editor to 0.9
demshy Jul 21, 2023
631ea6b
chore: update cypress to 12, update configs and tests to work with it
demshy Jul 21, 2023
2547eab
chore: replace redux-notifications with toastify
demshy Jul 21, 2023
9797d2e
chore: lint & test recent changes
demshy Jul 21, 2023
0fe3662
chore: upgrade slate editor to 0.9
demshy Jul 21, 2023
def6276
chore: update webpack to 5
demshy Jul 22, 2023
70f29a9
chore: upgrade slate editor to 0.9
demshy Jul 22, 2023
c8021a8
chore: lint & test recent changes
demshy Jul 22, 2023
7295be6
Merge branch 'rc-slate' into rc
demshy Jul 22, 2023
321ea31
chore: update code to ts4
demshy Jul 22, 2023
503582a
chore: lint proxy server and lint some code
demshy Jul 23, 2023
2bb2453
Merge branch 'rc-webpack' into rc
demshy Jul 23, 2023
b549a5c
Merge branch 'rc-toastify' into rc
demshy Jul 23, 2023
d019e2c
Merge branch 'rc-cypress' into rc
demshy Jul 23, 2023
763bb67
chore: lint & set node version in workflow
demshy Jul 25, 2023
c2b0563
fix: update ObjectControl and ListControl proptypes
demshy Jul 25, 2023
bfdfbb8
fix: add table renderers and serializers
demshy Jul 26, 2023
9db55c5
feat: add history to visual and raw editor
demshy Jul 26, 2023
9cc28cf
feat: add thematic break
demshy Jul 26, 2023
9ae9f0c
fix: add image renderer and fix thematic-break
demshy Jul 26, 2023
c4e0c0b
chore: cleanup old slate code
demshy Jul 26, 2023
916de66
Merge branch 'rc-slate' into rc
demshy Jul 26, 2023
85f341c
Merge branch 'master' into rc
demshy Jul 26, 2023
040746f
test: deploy rc
demshy Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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
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
Loading