Skip to content

Commit

Permalink
Merge pull request #565 from solita/feature/AE-2317-add-ui-representa…
Browse files Browse the repository at this point in the history
…tion-for-new-states

Feature/ae 2317 add UI representation for new states
  • Loading branch information
solita-juhohaa authored Oct 29, 2024
2 parents d4c5a50 + 5423e84 commit d42e2b7
Show file tree
Hide file tree
Showing 95 changed files with 24,669 additions and 208 deletions.
6 changes: 4 additions & 2 deletions e2e-tests/cypress/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = defineConfig({
defaultCommandTimeout: 15000,
video: true,
e2e: {
setupNodeEvents(on, config) {},
baseUrl: 'https://localhost:3009'
backendUrl: 'http://localhost:3444',
publicUrl: 'http://localhost:5059',
baseUrl: 'https://localhost:3009',
setupNodeEvents(on, config) {}
}
});
78 changes: 13 additions & 65 deletions e2e-tests/cypress/cypress/e2e/laatija/laatija.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ context('Laatija', () => {
it('should navigate to energiatodistus', () => {
cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-row"]').first().click();
cy.get('[data-cy="energiatodistus-id"]').contains('5').click();

cy.location().should(loc =>
assert.equal(loc.toString(), `${baseUrl}/#/energiatodistus/2018/5`)
Expand Down Expand Up @@ -55,82 +55,30 @@ context('Laatija', () => {
it('should delete energiatodistus from energiatodistus page', () => {
cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-row"]').first().click();

cy.intercept(
{
method: 'DELETE',
pathname: /\/api\/private\/energiatodistukset\/2018\/5$/
},
{ statusCode: 200 }
).as('deleteEnergiatodistus');

cy.intercept(
{
method: 'GET',
pathname: /\/api\/private\/energiatodistukset$/
},
req =>
req.reply(FIXTURES.energiatodistukset.filter(item => item.id !== 5))
).as('energiatodistukset');

cy.intercept(
{
method: 'GET',
pathname: /\/api\/private\/energiatodistukset\/count$/
},
{ statusCode: 200, body: { count: 4 } }
).as('count');
cy.get('[data-cy="energiatodistus-id"]').contains('5').click();

cy.contains('Poista').click();
cy.get('[data-cy="confirm-submit-button"]').click();

cy.wait('@deleteEnergiatodistus');
cy.wait('@energiatodistukset');
cy.wait('@count');
cy.get('[data-cy="confirm-submit-button"]').click();

cy.get('[data-cy="energiatodistus-row"]').should('have.length', 4);
cy.get('[data-cy="energiatodistus-id"]')
.contains('5')
.should('not.exist');
});

it('should delete energiatodistus from energiatodistukset page', () => {
cy.visit('/#/energiatodistus/all');

cy.intercept(
{
method: 'DELETE',
pathname: /\/api\/private\/energiatodistukset\/2018\/5$/
},
{ statusCode: 200 }
).as('deleteEnergiatodistus');

cy.get(
'[data-cy="energiatodistus-row"]:first-child td:last-child span'
).click();

cy.intercept(
{
method: 'GET',
pathname: /\/api\/private\/energiatodistukset$/
},
req =>
req.reply(FIXTURES.energiatodistukset.filter(item => item.id !== 5))
).as('energiatodistukset');

cy.intercept(
{
method: 'GET',
pathname: /\/api\/private\/energiatodistukset\/count$/
},
{ statusCode: 200, body: { count: 4 } }
).as('count');
cy.get('[data-cy="energiatodistus-id"]')
.contains('5')
.siblings('[data-cy="energiatodistus-delete"]')
.click();

cy.get('[data-cy="confirm-submit-button"]').click();

cy.wait('@deleteEnergiatodistus');
cy.wait('@energiatodistukset');
cy.wait('@count');

cy.get('[data-cy="energiatodistus-row"]').should('have.length', 4);
cy.get('[data-cy="energiatodistus-id"]')
.contains('5')
.should('not.exist');
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import { FIXTURES } from '../../fixtures/laatija';
import paakayttajaHeaders from '../../fixtures/users/paakayttaja.json';

const publicUrl = Cypress.config('publicUrl');
const backendUrl = Cypress.config('backendUrl');

const expiredEtWithValvontaId = 7;
const expiredEtWithoutValvontaId = 6;
const signedEtThatWillNotBeTouched1 = 1;
const signedEtThatWillNotBeTouchedId2 = 4;

const runExpirationOfTodistukset = () => {
cy.request(
'POST',
`${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired`
).then(response => {
expect(response.status).to.eq(200);
});
// There is no way to know when running the expiration is finished.
cy.wait(1000);
};

context('Laatija', () => {
beforeEach(() => {
cy.resetDb();
cy.intercept(/\/api\/private/, req => {
req.headers = { ...req.headers, ...FIXTURES.headers };
});
});

describe('when destroying expired energiatodistukset', () => {
it('should show energiatodistukset before the expiration is run', () => {
cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouched1)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouchedId2)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithoutValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');
});

it('Should only see non-expired and expired with ongoing valvonta energiatodistukset after running expiration', () => {
cy.request(
'POST',
`${backendUrl}/api/internal/energiatodistukset/anonymize-and-delete-expired`
).then(response => {
expect(response.status).to.eq(200);
});

// There is no way to know when running the expiration is finished.
cy.wait(1000);

cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouchedId2)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouched1)
.should('exist');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithoutValvontaId)
.should('not.exist');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Vanhentunut');

cy.visit(`/#/energiatodistus/2018/${expiredEtWithValvontaId}`);
cy.contains('Energiatodistus 2018/7 - Vanhentunut').should('exist');

cy.visit(`/#/energiatodistus/2018/${expiredEtWithoutValvontaId}`);
cy.contains('Puutteelliset käyttöoikeudet').should('exist');
});
});
});

context('Paakayttaja', () => {
beforeEach(() => {
cy.resetDb();
cy.intercept(/\/api\/private/, req => {
req.headers = { ...req.headers, ...paakayttajaHeaders };
});
});

describe('when destroying expired energiatodistukset', () => {
it('should see all the Voimassa energiatodistukset before running the expiration', () => {
cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouched1)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains('4')
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithoutValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');
});
it('should see 1 and 6 as tuhottu, 4 as voimassa and 7 as vahentunut after running the expiration', () => {
runExpirationOfTodistukset();
cy.visit('/#/energiatodistus/all');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouched1)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(signedEtThatWillNotBeTouchedId2)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Voimassa');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithoutValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Tuhottu');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithValvontaId)
.siblings('[data-cy="energiatodistus-tila"]')
.should('have.text', 'Vanhentunut');

cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithoutValvontaId)
.click();
cy.contains('Puutteelliset käyttöoikeudet').should('exist');

cy.visit('/#/energiatodistus/all');
cy.get('[data-cy="energiatodistus-id"]')
.contains(expiredEtWithValvontaId)
.click();
cy.contains('Energiatodistus 2018/7 - Vanhentunut').should('exist');
});
});
});

