Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
103 changes: 59 additions & 44 deletions cypress/e2e/inline-spoilers.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,106 +18,121 @@ describe('Inline Spoilers', () => {
.should('be.visible')
})

it('can be added with guttenberg', () => {
it('can be added with shortcode', () => {
const spoiler = {
title: 'Who Survives in the Final Episode? 🎬',
content: 'Against all odds, the main character fakes their death and escapes to another country.'
}

cy.open_new_post_page()

// Create post with spoiler
cy.get('[class*=editor-post-title__input]').type('Shortcode Spoiler')
cy.get('p[class*=block-editor-default-block-appender]').click()
cy.get('p[class*=block-editor-rich-text__editable]').last().focus()
.type(`[spoiler title="${spoiler.title}"]${spoiler.content}[/spoiler]{esc}`)

cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click()
cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]')
.click()

// Preview the post
cy.contains('View Post').click()

// Check spoiler behaviour
cy.contains(spoiler.content).should('be.not.visible')
cy.contains(spoiler.title).click()
cy.contains(spoiler.content).should('be.visible')
cy.contains(spoiler.title).click()
cy.contains(spoiler.content).should('be.not.visible')
})

it('can be added with Guttenberg', () => {
const spoiler = {
title: 'The Secret Ingredient in Grandma’s Cookies 🍪',
content: 'It’s actually a pinch of cinnamon! That’s what makes them so special.'
}

cy.open_new_post_page()

// Create post with spoiler
cy.get('[class*=editor-post-title__input]').type('Spoiled Content')
cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline')
cy.get('[class*=editor-block-list-item-inline-spoilers-block').click()
Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
cy.get('[class*=editor-block-list-item-inline-spoilers-block]').click()
cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]')
.type('The title')
.type(spoiler.title)
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]')
.type('Lorem ipsum dolor sit amet.')
.type(spoiler.content)
cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click()
cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]')
.click()

// Preview the post
cy.contains('View Post')
.click()
cy.contains('View Post').click()

// Check spoiler behaviour
cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible')
cy.contains('The title').click()
cy.wait(300)
cy.contains('Lorem ipsum dolor sit amet.').should('be.visible')
cy.contains('The title').click()
cy.wait(300)
cy.contains('Lorem ipsum dolor sit amet.').should('be.not.visible')
cy.contains(spoiler.content).should('be.not.visible')
cy.contains(spoiler.title).click()
cy.contains(spoiler.content).should('be.visible')
cy.contains(spoiler.title).click()
cy.contains(spoiler.content).should('be.not.visible')
})

it('can be added multiple times', () => {
const spoilers = [{
title: 'The first one',
content: 'Etiam augue urna, ullamcorper dapibus ex quis, elementum tristique libero.'
title: 'Hidden Feature in Our New App Update 📱',
content: 'You can now double-tap the logo in the settings to unlock a dark mode easter egg!'
},{
title: 'The second spoilier',
content: 'Phasellus nec turpis semper, fermentum magna ut, lobortis lacus.'
title: 'Unexpected Plot Twist in the Latest Mystery Novel 📖',
content: 'The detective was the real culprit all along, covering up their own crimes!'
}]

cy.open_new_post_page()

// Create post with spoiler
cy.get('[class*=editor-post-title__input]').type('Multiple Spoilers')
cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline')
cy.get('[class*=editor-block-list-item-inline-spoilers-block').click()
Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]')
.type(spoilers[0].title)
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]')
.type(spoilers[0].content)

cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
for(const spoiler of spoilers) {
cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline')
cy.get('[class*=editor-block-list-item-inline-spoilers-block').click()
Cypress.env('WP_CORE') > 5.4 && cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
cy.get('[class*=editor-inserter__menu] input[type=search]').type('inline')
cy.get('[class*=editor-block-list-item-inline-spoilers-block').click()
cy.get('div[class*=edit-post-header] button[class*=inserter][class*=toggle]')
.click()
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]')
.last()
.type(spoilers[1].title)
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-title]')
.last().type(spoiler.title)
cy.get('[class=wp-block-inline-spoilers-block] [class=spoiler-content] [role=textbox]')
.last()
.type(spoilers[1].content)
.last().type(spoiler.content)
}

cy.get('[class*=edit-post-header] [class*=editor-post-publish]').click()
cy.get('[class*=editor-post-publish-panel] [class*=editor-post-publish-button]')
.click()

// Preview the post
cy.contains('View Post')
.click()
cy.contains('View Post').click()

// Check spoilers behaviour
cy.contains(spoilers[0].content).should('be.not.visible')
cy.contains(spoilers[1].content).should('be.not.visible')

cy.contains(spoilers[0].title).click()
cy.wait(300)
cy.contains(spoilers[0].content).should('be.visible')
cy.contains(spoilers[1].content).should('be.not.visible')

cy.contains(spoilers[0].title).click()
cy.wait(300)
cy.contains(spoilers[0].content).should('be.not.visible')
cy.contains(spoilers[1].content).should('be.not.visible')

cy.contains(spoilers[0].title).click()
cy.contains(spoilers[1].title).click()
cy.wait(300)
cy.contains(spoilers[0].content).should('be.visible')
cy.contains(spoilers[1].content).should('be.visible')

cy.contains(spoilers[0].title).click()
cy.wait(300)
cy.contains(spoilers[0].content).should('be.not.visible')
cy.contains(spoilers[1].content).should('be.visible')
})
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/wordpress.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ describe('WordPress', () => {

it('credentials are valid', () => {
cy.login()
cy.contains('Howdy, wordpress')
})
})
25 changes: 1 addition & 24 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Cypress.Commands.add('login', (username='wordpress', password='wpassword') => {
cy.get('input[name=log]').type(username)
cy.get('input[name=pwd]').type(password)
cy.get('input[name=wp-submit]').click()
cy.contains('Howdy, wordpress')
});
cy.visit('/wp-admin')
})
Expand All @@ -45,14 +44,6 @@ Cypress.Commands.add('logout', () => {
cy.get('[name=loginform]').should('exist')
})

Cypress.Commands.add('logout', () => {
cy.visit('/wp-admin')
cy.contains('Howdy, wordpress')
cy.get('[class="menupop with-avatar"] [class="ab-sub-wrapper"]').invoke('show')
cy.get('[id=wp-admin-bar-logout] a').click()
cy.get('[name=loginform]').should('exist')
})

Cypress.Commands.add('open_new_post_page', () => {
cy.get('li[id=menu-posts]').click()
cy.get('a[class=page-title-action]').contains('Add New').click()
Expand All @@ -61,23 +52,9 @@ Cypress.Commands.add('open_new_post_page', () => {
})

Cypress.Commands.add('supress_guttenberg_wizzard', () => {

// WordPress 5.2 throws exception `Failed to execute 'send' on 'XMLHttpRequest'`
// when you're leaving `Add New` page with unsaved changes prompt
Cypress.env('WP_CORE') == 5.2 && Cypress.on('uncaught:exception', (popup) => {
return false
})

// Wait wizzard popup animation
Cypress.env('WP_CORE') >= 5.4 && cy.wait(1500)

// 5.0 ... 5.3
cy.get('body').then((body) => {
let popover = body.find('[class*=nux-dot-tip]');
popover.length && cy.get('[class*=nux-dot-tip__disable]').click()
})

// 5.4 ... 6.3

cy.get('body').then((body) => {
let popover = body.find('[class*=edit-post-welcome-guide]');
popover.length && cy.get('[class*=edit-post-welcome-guide] [class*=components-modal__header] [class*=components-button]').click()
Expand Down
Loading