Skip to content

Commit f738ca5

Browse files
committed
Merge branch 'master' of github.com:pluginpal/strapi-plugin-config-sync
2 parents 5947a1b + 0594173 commit f738ca5

12 files changed

Lines changed: 1393 additions & 545 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/node_modules
22
**/public
33
**/build
4+
**/dist
45
**/config
56
**/scripts
67
**/playground

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
"globals": {
2626
"strapi": true
2727
},
28+
"overrides": [
29+
{
30+
"files": [
31+
"**/*.cy.*",
32+
"./cypress/**/*.*"
33+
],
34+
"extends": [
35+
"plugin:cypress/recommended"
36+
],
37+
"parserOptions": {
38+
"project": "./tsconfig.cypress.json"
39+
}
40+
}
41+
],
2842
"rules": {
2943
"import/no-unresolved": [2, {
3044
"ignore": [

.github/workflows/tests.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
run: yarn --frozen-lockfile
2828
- name: Run eslint
2929
run: yarn run eslint
30-
integration:
31-
name: 'integration'
30+
test:
31+
name: 'test'
3232
needs: [lint]
3333
runs-on: ubuntu-latest
3434
strategy:
@@ -50,29 +50,30 @@ jobs:
5050
run: cd playground && yarn install --unsafe-perm
5151
- name: Build playground
5252
run: yarn playground:build
53-
- name: Run test
53+
# - name: Run unit tests
54+
# run: yarn test:unit
55+
- name: Run integration tests
5456
run: yarn run -s test:integration
57+
- name: Run end-to-end tests
58+
uses: cypress-io/github-action@v6
59+
with:
60+
start: yarn playground:start
61+
- uses: actions/upload-artifact@v4
62+
if: failure()
63+
with:
64+
name: cypress-screenshots
65+
path: cypress/screenshots
66+
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
67+
- uses: actions/upload-artifact@v4
68+
if: failure()
69+
with:
70+
name: cypress-videos
71+
path: cypress/videos
72+
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
5573
- name: Upload coverage to Codecov
5674
uses: codecov/codecov-action@v2
5775
with:
5876
token: ${{ secrets.CODECOV }}
5977
flags: unit
6078
verbose: true
6179
fail_ci_if_error: true
62-
# unit:
63-
# name: 'unit'
64-
# needs: [lint]
65-
# runs-on: ubuntu-latest
66-
# strategy:
67-
# matrix:
68-
# node: [16, 18, 20]
69-
# steps:
70-
# - uses: actions/checkout@v2
71-
# - uses: actions/setup-node@v2
72-
# with:
73-
# node-version: ${{ matrix.node }}
74-
# cache: 'yarn'
75-
# - name: Install dependencies
76-
# run: yarn --ignore-scripts --frozen-lockfile
77-
# - name: Run test
78-
# run: yarn run -s test:unit

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ npm-debug.log
1414
build
1515
dist
1616
bundle
17+
18+
# Cypress
19+
cypress/screenshots/
20+
cypress/videos/
21+
cypress/downloads/

admin/src/index.cy.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// <reference types="cypress" />
2+
3+
describe('Config Sync', () => {
4+
beforeEach(() => {
5+
cy.task('deleteFolder', 'playground/config/sync');
6+
});
7+
8+
it('Check the config diff', () => {
9+
cy.login();
10+
cy.navigateToInterface();
11+
cy.initialExport();
12+
13+
cy.makeConfigChanges();
14+
15+
cy.navigateToInterface();
16+
17+
cy.get('tbody tr').contains('plugin_users-permissions_advanced').click();
18+
19+
cy.contains('"unique_email": true,');
20+
cy.contains('"unique_email": false,');
21+
});
22+
23+
it('Download the config as zip', () => {
24+
cy.login();
25+
cy.navigateToInterface();
26+
cy.initialExport();
27+
28+
cy.intercept({
29+
method: 'GET',
30+
url: '/config-sync/zip',
31+
}).as('getConfigZip');
32+
33+
cy.get('button').contains('Download Config').click();
34+
35+
cy.wait('@getConfigZip').then((interception) => {
36+
const configZipResponse = interception.response.body;
37+
const downloadsFolder = Cypress.config('downloadsFolder');
38+
cy.readFile(`${downloadsFolder}/${configZipResponse.name.replaceAll(':', '_')}`).should('exist');
39+
});
40+
});
41+
42+
it('Partial import & export', () => {
43+
cy.login();
44+
cy.navigateToInterface();
45+
cy.initialExport();
46+
47+
cy.makeConfigChanges();
48+
49+
cy.navigateToInterface();
50+
51+
cy.get('button[aria-label="Select all entries"]').click();
52+
53+
cy.intercept({
54+
method: 'POST',
55+
url: '/config-sync/import',
56+
}).as('importConfig');
57+
cy.get('button[aria-label="Select plugin_upload_settings"]').click();
58+
cy.get('button').contains('Import').click();
59+
cy.get('button').contains('Yes, import').click();
60+
cy.wait('@importConfig').its('response.statusCode').should('equal', 200);
61+
cy.contains('plugin_users-permissions_advanced');
62+
cy.contains('plugin_users-permissions_email');
63+
64+
cy.intercept({
65+
method: 'POST',
66+
url: '/config-sync/export',
67+
}).as('exportConfig');
68+
cy.get('button[aria-label="Select plugin_users-permissions_advanced"]').click();
69+
cy.get('button').contains('Export').click();
70+
cy.get('button').contains('Yes, export').click();
71+
cy.wait('@exportConfig').its('response.statusCode').should('equal', 200);
72+
cy.contains('plugin_users-permissions_email');
73+
});
74+
});

cypress.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { defineConfig } = require('cypress');
2+
const fs = require('fs-extra');
3+
4+
module.exports = defineConfig({
5+
e2e: {
6+
baseUrl: 'http://localhost:1337',
7+
specPattern: '**/*.cy.{js,ts,jsx,tsx}',
8+
video: true,
9+
defaultCommandTimeout: 30000,
10+
requestTimeout: 30000,
11+
setupNodeEvents(on, config) {
12+
// implement node event listeners here.
13+
// eslint-disable-next-line global-require
14+
require('cypress-terminal-report/src/installLogsPrinter')(on);
15+
16+
on('task', {
17+
deleteFolder(folderName) {
18+
console.log(`deleting folder ${folderName}`);
19+
20+
return fs.remove(folderName)
21+
.then(() => {
22+
console.log(`folder ${folderName} deleted`);
23+
return null;
24+
})
25+
.catch((err) => {
26+
console.error(`error deleting folder ${folderName}`, err);
27+
throw err;
28+
});
29+
},
30+
});
31+
},
32+
},
33+
});

cypress/support/commands.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
29+
Cypress.Commands.add('login', (path) => {
30+
cy.visit('/');
31+
32+
cy.intercept({
33+
method: 'GET',
34+
url: '/admin/users/me',
35+
}).as('sessionCheck');
36+
37+
cy.intercept({
38+
method: 'GET',
39+
url: '/admin/init',
40+
}).as('adminInit');
41+
42+
// Wait for the initial request to complete.
43+
cy.wait('@adminInit').its('response.statusCode').should('equal', 200);
44+
45+
// Wait for the form to render.
46+
// eslint-disable-next-line cypress/no-unnecessary-waiting
47+
cy.wait(1000);
48+
49+
cy.get('body').then(($body) => {
50+
// Login
51+
if ($body.text().includes('Log in to your Strapi account')) {
52+
cy.get('input[name="email"]').type('johndoe@example.com');
53+
cy.get('input[name="password"]').type('Abc12345678');
54+
cy.get('button[type="submit"]').click();
55+
cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200);
56+
57+
// Sometimes the page hangs after logging in.
58+
// If this happens we reload the page and log in again.
59+
cy.reload();
60+
cy.get('body').then(($b) => {
61+
if ($b.text().includes('Log in to your Strapi account')) {
62+
cy.login();
63+
}
64+
});
65+
}
66+
// Register
67+
if ($body.text().includes('Credentials are only used to authenticate in Strapi')) {
68+
cy.get('input[name="firstname"]').type('John');
69+
cy.get('input[name="email"]').type('johndoe@example.com');
70+
cy.get('input[name="password"]').type('Abc12345678');
71+
cy.get('input[name="confirmPassword"]').type('Abc12345678');
72+
cy.get('button[type="submit"]').click();
73+
cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200);
74+
}
75+
});
76+
});
77+
78+
Cypress.Commands.add('navigateToInterface', (path) => {
79+
cy.intercept({
80+
method: 'GET',
81+
url: '/config-sync/diff',
82+
}).as('getConfigDiff');
83+
84+
cy.get('a[href="/admin/settings"]').click();
85+
cy.get('a[href="/admin/settings/config-sync"]').click();
86+
87+
cy.wait('@getConfigDiff').its('response.statusCode').should('equal', 200);
88+
});
89+
90+
91+
Cypress.Commands.add('initialExport', (path) => {
92+
cy.intercept({
93+
method: 'POST',
94+
url: '/config-sync/export',
95+
}).as('exportConfig');
96+
97+
cy.get('button').contains('Make the initial export').click();
98+
cy.get('button').contains('Yes, export').click();
99+
100+
cy.wait('@exportConfig').its('response.statusCode').should('equal', 200);
101+
102+
cy.contains('Config was successfully exported to config/sync/.');
103+
});
104+
105+
Cypress.Commands.add('makeConfigChanges', (path) => {
106+
// Change a setting in the UP advanced settings
107+
cy.intercept({
108+
method: 'PUT',
109+
url: '/users-permissions/advanced',
110+
}).as('saveUpAdvanced');
111+
cy.get('a[href="/admin/settings/users-permissions/advanced-settings"]').click();
112+
cy.get('input[name="unique_email"').click();
113+
cy.get('button[type="submit"]').click();
114+
cy.wait('@saveUpAdvanced').its('response.statusCode').should('equal', 200);
115+
116+
// Change a setting in the media library settings
117+
cy.intercept({
118+
method: 'PUT',
119+
url: '/upload/settings',
120+
}).as('saveMediaLibrarySettings');
121+
cy.get('a[href="/admin/settings/media-library"]').click();
122+
cy.get('input[name="responsiveDimensions"').click();
123+
cy.get('button[type="submit"]').click();
124+
cy.wait('@saveMediaLibrarySettings').its('response.statusCode').should('equal', 200);
125+
126+
// Change a setting in the email templates
127+
cy.intercept({
128+
method: 'PUT',
129+
url: '/users-permissions/email-templates',
130+
}).as('saveUpEmailTemplates');
131+
cy.get('a[href="/admin/settings/users-permissions/email-templates"]').click();
132+
cy.get('tbody tr').contains('Reset password').click();
133+
cy.get('input[name="options.response_email"]').clear();
134+
cy.get('input[name="options.response_email"]').type(`${Math.random().toString(36).substring(2, 15)}@example.com`);
135+
cy.get('button[type="submit"]').click();
136+
cy.wait('@saveUpEmailTemplates').its('response.statusCode').should('equal', 200);
137+
});

cypress/support/e2e.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
require('cypress-terminal-report/src/installLogsCollector')();
20+
21+
// Alternatively you can use CommonJS syntax:
22+
// require('./commands')

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
"eslint:fix": "eslint --fix './**/*.{js,jsx}'",
3737
"test:unit": "jest --verbose",
3838
"test:integration": "cd playground && node_modules/.bin/jest --verbose --forceExit --detectOpenHandles",
39+
"test:e2e": "cypress open",
3940
"playground:install": "yarn playground:yalc-add-link && cd playground && yarn install",
4041
"playground:yalc-add": "cd playground && yalc add strapi-plugin-config-sync",
4142
"playground:yalc-add-link": "cd playground && yalc add --link strapi-plugin-config-sync",
4243
"playground:build": "cd playground && yarn build",
43-
"playground:develop": "cd playground && yarn develop"
44+
"playground:develop": "cd playground && yarn develop",
45+
"playground:start": "cd playground && yarn start"
4446
},
4547
"dependencies": {
4648
"adm-zip": "^0.5.16",
@@ -95,12 +97,15 @@
9597
"@strapi/strapi": "^5.0.0",
9698
"@strapi/utils": "^5.0.0",
9799
"babel-eslint": "9.0.0",
100+
"cypress": "^13.9.0",
101+
"cypress-terminal-report": "^6.0.2",
98102
"eslint": "^7.32.0",
99103
"eslint-config-airbnb": "^18.2.1",
100104
"eslint-config-react-app": "^3.0.7",
101105
"eslint-import-resolver-webpack": "^0.11.0",
102106
"eslint-loader": "^4.0.2",
103107
"eslint-plugin-babel": "^5.3.0",
108+
"eslint-plugin-cypress": "^3.2.0",
104109
"eslint-plugin-flowtype": "2.50.1",
105110
"eslint-plugin-import": "^2.22.1",
106111
"eslint-plugin-jsx-a11y": "^6.4.1",

0 commit comments

Comments
 (0)