From 2b1e34583aa1bc46650206b943adb4db763e8616 Mon Sep 17 00:00:00 2001 From: Hans Morbach <6433480+hansmorb@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:18:57 -0400 Subject: [PATCH] added test data & basic shortcode tests --- .github/workflows/e2e.yml | 3 + Readme.md | 7 +- bin/install-wp-cli.sh | 8 + bin/setup-cypress-env.sh | 10 + cypress/e2e/load-shortcodes.cy.js | 30 ++ cypress/wordpress-files/content-example.xml | 394 ++++++++++++++++++++ package.json | 3 +- 7 files changed, 453 insertions(+), 2 deletions(-) create mode 100755 bin/setup-cypress-env.sh create mode 100644 cypress/e2e/load-shortcodes.cy.js create mode 100644 cypress/wordpress-files/content-example.xml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a90465cf1..b23b5c1bf 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -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: diff --git a/Readme.md b/Readme.md index 075a485bc..12fd9b113 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/bin/install-wp-cli.sh b/bin/install-wp-cli.sh index 0d54d0e67..799269577 100755 --- a/bin/install-wp-cli.sh +++ b/bin/install-wp-cli.sh @@ -1,3 +1,11 @@ +# install-wp-cli.sh +# +# Felipe Elia 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" diff --git a/bin/setup-cypress-env.sh b/bin/setup-cypress-env.sh new file mode 100755 index 000000000..c740aff8b --- /dev/null +++ b/bin/setup-cypress-env.sh @@ -0,0 +1,10 @@ +# setup-cypress-env.sh +# Felipe Elia 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" diff --git a/cypress/e2e/load-shortcodes.cy.js b/cypress/e2e/load-shortcodes.cy.js new file mode 100644 index 000000000..3019865cb --- /dev/null +++ b/cypress/e2e/load-shortcodes.cy.js @@ -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') + } ) +}) \ No newline at end of file diff --git a/cypress/wordpress-files/content-example.xml b/cypress/wordpress-files/content-example.xml new file mode 100644 index 000000000..be1906ba4 --- /dev/null +++ b/cypress/wordpress-files/content-example.xml @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + commonsbooking + http://localhost:1001 + + Mon, 11 Sep 2023 16:00:12 +0000 + en-US + 1.2 + http://localhost:1001 + http://localhost:1001 + + 1 + + + 1 + + + + + + https://wordpress.org/?v=6.3.1 + + + <![CDATA[Navigation]]> + http://localhost:1001/?p=7 + Mon, 11 Sep 2023 15:23:00 +0000 + + http://localhost:1001/?p=4 + + ]]> + + 7 + + + + + + + + + 0 + 0 + + + 0 + + + <![CDATA[Custom Styles]]> + http://localhost:1001/?p=8 + Mon, 11 Sep 2023 15:26:58 +0000 + + http://localhost:1001/?p=7 + + + + 8 + + + + + + + + + 0 + 0 + + + 0 + + + + <![CDATA[CommonsBooking Items Shortcode]]> + http://localhost:1001/?page_id=13 + Mon, 11 Sep 2023 15:28:48 +0000 + + http://localhost:1001/?page_id=13 + + +

[cb_items]

+]]>
+ + 13 + + + + + + + + + 0 + 0 + + + 0 +
+ + <![CDATA[CommonsBooking Locations Shortcode]]> + http://localhost:1001/?page_id=15 + Mon, 11 Sep 2023 15:29:05 +0000 + + http://localhost:1001/?page_id=15 + + +

[cb_locations]

+]]>
+ + 15 + + + + + + + + + 0 + 0 + + + 0 +
+ + <![CDATA[CommonsBooking Table Shortcode]]> + http://localhost:1001/?page_id=17 + Mon, 11 Sep 2023 15:29:28 +0000 + + http://localhost:1001/?page_id=17 + + +

[cb_items_table]

+]]>
+ + 17 + + + + + + + + + 0 + 0 + + + 0 +
+ + <![CDATA[CommonsBooking Map]]> + http://localhost:1001/?page_id=22 + Mon, 11 Sep 2023 15:32:55 +0000 + + http://localhost:1001/?page_id=22 + + +[cb_map id=36] +]]> + + 22 + + + + + + + + + 0 + 0 + + + 0 + + + <![CDATA[BasicTest - NoAdmin]]> + http://localhost:1001/?cb_item=basictest-noadmin + Mon, 11 Sep 2023 15:56:19 +0000 + + http://localhost:1001/?post_type=cb_item&p=30 + + + + 30 + + + + + + + + + 0 + 0 + + + 0 + + + + + + + <![CDATA[BasicTest - Köln Dom LocMap NoAdmin]]> + http://localhost:1001/?cb_location=basictest-koln-dom-locmap-noadmin + Mon, 11 Sep 2023 15:57:19 +0000 + + http://localhost:1001/?post_type=cb_location&p=32 + + + + 32 + + + + + + + + + 0 + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <![CDATA[BasicTest - Bookable DailyRep Fullday NoEnd NoCodes]]> + http://localhost:1001/?cb_timeframe=basictest-bookable-dailyrep-fullday-noend-nocodes + Mon, 11 Sep 2023 15:57:59 +0000 + + http://localhost:1001/?post_type=cb_timeframe&p=34 + + + + 34 + + + + + + + + + 0 + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <![CDATA[BasicTest AllDefault]]> + http://localhost:1001/?post_type=cb_map&p=36 + Mon, 11 Sep 2023 15:59:22 +0000 + + http://localhost:1001/?post_type=cb_map&p=36 + + + + 36 + + + + + + + + + 0 + 0 + + + 0 + + + + + + + + + +
+
+ \ No newline at end of file diff --git a/package.json b/package.json index 8ed083a1b..e109bd008 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "env": "wp-env", "env:install-tests-cli": "./bin/install-wp-cli.sh tests-wordpress", "env:start": "wp-env start && npm run env:install-tests-cli", - "env:stop": "wp-env stop" + "env:stop": "wp-env stop", + "cypress:setup": "./bin/setup-cypress-env.sh" }, "dependencies": { "leaflet": "^1.7.1",