Skip to content

Commit c7d7d62

Browse files
committedDec 21, 2021
Add integration tests
1 parent cf963e0 commit c7d7d62

File tree

9 files changed

+2194
-5198
lines changed

9 files changed

+2194
-5198
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.DS_Store
33
.env
44
*.local
5+
cypress/fixtures
56
deploy.sh
67
dist
78
dist-ssr

‎.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"alexkrechik.cucumberautocomplete",
4+
"muralidharan92.cuke-step-definition-generator",
5+
"Shelex.vscode-cy-helper"
6+
]
7+
}

‎cypress.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"baseUrl": "https://pensieve.amatiasq.com",
3+
"clientRoute": "/halt",
4+
"viewportWidth": 1920,
5+
"viewportHeight": 1080,
6+
"chromeWebSecurity": false
7+
}

‎cypress/integration/happy_path.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
describe('Happy path', () => {
2+
const getFirstNote = () => cy.get('.note-item');
3+
const firstNoteTitle = () => getFirstNote().get('.title-part');
4+
const getFirstNoteStar = () => getFirstNote().get('.fa-star');
5+
const getFirstGroupCounter = () => cy.get('.counter');
6+
const getFirstGroupFavCounter = () => cy.get('.fav-counter');
7+
const evenIfNotVisible = { force: true };
8+
9+
before(() => {
10+
cy.login();
11+
cy.visit('/');
12+
});
13+
14+
after(async () => {
15+
await cy.deleteRepo();
16+
cy.window().then(win => {
17+
win.localStorage.clear();
18+
return indexedDB.deleteDatabase('pensieve-data');
19+
});
20+
});
21+
22+
it('Create note', () => {
23+
const clickCreateNote = () => cy.get(`aside .fa-plus`).click();
24+
25+
cy.expectCommitFrom(clickCreateNote);
26+
getFirstNote().should('be.exist');
27+
});
28+
29+
it('Unfavorite note', () => {
30+
getFirstNoteStar().should('have.class', 'fas');
31+
cy.expectCommitFrom(() => getFirstNoteStar().click());
32+
getFirstNoteStar().should('have.class', 'far');
33+
});
34+
35+
it('Favorite note', () => {
36+
getFirstNoteStar().should('have.class', 'far');
37+
cy.expectCommitFrom(() => getFirstNoteStar().click(evenIfNotVisible));
38+
getFirstNoteStar().should('have.class', 'fas');
39+
});
40+
41+
it('Edit note title', () => {
42+
getFirstNote().click();
43+
cy.writeToEditor('TESTING');
44+
firstNoteTitle().should('include.text', 'TESTING');
45+
cy.saveNote();
46+
});
47+
48+
it('Move note to folder', () => {
49+
const getFirstGroup = () => cy.get('.group');
50+
const getFirstGroupTitle = () => getFirstGroup().get('.group-title');
51+
52+
getFirstNote().click();
53+
cy.writeToEditor('MY FOLDER / NOTE NAME');
54+
firstNoteTitle().contains('NOTE NAME');
55+
cy.saveNote();
56+
getFirstGroup().should('be.exist');
57+
getFirstGroupTitle().contains('MY FOLDER');
58+
getFirstGroupCounter().contains('1');
59+
});
60+
61+
it('Unfavorite note in group', () => {
62+
getFirstGroupFavCounter().contains('1');
63+
getFirstNoteStar().should('have.class', 'fas');
64+
cy.expectCommitFrom(() => getFirstNoteStar().click());
65+
getFirstNoteStar().should('have.class', 'far');
66+
getFirstGroupFavCounter().should('not.exist');
67+
});
68+
69+
it('Favorite note in group', () => {
70+
getFirstGroupFavCounter().should('not.exist');
71+
getFirstNoteStar().should('have.class', 'far');
72+
cy.expectCommitFrom(() => getFirstNoteStar().click(evenIfNotVisible));
73+
getFirstNoteStar().should('have.class', 'fas');
74+
getFirstGroupFavCounter().contains('1');
75+
});
76+
77+
it('Delete note', () => {
78+
const deleteFirstNote = () =>
79+
cy.get('.note-item .fa-trash').click(evenIfNotVisible);
80+
81+
cy.expectCommitFrom(deleteFirstNote);
82+
getFirstNote().should('not.exist');
83+
});
84+
});