context('Public', () => {
beforeEach(() => {
cy.resetDb();
});

describe('when destroying expired energiatodistukset', () => {
it('should see all the Voimassa energiatodistukset before running the expiration', () => {
cy.visit(`${publicUrl}/ethaku`);

cy.get('[data-cy="ethaku-hae"]').click();

// Notice that these are the type that are seen by the public
cy.get('[data-cy="ethaku-tunnus"]')
.contains(expiredEtWithValvontaId)
.should('exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(expiredEtWithoutValvontaId)
.should('exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(signedEtThatWillNotBeTouchedId2)
.should('exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(signedEtThatWillNotBeTouched1)
.should('exist');
});
it('should only see the non-expired todistukset after running the expiration.', () => {
runExpirationOfTodistukset();
cy.visit(`${publicUrl}/ethaku`);

cy.get('[data-cy="ethaku-hae"]').click();

// Notice that these are the type that are seen by the public
cy.get('[data-cy="ethaku-tunnus"]')
.contains(expiredEtWithValvontaId)
.should('not.exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(expiredEtWithoutValvontaId)
.should('not.exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(signedEtThatWillNotBeTouchedId2)
.should('exist');

cy.get('[data-cy="ethaku-tunnus"]')
.contains(signedEtThatWillNotBeTouched1)
.should('exist');

cy.visit(
`${publicUrl}/energiatodistus?id=${expiredEtWithValvontaId}&versio=2018`
);
cy.contains('Energiatodistusta ei löytynyt').should('exist');

cy.visit(
`${publicUrl}/energiatodistus?id=${expiredEtWithoutValvontaId}&versio=2018`
);
cy.contains('Energiatodistusta ei löytynyt').should('exist');

cy.visit(
`${publicUrl}/energiatodistus?id=${signedEtThatWillNotBeTouched1}&versio=2013`
);
// This is a piece of the todistus' notes.
cy.contains('Seuraavia toimenpiteitä voisi tehdä:').should('exist');
});
});
});
Loading

0 comments on commit d42e2b7

Please sign in to comment.