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

test: [TOL-1361] Rich Text editor component tests #1565

Merged
merged 41 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
90aa6d1
test: rich text commands tests
colomolo Dec 19, 2023
338f7b7
test: add embedded asset blocks
colomolo Dec 20, 2023
6836913
test: add embedded entry blocks tests
colomolo Dec 20, 2023
7a58272
test: add entry inlines test
colomolo Dec 20, 2023
90ac5dc
test: add resource blocks tests
colomolo Dec 20, 2023
263c7b6
test: add resources inline tests
colomolo Dec 21, 2023
98a5ee7
test: add headings tests
colomolo Dec 21, 2023
487c5a2
test: add hr tests
colomolo Dec 21, 2023
6bfd5c4
test: add links tests
colomolo Dec 21, 2023
f31a8d2
test: add marks tests
colomolo Dec 21, 2023
e23a590
chore: fix minor things
colomolo Dec 21, 2023
30079c7
test: add pasting tests
colomolo Dec 22, 2023
a990d99
test: add quotes tests
colomolo Dec 22, 2023
971c8f4
chore: add tab plugin to cypres config
colomolo Dec 22, 2023
1c30ceb
test: add fixtures
colomolo Dec 22, 2023
326518b
chore: clean up
colomolo Feb 13, 2024
645f451
test: add richtext editor suite
colomolo Feb 14, 2024
dbc3a57
test: add Tables suite
colomolo Feb 15, 2024
41bd2d5
test: add escape inlines suite
colomolo Feb 15, 2024
b75beba
chore: clean up rich text page
colomolo Feb 15, 2024
c3b8f88
chore: remove helpers duplication
colomolo Feb 16, 2024
31f3826
test: add list suite
colomolo Feb 16, 2024
d9f1717
test: add tracking suite
colomolo Feb 19, 2024
80876a4
chore: refactor test suites tsx→ts
colomolo Feb 19, 2024
8f2de06
Merge branch 'master' into TOL-1361-rich-text-editor-component-tests
colomolo Feb 19, 2024
3e22b76
chore: clean up e2e stuff
colomolo Feb 19, 2024
c6d99f7
fix: ci pipeline
colomolo Feb 19, 2024
21e3c49
fix: ci pipeline 2
colomolo Feb 19, 2024
853b8c4
Merge branch 'master' into TOL-1361-rich-text-editor-component-tests
colomolo Feb 20, 2024
f9b2461
test: fix mount props passing
colomolo Feb 20, 2024
7ceadf0
test: bring back frame sizes
colomolo Feb 20, 2024
7eb0220
test: optimize select all action
colomolo Feb 20, 2024
a64ed50
test: move delete codes to const
colomolo Feb 20, 2024
0bc033f
test: try remove wait on getValue
colomolo Feb 20, 2024
ca3c915
test: revert getValue wait
colomolo Feb 20, 2024
067303c
chore: address review issues
colomolo Feb 21, 2024
5afb685
test: tighten assertions
colomolo Feb 22, 2024
b40bcd1
test: toggle headers on real text (to reduce flakyness)
colomolo Feb 22, 2024
8daf79d
Merge branch 'master' into TOL-1361-rich-text-editor-component-tests
colomolo Feb 22, 2024
040940c
chore: update yarn.lock
colomolo Feb 22, 2024
f5d8ebe
Revert "chore: update yarn.lock"
colomolo Feb 22, 2024
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
42 changes: 0 additions & 42 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,6 @@ jobs:
- store_test_results:
path: reports

integration-tests:
parameters:
executor:
type: executor
browser:
type: enum
# firefox has been disabled temporarily until further investigation
enum: [chrome, edge]

parallelism: 3
executor: << parameters.executor >>
steps:
- checkout
- yarn_install
- run: yarn build
- run: yarn build-storybook
- yarn_serve
- run:
command: |
TESTFILES=$(circleci tests glob "cypress/e2e/**/*.ts" | circleci tests split --split-by=timings --timings-type=filename | awk '{if (NR>1) printf ","; printf "%s", $0} END {if (NR>0) printf " "}')
npx cypress run \
--spec "${TESTFILES}" \
--reporter junit \
--reporter-options "mochaFile=./cypress/reports/e2e/test-results.[hash].xml" \
--browser << parameters.browser >>
- store_test_results:
path: cypress/reports/e2e
- store_artifacts:
path: cypress/screenshots
- store_artifacts:
path: cypress/videos