‎cypress/plugins/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference types="cypress" />
2+
3+
require('dotenv').config();
4+
// const cucumber = require('cypress-cucumber-preprocessor').default;
5+
6+
/**
7+
* @type {Cypress.PluginConfig}
8+
*/
9+
module.exports = (on, config) => {
10+
// on('file:preprocessor', cucumber());
11+
12+
for (const key of ['TEST_GH_USERNAME', 'TEST_GH_TOKEN']) {
13+
config.env[key] = getEnvironmentVariable(key);
14+
}
15+
16+
return config;
17+
};
18+
19+
function getEnvironmentVariable(name, defaultValue) {
20+
if (!(name in process.env) && !defaultValue) {
21+
throw new Error(`Missing mandatory environment variable ${name}`);
22+
}
23+
24+
return process.env[name] || defaultValue;
25+
}

‎cypress/support/commands.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
Cypress.Commands.add('login', () =>
28+
cy.window().then(win => {
29+
win.localStorage.setItem(
30+
'notes.gh-user',
31+
`{"data":"${Cypress.env('TEST_GH_USERNAME')}","version":1}`,
32+
);
33+
34+
win.localStorage.setItem(
35+
'notes.gh-token',
36+
`{"data":"${Cypress.env('TEST_GH_TOKEN')}","version":1}`,
37+
);
38+
}),
39+
);
40+
41+
Cypress.Commands.add('deleteRepo', () =>
42+
cy.request({
43+
method: 'DELETE',
44+
url: `https://api.github.com/repos/${Cypress.env(
45+
'TEST_GH_USERNAME',
46+
)}/pensieve-data`,
47+
headers: {
48+
Authorization: `token ${Cypress.env('TEST_GH_TOKEN')}`,
49+
},
50+
}),
51+
);
52+
53+
Cypress.Commands.add('expectCommitFrom', action => {
54+
cy.intercept('POST', '/commit').as('commit');
55+
action();
56+
cy.wait('@commit');
57+
});
58+
59+
Cypress.Commands.add('selectEditor', () => cy.get('.editor').click().focused());
60+
61+
Cypress.Commands.add('writeToEditor', text =>
62+
cy.selectEditor().type('{cmd}a').clear().type(text),
63+
);
64+
65+
Cypress.Commands.add('saveNote', () =>
66+
cy.expectCommitFrom(() => cy.selectEditor().type('{cmd}s')),
67+
);

‎cypress/support/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ***********************************************************
2+
// This example support/index.js 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+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')
21+
// Handle redirect to login page error

‎package-lock.json

+1,974-5,197
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88
"serve": "vite preview --port 1234",
99
"pwa": "npm run build && npm run serve",
1010
"lint": "eslint . --ext .ts",
11-
"prepare": "husky install"
11+
"prepare": "husky install",
12+
"cypress": "cypress open",
13+
"e2e": "cypress run"
1214
},
1315
"browserslist": [
1416
"> 1% and last 2 versions"
1517
],
18+
"cypress-cucumber-preprocessor": {
19+
"nonGlobalStepDefinitions": true
20+
},
1621
"dependencies": {
1722
"@amatiasq/client-storage": "^3.0.3",
1823
"@amatiasq/emitter": "^4.1.2",
@@ -36,6 +41,8 @@
3641
"@types/react-router-dom": "^5.1.7",
3742
"@types/uuid": "^8.3.0",
3843
"@typescript-eslint/eslint-plugin": "^4.14.2",
44+
"cypress": "^9.1.1",
45+
"dotenv": "^10.0.0",
3946
"eslint": "^7.19.0",
4047
"husky": "^7.0.1",
4148
"sass": "^1.32.6",

0 commit comments

Comments
 (0)
Please sign in to comment.