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

[WIP] Fix broken drafts and cypress #551

Closed
wants to merge 15 commits into from
26 changes: 25 additions & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,39 @@ jobs:
npm run wp-env:init
npm run wp-env:test:setup

- name: Cypress run
- name: Cypress run main
uses: cypress-io/github-action@v2
with:
install: false
spec: "cypress/integration/main/*.spec.js"
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cypress run redirector
uses: cypress-io/github-action@v2
with:
install: false
spec: "cypress/integration/redirector/*.spec.js"
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cypress run flaky
uses: cypress-io/github-action@v2
with:
install: false
spec: "cypress/integration/flaky/*.spec.js"
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@v1
if: failure()
with:
Expand Down
4 changes: 2 additions & 2 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"core": "WordPress/WordPress#5.8.3",
"themes": [
"./wordpress/wp-content/themes/cds-default"
"./wordpress/wp-content/themes/cds-default",
"./wordpress/wp-content/themes/cds-redirector"
],
"mappings": {
"wp-content/mu-plugins": "./wordpress/wp-content/mu-plugins",
Expand Down
4 changes: 2 additions & 2 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"baseUrl": "http://localhost:8889",
"video": false,
"screenshotOnRunFailure": false,
"video": true,
"screenshotOnRunFailure": true,
"retries": {
"runMode": 2,
"openMode": 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addArticle } from "./util";
import { addArticle } from "../util";

/// <reference types="Cypress" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addArticle } from "./util";
import { addArticle } from "../util";

/// <reference types="Cypress" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addPage } from "./util";
import { addPage } from "../util";

/// <reference types="Cypress" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ describe('Site Settings', () => {
cy.get('#collection_live').should('be.empty');
});

it('Can save collection settings and show maintenance pagec', () => {
it('Can save collection settings and show maintenance page', () => {
cy.visit('/wp-admin/options-general.php?page=collection-settings');
cy.get('#collection_maintenance').check();
cy.get('#submit').click();
cy.get('#setting-error-settings_updated').should('contain.text', 'Settings saved');

cy.get('#wp-admin-bar-my-account > [aria-haspopup="true"]').trigger('mouseover');
cy.get("a").contains("Log Out").click({force: true});
cy.visit('/');
cy.get('h1').should('have.text', "We're currently working on this");
// log out
cy.get("#wp-admin-bar-logout > a").should($a => {
expect($a.attr('href'), 'href').to.contain('action=logout')
}).invoke('attr', 'href').then(href => {
cy.visit(href)
});

// should be logged out
cy.visit('/')
cy.get('h1').should('have.text', "We're currently working on this");
})
});
});
38 changes: 38 additions & 0 deletions cypress/integration/redirector/redirector.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { addArticle } from "../util";

/// <reference types="Cypress" />

describe.skip('Switch theme', () => {
before(() => {
cy.testSetup({theme: 'cds-redirector'});
});

it('CDS Redirector theme', async () => {
const redirectUrl = "https://example.com"

cy.login();

// set redirect url
cy.visit("/wp-admin/admin.php?page=theme-settings");
cy.get('input[name*="redirect_url"]').type(redirectUrl);
cy.get('input#submit').click();
cy.get('input[name*="redirect_url"]').should('have.value', redirectUrl);

// create post
const text = "Hello from GC Admin";
addArticle(text)

// preview > check URL
cy.get('a.editor-post-preview').should($a => {
expect($a.attr('href'), 'href').to.contain('preview=true')
}).invoke('attr', 'href').then(href => {
cy.request({
url: href,
followRedirect: false,
}).then(resp => {
expect(resp.status).to.eq(302)
expect(resp.redirectedToUrl).to.eq("https://example.com/?lang=en")
})
});
});
});
2 changes: 0 additions & 2 deletions cypress/screenshots/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion cypress/support/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import './visit-profile';
import './add-user';
import './login-user';
import './add-user-cap';
import './test-setup';
import './test-setup';
5 changes: 3 additions & 2 deletions cypress/support/commands/test-setup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
Cypress.Commands.add('testSetup', (index = 0) => {
Cypress.Commands.add('testSetup', ({ theme = 'cds-default' } = {}) => {
const options = { failOnNonZeroExit: false }

cy.exec('wp-env run tests-cli wp db import "test_run_dump.sql"', options).then((result) => {
cy.log(result.code);
cy.log(result.stdout);

cy.exec(`wp-env run tests-cli wp theme activate ${theme}`, options)

if(result.code === 0) {
return;
}

cy.exec('npm run wp-env:clean', options);
cy.exec('wp-env run tests-cli wp option delete list_values', options);
cy.exec('wp-env run tests-cli wp option set list_values --format=json < ./cypress/fixtures/notify-list-data.json', options)
cy.exec('wp-env run tests-cli wp theme activate cds-default', options)
cy.exec('wp-env run tests-cli wp plugin activate sitepress-multilingual-cms cds-base two-factor;', options)
cy.exec('wp-env run tests-cli wp plugin activate s3-uploads disable-user-login;', options) // wps-hide-login
cy.exec('wp-env run tests-cli wp plugin activate wordpress-seo wordpress-seo-premium wp-rest-api-v2-menus;', options)
Expand Down
2 changes: 0 additions & 2 deletions cypress/videos/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion wordpress/wp-content/themes/cds-redirector/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function redirectorStyles(): void
wp_enqueue_style('redirector-style', get_stylesheet_uri(), []);
}


/**
* Returns all theme options
*
Expand Down