Skip to content

Commit a2605dc

Browse files
committed
feat(specs): add cypress
1 parent e976d35 commit a2605dc

19 files changed

+5541
-492
lines changed

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

cypress.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"baseUrl": "http://localhost:4200"
3+
}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/home.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export function generateContent(lang = 'english') {
2+
// Structural Directive
3+
cy.get(`[data-cy=regular]`).should('contain', `home ${lang}`);
4+
cy.get(`[data-cy=with-params]`).should('contain', `alert 🦄 ${lang}`);
5+
cy.get(`[data-cy=with-translation-reuse]`).should('contain', `a.b.c from list ${lang}`);
6+
7+
// Directive
8+
cy.get(`[data-cy=d-regular] span`).should('contain', `home ${lang}`);
9+
cy.get(`[data-cy=d-with-params]`).should('contain', `alert 🦄 ${lang}`);
10+
cy.get(`[data-cy=d-with-translation-reuse]`).should('contain', `a.b.c from list ${lang}`);
11+
cy.get(`[data-cy=d-dynamic-key]`).should('contain', `home ${lang}`);
12+
13+
// Dynamic key
14+
cy.get(`[data-cy=d-dynamic-key]`).click();
15+
cy.get(`[data-cy=d-dynamic-key]`).should('contain', `from list`);
16+
cy.get(`[data-cy=d-dynamic-key]`).click();
17+
cy.get(`[data-cy=d-dynamic-key]`).should('contain', `home ${lang}`);
18+
19+
// Dynamic params
20+
cy.get(`[data-cy=d-with-params]`).click();
21+
cy.get(`[data-cy=d-with-params]`).should('contain', `alert 🦄🦄🦄 ${lang}`);
22+
cy.get(`[data-cy=d-with-params]`).click();
23+
cy.get(`[data-cy=d-with-params]`).should('contain', `🦄 ${lang}`);
24+
25+
// Pipe
26+
cy.get(`[data-cy=p-regular]`).should('contain', `home ${lang}`);
27+
cy.get(`[data-cy=p-with-params]`).should('contain', `alert 🦄 ${lang}`);
28+
cy.get(`[data-cy=p-with-translation-reuse]`).should('contain', `a.b.c from list ${lang}`);
29+
30+
// Missing key
31+
cy.get(`[data-cy=missing-key]`).should('contain', 'alertty');
32+
}
33+
34+
describe('Transloco', () => {
35+
beforeEach(() => {
36+
cy.visit('');
37+
});
38+
39+
it('should translate to english', () => {
40+
generateContent();
41+
42+
cy.get(`[data-cy=es]`).click();
43+
44+
generateContent('spanish');
45+
46+
cy.get(`[data-cy=en]`).click();
47+
48+
generateContent();
49+
});
50+
});

cypress/integration/onPush.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { generateContent } from './home';
2+
3+
describe('Transloco - onPush Component', () => {
4+
beforeEach(() => {
5+
cy.visit('/page');
6+
});
7+
8+
it('should translate to english', () => {
9+
generateContent();
10+
11+
cy.get(`[data-cy=es]`).click();
12+
13+
generateContent('spanish');
14+
15+
cy.get(`[data-cy=en]`).click();
16+
17+
generateContent();
18+
});
19+
});

cypress/plugins/cy-ts-preprocessor.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const wp = require('@cypress/webpack-preprocessor');
2+
3+
const webpackOptions = {
4+
resolve: {
5+
extensions: ['.ts', '.js']
6+
},
7+
module: {
8+
rules: [
9+
{
10+
test: /\.ts$/,
11+
exclude: [/node_modules/],
12+
use: [
13+
{
14+
loader: 'ts-loader'
15+
}
16+
]
17+
}
18+
]
19+
}
20+
};
21+
22+
const options = {
23+
webpackOptions
24+
};
25+
26+
module.exports = wp(options);

cypress/plugins/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor');
2+
3+
module.exports = on => {
4+
on('file:preprocessor', cypressTypeScriptPreprocessor);
5+
};

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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')

cypress/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["integration/*.ts", "support/*.ts", "../node_modules/cypress"]
4+
}

0 commit comments

Comments
 (0)