-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3908 from GeotrekCE/improve_cypress_tests
Improve mocking tiles in cypress tests
- Loading branch information
Showing
9 changed files
with
383 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,88 @@ | ||
describe('Login from home page / admin page', () => { | ||
|
||
beforeEach(() => { | ||
cy.setCookie('django_language', 'en'); | ||
}) | ||
beforeEach(() => { | ||
cy.setCookie('django_language', 'en'); | ||
}) | ||
|
||
it('Redirects to login page.', () => { | ||
cy.visit('/') | ||
cy.url().should('include', '/login/?next=/') | ||
cy.get('form') | ||
cy.contains("Username") | ||
cy.get('[name="username"]') | ||
it('Redirects to login page.', () => { | ||
cy.visit('/'); | ||
cy.url().should('include', '/login/?next=/'); | ||
cy.get('form'); | ||
cy.contains("Username"); | ||
cy.get('[name="username"]'); | ||
}) | ||
|
||
it('Fail to login', () => { | ||
cy.visit('/login/?next=/') | ||
cy.get('[name="username"]') | ||
.type('fake') | ||
.should('have.value', 'fake') | ||
cy.get('[name="password"]') | ||
.type('password') | ||
.should('have.value', 'password') | ||
cy.get("button[type='submit']").click() | ||
cy.url().should('include', '/login/?next=/') | ||
}) | ||
it('Fail to login', () => { | ||
cy.visit('/login/?next=/'); | ||
cy.get('[name="username"]') | ||
.type('fake') | ||
.should('have.value', 'fake'); | ||
cy.get('[name="password"]') | ||
.type('password') | ||
.should('have.value', 'password'); | ||
cy.get("button[type='submit']").click(); | ||
cy.url().should('include', '/login/?next=/'); | ||
}) | ||
|
||
it('Login', () => { | ||
cy.visit('/login/?next=/') | ||
cy.get('[name="username"]') | ||
.type('admin') | ||
.should('have.value', 'admin') | ||
cy.get('[name="password"]') | ||
.type('admin') | ||
.should('have.value', 'admin') | ||
cy.get("button[type='submit']").click() | ||
cy.url().should('include', '/path/list/') | ||
cy.url().should('not.include', '/login/?next=/') | ||
}) | ||
it('Login', () => { | ||
cy.visit('/login/?next=/'); | ||
cy.get('[name="username"]') | ||
.type('admin') | ||
.should('have.value', 'admin'); | ||
cy.get('[name="password"]') | ||
.type('admin') | ||
.should('have.value', 'admin'); | ||
cy.get("button[type='submit']").click(); | ||
cy.url().should('include', '/path/list/'); | ||
cy.url().should('not.include', '/login/?next=/'); | ||
}) | ||
|
||
it('Redirects to admin login page.', () => { | ||
cy.visit('/admin') | ||
cy.url().should('include', '/login/?next=/') | ||
cy.get('form') | ||
cy.contains("Username") | ||
cy.get('[name="username"]') | ||
}) | ||
it('Redirects to admin login page.', () => { | ||
cy.visit('/admin'); | ||
cy.url().should('include', '/login/?next=/'); | ||
cy.get('form'); | ||
cy.contains("Username"); | ||
cy.get('[name="username"]'); | ||
}) | ||
|
||
it('Login admin', () => { | ||
cy.visit('/admin/') | ||
cy.get('[name="username"]') | ||
.type('admin') | ||
.should('have.value', 'admin') | ||
cy.get('[name="password"]') | ||
.type('admin') | ||
.should('have.value', 'admin') | ||
cy.get("input[type='submit']").click() | ||
cy.url().should('include', '/admin/') | ||
cy.url().should('not.include', '/login/?next=/') | ||
}) | ||
it('Login admin', () => { | ||
cy.visit('/admin/'); | ||
cy.get('[name="username"]') | ||
.type('admin') | ||
.should('have.value', 'admin'); | ||
cy.get('[name="password"]') | ||
.type('admin') | ||
.should('have.value', 'admin'); | ||
cy.get("input[type='submit']").click(); | ||
cy.url().should('include', '/admin/'); | ||
cy.url().should('not.include', '/login/?next=/'); | ||
}) | ||
}) | ||
|
||
|
||
describe('Logout', () => { | ||
beforeEach(() => { | ||
const username = 'admin' | ||
const password = 'admin' | ||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}) | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
}) | ||
beforeEach(() => { | ||
const username = 'admin'; | ||
const password = 'admin'; | ||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}) | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
}) | ||
|
||
it('Logout', () => { | ||
cy.visit('/') | ||
cy.url().should('include', '/path/list/') | ||
cy.get("a.dropdown-toggle").contains('admin').click() | ||
cy.get("a[href='/logout/']").click() | ||
cy.url().should('include', '/login/') | ||
}) | ||
it('Logout', () => { | ||
cy.visit('/'); | ||
cy.url().should('include', '/path/list/'); | ||
cy.get("a.dropdown-toggle").contains('admin').click(); | ||
cy.get("a[href='/logout/']").click(); | ||
cy.url().should('include', '/login/'); | ||
}) | ||
|
||
|
||
it('Logout admin', () => { | ||
cy.visit('/admin/') | ||
cy.get("a[href='/admin/logout/']").click() | ||
cy.url().should('include', '/admin/logout/') | ||
}) | ||
it('Logout admin', () => { | ||
cy.visit('/admin/'); | ||
cy.get("a[href='/admin/logout/']").click(); | ||
cy.url().should('include', '/admin/logout/'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
describe('Create path', () => { | ||
before(() => { | ||
const username = 'admin' | ||
const password = 'admin' | ||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}) | ||
}) | ||
before(() => { | ||
const username = 'admin'; | ||
const password = 'admin'; | ||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}); | ||
}) | ||
|
||
beforeEach(() => { | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
}); | ||
beforeEach(() => { | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
}); | ||
|
||
it('Change language', () => { | ||
cy.visit('/path/list') | ||
cy.get("a.dropdown-toggle").contains('admin').click() | ||
cy.get("button.language-menu-item[value='fr']").click() | ||
cy.get("a.btn-success[href='/path/add/']").contains('Ajouter un tronçon') | ||
cy.url().should('include', '/path/list/') | ||
cy.get("a.dropdown-toggle").contains('admin').click() | ||
cy.get("button.language-menu-item[value='en']").click() | ||
}) | ||
it('Change language', () => { | ||
cy.visit('/path/list'); | ||
cy.get("a.dropdown-toggle").contains('admin').click(); | ||
cy.get("button.language-menu-item[value='fr']").click(); | ||
cy.get("a.btn-success[href='/path/add/']").contains('Ajouter un tronçon'); | ||
cy.url().should('include', '/path/list/'); | ||
cy.get("a.dropdown-toggle").contains('admin').click(); | ||
cy.get("button.language-menu-item[value='en']").click(); | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,84 @@ | ||
describe('Create path', () => { | ||
before(() => { | ||
const username = 'admin' | ||
const password = 'admin' | ||
before(() => { | ||
const username = 'admin'; | ||
const password = 'admin'; | ||
|
||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}); | ||
}); | ||
cy.loginByCSRF(username, password) | ||
.then((resp) => { | ||
expect(resp.status).to.eq(200) | ||
}); | ||
cy.mockTiles(); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.setCookie('django_language', 'en'); | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
cy.intercept("https://*.tile.opentopomap.org/*/*/*.png", {fixture: "images/tile.png"}) | ||
}); | ||
beforeEach(() => { | ||
cy.setCookie('django_language', 'en'); | ||
Cypress.Cookies.preserveOnce('sessionid', 'csrftoken'); | ||
}); | ||
|
||
it('Create path', () => { | ||
cy.visit('/path/list') | ||
cy.get("a.btn-success[href='/path/add/']").contains('Add a new path').click() | ||
cy.get("a.leaflet-draw-draw-polyline").click() | ||
cy.get('.leaflet-map-pane') | ||
.click(390, 250) | ||
.click(400, 50) | ||
.click(450, 50) | ||
.click(450, 150) | ||
.click(450, 150); | ||
cy.get("input[name='name']").type('Path number 1') | ||
cy.get('#save_changes').click() | ||
cy.url().should('not.include', '/path/add/') | ||
cy.get('.content').should('contain', 'Path number 1') | ||
}) | ||
it('Create path', () => { | ||
cy.visit('/path/list'); | ||
cy.wait('@tiles'); | ||
cy.get("a.btn-success[href='/path/add/']").contains('Add a new path').click(); | ||
cy.get("a.leaflet-draw-draw-polyline").click(); | ||
cy.get('.leaflet-map-pane') | ||
.click(390, 250) | ||
.click(400, 50) | ||
.click(450, 50) | ||
.click(450, 150) | ||
.click(450, 150); | ||
cy.get("input[name='name']").type('Path number 1'); | ||
cy.get('#save_changes').click(); | ||
cy.url().should('not.include', '/path/add/'); | ||
cy.get('.content').should('contain', 'Path number 1'); | ||
}) | ||
|
||
it('Create path split', () => { | ||
cy.visit('/path/list') | ||
cy.get("a.btn-success[href='/path/add/']").contains('Add a new path').click() | ||
cy.get("a.leaflet-draw-draw-polyline").click() | ||
cy.get('.leaflet-map-pane') | ||
.click(380, 220) | ||
.click(405, 290) | ||
.click(405, 290); | ||
cy.get("input[name='name']").type('Path number 2') | ||
cy.get('#save_changes').click() | ||
cy.url().should('not.include', '/path/add/') | ||
cy.get('.content').should('contain', 'Path number 2') | ||
}) | ||
it('Path list', () => { | ||
cy.visit('/path/list') | ||
cy.get("a[title='Path number 1']").should('have.length', 2) | ||
cy.get("a[title='Path number 2']").should('have.length', 2) | ||
}) | ||
it('Path action delete multiple without path', () => { | ||
cy.visit('/path/list') | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click() | ||
cy.get("a[href='#delete']").click() | ||
cy.url().should('include', '/path/list/') | ||
cy.get("a[title='Path number 1']").should('have.length', 2) | ||
cy.get("a[title='Path number 2']").should('have.length', 2) | ||
}) | ||
it('Path action delete multiple path', () => { | ||
cy.visit('/path/list') | ||
cy.get("input[name='path[]'][value='1']").click() | ||
cy.get("input[name='path[]'][value='2']").click() | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click() | ||
cy.get("a[href='#delete']").click() | ||
cy.get("input[type='submit']").click() | ||
cy.url().should('include', '/path/list/') | ||
cy.get("a[title='Path number 1']").should('have.length', 1) | ||
cy.get("a[title='Path number 2']").should('have.length', 1) | ||
}) | ||
// Two path | ||
it('Path action merge multiple path', () => { | ||
cy.visit('/path/list') | ||
cy.get("input[name='path[]'][value='3']").click() | ||
cy.get("input[name='path[]'][value='4']").click() | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click() | ||
cy.get("a[href='#confirm-merge']").click() | ||
cy.get("button").contains('Merge').click() | ||
cy.url().should('include', '/path/list/') | ||
cy.get("table#objects-list tbody tr").should('have.length', 1) | ||
}) | ||
// One last path | ||
it('Create path split', () => { | ||
cy.visit('/path/list'); | ||
cy.get("a.btn-success[href='/path/add/']").contains('Add a new path').click(); | ||
cy.get("a.leaflet-draw-draw-polyline").click(); | ||
cy.get('.leaflet-map-pane') | ||
.click(380, 220) | ||
.click(405, 290) | ||
.click(405, 290); | ||
cy.get("input[name='name']").type('Path number 2'); | ||
cy.get('#save_changes').click(); | ||
cy.url().should('not.include', '/path/add/'); | ||
cy.get('.content').should('contain', 'Path number 2'); | ||
}) | ||
it('Path list', () => { | ||
cy.visit('/path/list'); | ||
cy.get("a[title='Path number 1']").should('have.length', 2); | ||
cy.get("a[title='Path number 2']").should('have.length', 2); | ||
}) | ||
it('Path action delete multiple without path', () => { | ||
cy.visit('/path/list'); | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click(); | ||
cy.get("a[href='#delete']").click(); | ||
cy.url().should('include', '/path/list/'); | ||
cy.get("a[title='Path number 1']").should('have.length', 2); | ||
cy.get("a[title='Path number 2']").should('have.length', 2); | ||
}) | ||
it('Path action delete multiple path', () => { | ||
cy.visit('/path/list'); | ||
cy.get("input[name='path[]'][value='1']").click(); | ||
cy.get("input[name='path[]'][value='2']").click(); | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click(); | ||
cy.get("a[href='#delete']").click(); | ||
cy.get("input[type='submit']").click(); | ||
cy.url().should('include', '/path/list/'); | ||
cy.get("a[title='Path number 1']").should('have.length', 1); | ||
cy.get("a[title='Path number 2']").should('have.length', 1); | ||
}) | ||
// Two path | ||
it('Path action merge multiple path', () => { | ||
cy.visit('/path/list'); | ||
cy.get("input[name='path[]'][value='3']").click(); | ||
cy.get("input[name='path[]'][value='4']").click(); | ||
cy.get("a.btn-primary[data-toggle='dropdown']").click(); | ||
cy.get("a[href='#confirm-merge']").click(); | ||
cy.get("button").contains('Merge').click(); | ||
cy.url().should('include', '/path/list/'); | ||
cy.get("table#objects-list tbody tr").should('have.length', 1); | ||
}) | ||
// One last path | ||
}) |
Oops, something went wrong.