Skip to content

Commit

Permalink
Add e2e tests for control unit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 11, 2023
1 parent fafe1ae commit bbda84f
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context('Back Office > Administration List > Filters', () => {
context('Back Office > Administration Table > Filters', () => {
beforeEach(() => {
cy.intercept('GET', `/api/v1/administrations`).as('getAdministrations')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Successful archiving and deleting use cases are tested in `administration_form.spec.ts` for Test Idempotency purpose
context('Back Office > Administration List > Row Actions', () => {
context('Back Office > Administration Table > Row Actions', () => {
beforeEach(() => {
cy.intercept('GET', `/api/v1/administrations`).as('getAdministrations')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context('Back Office > Base List > Filters', () => {
context('Back Office > Base Table > Filters', () => {
beforeEach(() => {
cy.intercept('GET', `/api/v1/bases`).as('getBases')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context('Back Office > Control Unit List > Filters', () => {
context('Back Office > Control Unit Table > Filters', () => {
beforeEach(() => {
cy.intercept('GET', `/api/v2/control_units`).as('getControlUnits')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Successful archiving and deleting use cases are tested in `control_unit_form.spec.ts` for Test Idempotency purpose
context('Back Office > Control Unit List > Row Actions', () => {
context('Back Office > Control Unit Table > Row Actions', () => {
beforeEach(() => {
cy.intercept('GET', `/api/v2/control_units`).as('getControlUnits')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { gotToMainWindowAndOpenControlUnit } from './utils'

context('Main Window > Control Unit Dialog > Contact List', () => {
beforeEach(() => {
gotToMainWindowAndOpenControlUnit(10000)
})

it('Should show all contacts by default', () => {
cy.contains('Contact 1').should('be.visible')
cy.contains('Contact 2').should('be.visible')
})

it('Should validate the form', () => {
cy.clickButton('Ajouter un contact')

cy.clickButton('Ajouter')

cy.contains('Veuillez choisir un nom.').should('be.visible')
cy.contains('Veuillez entrer un téléphone ou un email.').should('be.visible')

cy.clickButton('Annuler')

cy.get('p').contains('Ajouter un contact').should('not.exist')
})

it('Should add, edit and delete a contact', () => {
// -------------------------------------------------------------------------
// Create

cy.intercept('POST', `/api/v1/control_unit_contacts`).as('createControlUnitContact')

cy.clickButton('Ajouter un contact')

cy.fill('Nom du contact', 'Adjoint')
cy.fill('Numéro de téléphone', '0123456789')
cy.fill('Adresse mail', '[email protected]')

cy.clickButton('Ajouter')

cy.wait('@createControlUnitContact').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
email: '[email protected]',
name: 'ADJUNCT',
phone: '0123456789'
})
})

cy.get('p').contains('Ajouter un contact').should('not.exist')
cy.contains('Adjoint').should('be.visible')

// -------------------------------------------------------------------------
// Edit

cy.intercept('PUT', `/api/v1/control_unit_contacts/4`).as('updateControlUnitContact')

cy.getDataCy('ControlUnitDialog-control-unit-contact').filter('[data-id="4"]').clickButton('Éditer ce contact')

cy.fill('Nom du contact', 'Passerelle')
cy.fill('Numéro de téléphone', '9876543210')
cy.fill('Adresse mail', '[email protected]')

cy.clickButton('Enregistrer les modifications')

cy.wait('@updateControlUnitContact').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
email: '[email protected]',
id: 4,
name: 'BRIDGE',
phone: '9876543210'
})
})

cy.get('p').contains('Éditer un contact').should('not.exist')
cy.contains('Enregistrer les modifications').should('not.exist')
cy.contains('Passerelle').should('be.visible')

// -------------------------------------------------------------------------
// Delete

cy.intercept('DELETE', `/api/v1/control_unit_contacts/4`).as('deleteControlUnitContact')

cy.getDataCy('ControlUnitDialog-control-unit-contact').filter('[data-id="4"]').clickButton('Éditer ce contact')
cy.clickButton('Supprimer ce contact')
cy.clickButton('Supprimer')

cy.wait('@deleteControlUnitContact')

cy.contains('Passerelle').should('not.exist')
})
})
57 changes: 57 additions & 0 deletions frontend/cypress/e2e/main_window/control_unit_dialog/form.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { gotToMainWindowAndOpenControlUnit } from './utils'

context('Main Window > Control Unit Dialog > Resource List', () => {
beforeEach(() => {
gotToMainWindowAndOpenControlUnit(10000)
})

it('Should edit a control unit', () => {
cy.intercept('PUT', `/api/v2/control_units/10000`).as('updateControlUnit')

// -------------------------------------------------------------------------
// Terms note

cy.getDataCy('ControlUnitDialog-termsNote').forceClick()

cy.fill('Modalités de contact avec l’unité', 'Des modalités de contact avec l’unité.')

cy.clickButton('Valider')

cy.wait('@updateControlUnit').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
id: 10000,
termsNote: 'Des modalités de contact avec l’unité.'
})
})

cy.contains('Des modalités de contact avec l’unité.').should('be.visible')
cy.get('.Element-Button').contains('Valider').should('not.exist')

// -------------------------------------------------------------------------
// Area note

cy.getDataCy('ControlUnitDialog-areaNote').forceClick()

cy.fill('Secteur d’intervention', 'Un secteur d’intervention.')

cy.clickButton('Valider')

cy.wait('@updateControlUnit').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
areaNote: 'Un secteur d’intervention.',
id: 10000
})
})

cy.contains('Un secteur d’intervention.').should('be.visible')
cy.get('.Element-Button').contains('Valider').should('not.exist')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { gotToMainWindowAndOpenControlUnit } from './utils'

context('Main Window > Control Unit Dialog > Resource List', () => {
beforeEach(() => {
gotToMainWindowAndOpenControlUnit(10000)
})

it('Should show all resources by default', () => {
cy.contains('Barge – Semi-rigide 1').should('be.visible')
cy.contains('Barge – Semi-rigide 2').should('be.visible')
})

it('Should validate the form', () => {
cy.clickButton('Ajouter un moyen')

cy.clickButton('Ajouter')

cy.contains('Veuillez choisir un type.').should('be.visible')
cy.contains('Veuillez choisir une base.').should('be.visible')

cy.clickButton('Annuler')

cy.get('p').contains('Ajouter un moyen').should('not.exist')
})

it('Should add, edit and delete a resource', () => {
// -------------------------------------------------------------------------
// Create

cy.intercept('POST', `/api/v1/control_unit_resources`).as('createControlUnitResource')

cy.clickButton('Ajouter un moyen')

cy.fill('Type de moyen', 'Avion')
// On ne met pas de nom de moyen ici
// pour tester que ce soit bien le type qui soit utilisé comme nom lorsque le nom est vide.
cy.fill('Base du moyen', 'Dunkerque')
cy.fill('Commentaire', 'Un commentaire sur le moyen.')

cy.clickButton('Ajouter')

cy.wait('@createControlUnitResource').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
baseId: 3,
name: 'Avion',
note: 'Un commentaire sur le moyen.',
type: 'AIRPLANE'
})
})

cy.get('p').contains('Ajouter un moyen').should('not.exist')
cy.contains('Avion – Avion').should('be.visible')

// -------------------------------------------------------------------------
// Edit

cy.intercept('PUT', `/api/v1/control_unit_resources/13`).as('updateControlUnitResource')

cy.getDataCy('ControlUnitDialog-control-unit-resource').filter('[data-id="13"]').clickButton('Éditer ce moyen')

cy.fill('Type de moyen', 'Bâtiment de soutien')
cy.fill('Nom du moyen', 'Super Moyen')
cy.fill('Base du moyen', 'Saint-Malo')
cy.fill('Commentaire', 'Un autre commentaire sur le moyen.')

cy.clickButton('Enregistrer les modifications')

cy.wait('@updateControlUnitResource').then(interception => {
if (!interception.response) {
assert.fail('`interception.response` is undefined.')
}

assert.deepInclude(interception.request.body, {
baseId: 2,
id: 13,
name: 'Super Moyen',
note: 'Un autre commentaire sur le moyen.',
type: 'SUPPORT_SHIP'
})
})

cy.get('p').contains('Éditer un moyen').should('not.exist')
cy.contains('Enregistrer les modifications').should('not.exist')
cy.contains('Bâtiment de soutien – Super Moyen').should('be.visible')

// -------------------------------------------------------------------------
// Delete

cy.intercept('DELETE', `/api/v1/control_unit_resources/13`).as('deleteControlUnitResource')

cy.getDataCy('ControlUnitDialog-control-unit-resource').filter('[data-id="13"]').clickButton('Éditer ce moyen')
cy.clickButton('Supprimer ce moyen')
cy.clickButton('Supprimer')

cy.wait('@deleteControlUnitResource')

cy.contains('Bâtiment de soutien – Super Moyen').should('not.exist')
})
})
8 changes: 8 additions & 0 deletions frontend/cypress/e2e/main_window/control_unit_dialog/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { goToMainWindow } from '../utils'

export function gotToMainWindowAndOpenControlUnit(controlUnitId: number) {
goToMainWindow()

cy.clickButton('Liste des unités de contrôle')
cy.getDataCy('ControlUnitListDialog-control-unit').filter(`[data-id="${controlUnitId}"]`).forceClick().wait(250)
}
50 changes: 0 additions & 50 deletions frontend/cypress/e2e/main_window/control_unit_list/filters.spec.ts

This file was deleted.

Loading

0 comments on commit bbda84f

Please sign in to comment.