Skip to content

Commit

Permalink
added test data & basic shortcode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmorb committed Sep 11, 2023
1 parent df2feff commit 2b1e345
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- name: setup wp env
run: npm run env:start

- name: install test data for e2e test
run: npm run cypress:setup

- name: Cypress run
uses: cypress-io/github-action@v6
with:
Expand Down
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ php ~/phpunit.phar --bootstrap tests/bootstrap.php
E2E (end to end) tests are written in [cypress](https://www.cypress.io/). To run them you need to install cypress and start the wordpress environment:
```bash
npm install --legacy-peer-deps
wp-env start
npm run env:start
```
Now, install the test data needed for the tests:
```bash
npm run cypress:setup
```

Then you can run the tests:
```bash
npx cypress run
Expand Down
8 changes: 8 additions & 0 deletions bin/install-wp-cli.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# install-wp-cli.sh
#
# Felipe Elia <contato@felipeelia.com.br> and 10up contributors
#
# The following code is a derivative work of the code from the ElasticPress project,
# which is licensed GPLv2. This code therefore is also licensed under the terms
# of the GNU Public License, version 2.'

#!/usr/bin/env bash

echo "Installing WP-CLI in $1"
Expand Down
10 changes: 10 additions & 0 deletions bin/setup-cypress-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# setup-cypress-env.sh
# Felipe Elia <contato@felipeelia.com.br> and 10up contributors
#
# The following code is a derivative work of the code from the ElasticPress project,
# which is licensed GPLv2. This code therefore is also licensed under the terms
# of the GNU Public License, version 2.'

#!/bin/bash

./bin/wp-env-cli tests-wordpress "wp --allow-root import /var/www/html/wp-content/plugins/commonsbooking/cypress/wordpress-files/content-example.xml --authors=create"
30 changes: 30 additions & 0 deletions cypress/e2e/load-shortcodes.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('load shortcodes', () => {
it('can load cb_items shortcode', () => {
cy.visit('/?page_id=13')
cy.get('.cb-shortcode-items').should('be.visible')
cy.screenshot('cb-items-shortcode')
cy.get('.cb-shortcode-items').find('.cb-button').should('be.visible')
cy.get('.cb-shortcode-items').find('.cb-button').contains('Book item')
cy.get('.cb-shortcode-items').find('.cb-button').click()
cy.url().should('include', '/?cb_item=basictest-noadmin&cb-location=32')
})
it('can load cb_locations shortcode', () => {
cy.visit('/?page_id=15')
cy.get('.cb-shortcode-locations').should('be.visible')
cy.screenshot('cb-locations-shortcode')
cy.get('.cb-shortcode-locations').find('.cb-button').should('be.visible')
cy.get('.cb-shortcode-locations').find('.cb-button').contains('Book item')
cy.get('.cb-shortcode-locations').find('.cb-button').click()
cy.url().should('include', '/?cb_item=basictest-noadmin&cb-location=32')
} )

it('can load cb_item_table shortcode', () => {
cy.visit('/?page_id=17')
cy.get('.cb-shortcode-items_table').should('be.visible')
cy.screenshot('cb-item-table-shortcode')
cy.get('.cb-shortcode-items_table').find('tbody > tr > :nth-child(1)').contains('BasicTest')
cy.get('.cb-shortcode-items_table').find('tbody > tr > :nth-child(1)').find('b > a').should('be.visible')
cy.get('.cb-shortcode-items_table').find('tbody > tr > :nth-child(1)').find('b > a').click()
cy.url().should('include', '/?cb_item=basictest-noadmin&cb-location=32')
} )
})
Loading

0 comments on commit 2b1e345

Please sign in to comment.