Skip to content

Commit

Permalink
Merge pull request #3908 from GeotrekCE/improve_cypress_tests
Browse files Browse the repository at this point in the history
Improve mocking tiles in cypress tests
  • Loading branch information
submarcos committed Jan 29, 2024
2 parents 3bde71c + 937155c commit 75a6a63
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 371 deletions.
144 changes: 72 additions & 72 deletions cypress/integration/nav_authent.js
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/');
})
})
40 changes: 20 additions & 20 deletions cypress/integration/nav_b_language.js
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();
})

})
155 changes: 78 additions & 77 deletions cypress/integration/nav_create_path.js
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
})

0 comments on commit 75a6a63

Please sign in to comment.