Skip to content

Commit

Permalink
test: fix tests & enforce cypress to install (#5989)
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 authored Jan 6, 2025
1 parent 7b4e6f5 commit c82fd7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

- name: Install dependencies
id: install-dependencies
run: pnpm install
run: pnpm install && pnpm exec cypress install

- name: Try to build the packages
id: build-packages
Expand Down
126 changes: 2 additions & 124 deletions demos/src/Commands/Cut/React/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
context('/src/Examples/Default/React/', () => {
context('/src/Commands/Cut/React/', () => {
before(() => {
cy.visit('/src/Examples/Default/React/')
cy.visit('/src/Commands/Cut/React/')
})

beforeEach(() => {
Expand All @@ -12,132 +12,10 @@ context('/src/Examples/Default/React/', () => {

it('should apply the paragraph style when the keyboard shortcut is pressed', () => {
cy.get('.tiptap h1').should('exist')
cy.get('.tiptap p').should('not.exist')

cy.get('.tiptap')
.trigger('keydown', { modKey: true, altKey: true, key: '0' })
.find('p')
.should('contain', 'Example Text')
})

const buttonMarks = [
{ label: 'Bold', tag: 'strong' },
{ label: 'Italic', tag: 'em' },
{ label: 'Strike', tag: 's' },
]

buttonMarks.forEach(m => {
it(`should disable ${m.label} when the code tag is enabled for cursor`, () => {
cy.get('.tiptap').type('{selectall}Hello world')
cy.get('button').contains('Code').click()
cy.get('button').contains(m.label).should('be.disabled')
})

it(`should enable ${m.label} when the code tag is disabled for cursor`, () => {
cy.get('.tiptap').type('{selectall}Hello world')
cy.get('button').contains('Code').click()
cy.get('button').contains('Code').click()
cy.get('button').contains(m.label).should('not.be.disabled')
})

it(`should disable ${m.label} when the code tag is enabled for selection`, () => {
cy.get('.tiptap').type('{selectall}Hello world{selectall}')
cy.get('button').contains('Code').click()
cy.get('button').contains(m.label).should('be.disabled')
})

it(`should enable ${m.label} when the code tag is disabled for selection`, () => {
cy.get('.tiptap').type('{selectall}Hello world{selectall}')
cy.get('button').contains('Code').click()
cy.get('button').contains('Code').click()
cy.get('button').contains(m.label).should('not.be.disabled')
})

it(`should apply ${m.label} when the button is pressed`, () => {
cy.get('.tiptap').type('{selectall}Hello world')
cy.get('button').contains('Paragraph').click()
cy.get('.tiptap').type('{selectall}')
cy.get('button').contains(m.label).click()
cy.get(`.tiptap ${m.tag}`).should('exist').should('have.text', 'Hello world')
})
})

it('should clear marks when the button is pressed', () => {
cy.get('.tiptap').type('{selectall}Hello world')
cy.get('button').contains('Paragraph').click()
cy.get('.tiptap').type('{selectall}')
cy.get('button').contains('Bold').click()
cy.get('.tiptap strong').should('exist').should('have.text', 'Hello world')
cy.get('button').contains('Clear marks').click()
cy.get('.tiptap strong').should('not.exist')
})

it('should clear nodes when the button is pressed', () => {
cy.get('.tiptap').type('{selectall}Hello world')
cy.get('button').contains('Bullet list').click()
cy.get('.tiptap ul').should('exist').should('have.text', 'Hello world')
cy.get('.tiptap').type('{enter}A second item{enter}A third item{selectall}')
cy.get('button').contains('Clear nodes').click()
cy.get('.tiptap ul').should('not.exist')
cy.get('.tiptap p').should('have.length', 3)
})

const buttonNodes = [
{ label: 'H1', tag: 'h1' },
{ label: 'H2', tag: 'h2' },
{ label: 'H3', tag: 'h3' },
{ label: 'H4', tag: 'h4' },
{ label: 'H5', tag: 'h5' },
{ label: 'H6', tag: 'h6' },
{ label: 'Bullet list', tag: 'ul' },
{ label: 'Ordered list', tag: 'ol' },
{ label: 'Code block', tag: 'pre code' },
{ label: 'Blockquote', tag: 'blockquote' },
]

buttonNodes.forEach(n => {
it(`should set ${n.label} when the button is pressed`, () => {
cy.get('button').contains('Paragraph').click()
cy.get('.tiptap').type('{selectall}Hello world{selectall}')

cy.get('button').contains(n.label).click()
cy.get(`.tiptap ${n.tag}`).should('exist').should('have.text', 'Hello world')
cy.get('button').contains(n.label).click()
cy.get(`.tiptap ${n.tag}`).should('not.exist')
})
})

it('should add a hr when on the same line as a node', () => {
cy.get('.tiptap').type('{rightArrow}')
cy.get('button').contains('Horizontal rule').click()
cy.get('.tiptap hr').should('exist')
cy.get('.tiptap h1').should('exist')
})

it('should add a hr when on a new line', () => {
cy.get('.tiptap').type('{rightArrow}{enter}')
cy.get('button').contains('Horizontal rule').click()
cy.get('.tiptap hr').should('exist')
cy.get('.tiptap h1').should('exist')
})

it('should add a br', () => {
cy.get('.tiptap').type('{rightArrow}')
cy.get('button').contains('Hard break').click()
cy.get('.tiptap h1 br').should('exist')
})

it('should undo', () => {
cy.get('.tiptap').type('{selectall}{backspace}')
cy.get('button').contains('Undo').click()
cy.get('.tiptap').should('contain', 'Hello world')
})

it('should redo', () => {
cy.get('.tiptap').type('{selectall}{backspace}')
cy.get('button').contains('Undo').click()
cy.get('.tiptap').should('contain', 'Hello world')
cy.get('button').contains('Redo').click()
cy.get('.tiptap').should('not.contain', 'Hello world')
})
})

0 comments on commit c82fd7c

Please sign in to comment.