Skip to content

Commit c2d7fcc

Browse files
authored
E2E test set up (#64)
* E2E test set up * E2E test | completed jouney
1 parent 2c718dd commit c2d7fcc

File tree

8 files changed

+130
-1
lines changed

8 files changed

+130
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/node_modules
55
/.pnp
66
.pnp.js
7+
package-lock.json
8+
cypress/videos
79

810
# testing
911
/coverage

cypress.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"video":false,
3+
"env": {
4+
"prodUrl": "https://metrofare.netlify.app/",
5+
"devUrl": "http://localhost:3000/"
6+
}
7+
}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"departure": "[d=\"M602,411a10,10 0 1,0 20,0 a10,10 0 1,0 -20,0 \"]",
3+
"arrival": "[d=\"M674,464a10,10 0 1,0 20,0 a10,10 0 1,0 -20,0 \"]"
4+
5+
}

cypress/integration/endToEndTest.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('Verify end to end test scenarios', function(){
4+
5+
beforeEach(function(){
6+
cy.fixture('example').then(function(data)
7+
{
8+
this.data = data
9+
})
10+
})
11+
12+
it('land on MetroFare home screen', function(){
13+
cy.visit(Cypress.env('prodUrl'))
14+
cy.get('.MuiTypography-root.MuiTypography-h6').should('have.text', 'MetroFare')
15+
})
16+
17+
it('select departure station', function(){
18+
cy.get(this.data.departure).click()
19+
cy.get('h3').then(function(element){
20+
const departureNameWithCode = element.text()
21+
var departureName = departureNameWithCode.split(' ')
22+
departureName = departureName[1].trim()
23+
cy.get('.leaflet-popup-content > section > :nth-child(2)').click()
24+
cy.get('.from-to-button-width70').should('contain.text', departureName)
25+
})
26+
})
27+
28+
it('select arrival station', function(){
29+
cy.get(this.data.arrival).click()
30+
cy.get('h3').then(function(element){
31+
const arrivalNameWithCode = element.text()
32+
var arrivalName = arrivalNameWithCode.split(' ')
33+
arrivalName = arrivalName[1].trim()
34+
cy.get('.leaflet-popup-content > section > :nth-child(3)').click()
35+
cy.get(':nth-child(2) > .from-to-button-width70').should('contain.text', arrivalName)
36+
})
37+
})
38+
39+
it('display price of the jouney', function(){
40+
//fix price can be improve
41+
cy.get('.MuiGrid-grid-xs-10 > .MuiPaper-root > .MuiGrid-direction-xs-column > .MuiGrid-container > :nth-child(2)')
42+
.should('contain.text', '26 Baht')
43+
})
44+
45+
})

cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

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 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')

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/react-leaflet": "^2.5.1",
2222
"@types/react-router-dom": "^5.1.6",
2323
"axios": "^0.21.1",
24+
"cypress": "^8.6.0",
2425
"dotenv": "^8.2.0",
2526
"firebase": "^8.2.1",
2627
"http-proxy": "^1.18.1",
@@ -46,7 +47,9 @@
4647
"test": "react-scripts test",
4748
"test:coverage": "yarn test --coverage --watchAll=false",
4849
"eject": "react-scripts eject",
49-
"sec-audit": "hawkeye scan"
50+
"sec-audit": "hawkeye scan",
51+
"test:e2e": "node_modules/.bin/cypress run",
52+
"test:open": "node_modules/.bin/cypress open"
5053
},
5154
"eslintConfig": {
5255
"extends": "react-app"

0 commit comments

Comments
 (0)