component-tests:
parallelism: 3
executor: linux-cypress
Expand Down Expand Up @@ -140,15 +108,6 @@ workflows:
context: vault
- component-tests:
context: vault
- integration-tests:
name: integration-<< matrix.executor >>-<< matrix.browser >>
context: vault
matrix:
alias: integration-tests-linux
parameters:
executor: [linux-cypress]
# firefox has been disabled temporarily until further investigation
browser: [chrome, edge]
- release:
context: vault
filters:
Expand All @@ -157,4 +116,3 @@ workflows:
requires:
- lint
- unit-tests
- integration-tests-linux
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default defineConfig({
module: {
rules: [
{
test: /\.tsx?$/,
test: /\.t|jsx?$/,
exclude: [/node_modules/],
use: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable mocha/no-setup-in-describe */

import { BLOCKS, INLINES } from '@contentful/rich-text-types';

import { block, document as doc, text } from '../../../packages/rich-text/src/helpers/nodeFactory';
import { getIframe } from '../../fixtures/utils';
import { createRichTextFakeSdk } from '../../fixtures';
import { RichTextPage } from './RichTextPage';
import { mountRichTextEditor } from './utils';

// the sticky toolbar gets in the way of some of the tests, therefore
// we increase the viewport height to fit the whole page on the screen
Expand All @@ -15,12 +14,12 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
beforeEach(() => {
cy.viewport(1000, 2000);
richText = new RichTextPage();
richText.visit();
mountRichTextEditor();
});

describe('Palette', () => {
const getPalette = () => getIframe().findByTestId('rich-text-commands');
const getCommandList = () => getIframe().findByTestId('rich-text-commands-list');
const getPalette = () => cy.findByTestId('rich-text-commands');
const getCommandList = () => cy.findByTestId('rich-text-commands-list');

it('should be visible', () => {
richText.editor.click().type('/');
Expand Down Expand Up @@ -60,7 +59,7 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
it('should embed entry', () => {
richText.editor.click().type('/');
getCommandList().findByText('Embed Example Content Type').click();
getCommandList().findByText('Hello world').click();
getCommandList().findByText('The best article ever').click();

//this is used instead of snapshot value because we have randomized entry IDs
richText.getValue().should((doc) => {
Expand All @@ -73,7 +72,7 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
it('should embed inline', () => {
richText.editor.click().type('/');
getCommandList().findByText('Embed Example Content Type - Inline').click();
getCommandList().findByText('Hello world').click();
getCommandList().findByText('The best article ever').click();

//this is used instead of snapshot value because we have randomized entry IDs
richText.getValue().should((doc) => {
Expand Down Expand Up @@ -102,7 +101,7 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
it('should delete command after embedding', () => {
richText.editor.click().type('/');
getCommandList().findByText('Embed Example Content Type').click();
getCommandList().findByText('Hello world').click();
getCommandList().findByText('The best article ever').click();

richText.editor.children().contains('/').should('not.exist');
});
Expand Down Expand Up @@ -174,13 +173,14 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
});

it('should be disabled without any action item', () => {
// disable embedded entries/assets
cy.setFieldValidations([
{
enabledNodeTypes: ['heading-1'],
},
]);
cy.reload();
const sdk = createRichTextFakeSdk({
validations: [
{
enabledNodeTypes: ['heading-1'],
},
],
});
mountRichTextEditor({ sdk, actionsDisabled: true });

// try to open command prompt
richText.editor.click().type('/');
Expand Down Expand Up @@ -218,8 +218,6 @@ describe('Rich Text Editor - Commands', { viewportHeight: 2000 }, () => {
},
],
});
// Clear validations after the test
cy.setFieldValidations([]);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,58 +1,22 @@
/* eslint-disable mocha/no-setup-in-describe */

import { BLOCKS } from '@contentful/rich-text-types';

import { block, document as doc, text } from '../../../packages/rich-text/src/helpers/nodeFactory';
import { getIframe } from '../../fixtures/utils';
import { mod } from '../../fixtures/utils';
import { KEYS, assetBlock, emptyParagraph, paragraphWithText } from './helpers';
import { RichTextPage } from './RichTextPage';
import { mountRichTextEditor } from './utils';

// the sticky toolbar gets in the way of some of the tests, therefore
// we increase the viewport height to fit the whole page on the screen

describe('Rich Text Editor - Embedded Entry Assets', { viewportHeight: 2000 }, () => {
let richText: RichTextPage;

// copied from the 'is-hotkey' library we use for RichText shortcuts
const IS_MAC =
typeof window != 'undefined' && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
const mod = IS_MAC ? 'meta' : 'control';
const buildHelper =
(type) =>
(...children) =>
block(type, {}, ...children);
const paragraph = buildHelper(BLOCKS.PARAGRAPH);
const paragraphWithText = (t) => paragraph(text(t, []));
const emptyParagraph = () => paragraphWithText('');
const expectDocumentToBeEmpty = () => richText.expectValue(undefined);

const keys = {
enter: { keyCode: 13, which: 13, key: 'Enter' },
backspace: { keyCode: 8, which: 8, key: 'Backspace' },
};

function pressEnter() {
richText.editor.trigger('keydown', keys.enter);
}

const assetBlock = () =>
block(BLOCKS.EMBEDDED_ASSET, {
target: {
sys: {
id: 'example-entity-id',
type: 'Link',
linkType: 'Asset',
},
},
});

beforeEach(() => {
richText = new RichTextPage();
richText.visit();
cy.shouldConfirm(true);
});

afterEach(() => {
cy.unsetShouldConfirm();
mountRichTextEditor();
});

const methods: [string, () => void][] = [
Expand All @@ -76,9 +40,8 @@ describe('Rich Text Editor - Embedded Entry Assets', { viewportHeight: 2000 }, (
richText.editor.click();
triggerEmbeddedAsset();

richText.editor.find('[data-entity-id="example-entity-id"]').click();

richText.editor.trigger('keydown', keys.enter);
richText.editor.find('[data-entity-id="published_asset"]').click();
richText.editor.trigger('keydown', KEYS.enter);

richText.expectValue(doc(emptyParagraph(), assetBlock(), emptyParagraph()));
});
Expand All @@ -93,12 +56,12 @@ describe('Rich Text Editor - Embedded Entry Assets', { viewportHeight: 2000 }, (
addEmbeddedAsset();

// Press enter on the first asset block
richText.editor.click().find('[data-entity-id="example-entity-id"]').first().click();
pressEnter();
richText.editor.click().find('[data-entity-id="published_asset"]').first().click();
richText.editor.trigger('keydown', KEYS.enter);

// Press enter on the second asset block
richText.editor.click().find('[data-entity-id="example-entity-id"]').first().click();
pressEnter();
richText.editor.click().find('[data-entity-id="published_asset"]').first().click();
richText.editor.trigger('keydown', KEYS.enter);

richText.expectValue(
doc(emptyParagraph(), assetBlock(), emptyParagraph(), assetBlock(), emptyParagraph())
Expand All @@ -110,8 +73,8 @@ describe('Rich Text Editor - Embedded Entry Assets', { viewportHeight: 2000 }, (

richText.expectValue(doc(assetBlock(), emptyParagraph()));

getIframe().findByTestId('cf-ui-card-actions').click();
getIframe().findByTestId('card-action-remove').click();
cy.findByTestId('cf-ui-card-actions').click();
cy.findByTestId('card-action-remove').click();

richText.expectValue(undefined);
});
Expand All @@ -121,9 +84,9 @@ describe('Rich Text Editor - Embedded Entry Assets', { viewportHeight: 2000 }, (

richText.expectValue(doc(assetBlock(), emptyParagraph()));

getIframe().findByTestId('cf-ui-asset-card').click();
cy.findByTestId('cf-ui-asset-card').click();
// .type('{backspace}') does not work on non-typable elements.(contentEditable=false)
richText.editor.trigger('keydown', keys.backspace);
richText.editor.trigger('keydown', KEYS.backspace);

richText.expectValue(undefined);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
/* eslint-disable mocha/no-setup-in-describe */

import { BLOCKS } from '@contentful/rich-text-types';

import { block, document as doc, text } from '../../../packages/rich-text/src/helpers/nodeFactory';
import { getIframe } from '../../fixtures/utils';
import { mod } from '../../fixtures/utils';
import { emptyParagraph, KEYS, paragraphWithText } from './helpers';
import { RichTextPage } from './RichTextPage';
import { mountRichTextEditor } from './utils';

// the sticky toolbar gets in the way of some of the tests, therefore
// we increase the viewport height to fit the whole page on the screen

describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, () => {
let richText: RichTextPage;

// copied from the 'is-hotkey' library we use for RichText shortcuts
const IS_MAC =
typeof window != 'undefined' && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
const mod = IS_MAC ? 'meta' : 'control';
const buildHelper =
(type) =>
(...children) =>
block(type, {}, ...children);
const paragraph = buildHelper(BLOCKS.PARAGRAPH);
const paragraphWithText = (t) => paragraph(text(t, []));
const emptyParagraph = () => paragraphWithText('');
const expectDocumentToBeEmpty = () => richText.expectValue(undefined);

const keys = {
enter: { keyCode: 13, which: 13, key: 'Enter' },
backspace: { keyCode: 8, which: 8, key: 'Backspace' },
};

function pressEnter() {
richText.editor.trigger('keydown', keys.enter);
}

const entryBlock = () =>
block(BLOCKS.EMBEDDED_ENTRY, {
target: {
sys: {
id: 'example-entity-id',
id: 'published-entry',
type: 'Link',
linkType: 'Entry',
},
Expand All @@ -48,12 +27,7 @@ describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, (
beforeEach(() => {
cy.viewport(1000, 2000);
richText = new RichTextPage();
richText.visit();
cy.shouldConfirm(true);
});

afterEach(() => {
cy.unsetShouldConfirm();
mountRichTextEditor();
});

const methods: [string, () => void][] = [
Expand All @@ -76,9 +50,9 @@ describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, (
it('adds paragraph before the block when pressing enter if the block is first document node', () => {
richText.editor.click().then(triggerEmbeddedEntry);

richText.editor.find('[data-entity-id="example-entity-id"]').click();
richText.editor.find('[data-entity-id="published-entry"]').click();

richText.editor.trigger('keydown', keys.enter);
richText.editor.trigger('keydown', KEYS.enter);

richText.expectValue(doc(emptyParagraph(), entryBlock(), emptyParagraph()));
});
Expand All @@ -93,12 +67,12 @@ describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, (
addEmbeddedEntry();

// Inserts paragraph before embed because it's in the first line.
richText.editor.find('[data-entity-id="example-entity-id"]').first().click();
pressEnter();
richText.editor.find('[data-entity-id="published-entry"]').first().click();
richText.editor.trigger('keydown', KEYS.enter);

// inserts paragraph in-between embeds.
richText.editor.find('[data-entity-id="example-entity-id"]').first().click();
pressEnter();
richText.editor.find('[data-entity-id="published-entry"]').first().click();
richText.editor.trigger('keydown', KEYS.enter);

richText.expectValue(
doc(emptyParagraph(), entryBlock(), emptyParagraph(), entryBlock(), emptyParagraph())
Expand All @@ -110,8 +84,8 @@ describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, (

richText.expectValue(doc(entryBlock(), emptyParagraph()));

getIframe().findByTestId('cf-ui-card-actions').click();
getIframe().findByTestId('delete').click();
cy.findByTestId('cf-ui-card-actions').click();
cy.findByTestId('delete').click();

richText.expectValue(undefined);
});
Expand All @@ -121,9 +95,9 @@ describe('Rich Text Editor - Embedded Entry Blocks', { viewportHeight: 2000 }, (

richText.expectValue(doc(entryBlock(), emptyParagraph()));

getIframe().findByTestId('cf-ui-entry-card').click();
cy.findByTestId('cf-ui-entry-card').click();
// .type('{backspace}') does not work on non-typable elements.(contentEditable=false)
richText.editor.trigger('keydown', keys.backspace);
richText.editor.trigger('keydown', KEYS.backspace);

richText.expectValue(undefined);
});
Expand Down
Loading
Loading