Skip to content

Commit

Permalink
Merge pull request #633 from Opetushallitus/feature/OPHYKIKEH-246
Browse files Browse the repository at this point in the history
YKI(Frontend): OPHYKIKEH-246 Tutkintoon ilmoittautumisen testejä
  • Loading branch information
pkoivisto authored Mar 1, 2024
2 parents 7647de1 + e7378e9 commit b70e2b7
Show file tree
Hide file tree
Showing 27 changed files with 3,434 additions and 60 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/akr/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:4000',
video: false,
defaultCommandTimeout: 15000,
defaultCommandTimeout: 3000,
chromeWebSecurity: false,
retries: 1,
fixturesFolder: './src/tests/cypress/fixtures/json',
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/otr/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:4001',
video: false,
defaultCommandTimeout: 15000,
defaultCommandTimeout: 3000,
chromeWebSecurity: false,
retries: 1,
fixturesFolder: './src/tests/cypress/fixtures/json',
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/vkt/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:4002',
video: false,
defaultCommandTimeout: 15000,
defaultCommandTimeout: 3000,
chromeWebSecurity: false,
retries: 1,
fixturesFolder: './src/tests/cypress/fixtures/json',
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/yki/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
e2e: {
baseUrl: 'http://localhost:4003',
video: false,
defaultCommandTimeout: 15000,
defaultCommandTimeout: 3000,
chromeWebSecurity: false,
retries: 1,
fixturesFolder: './src/tests/cypress/fixtures/json',
Expand Down
13 changes: 13 additions & 0 deletions frontend/packages/yki/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,19 @@ module.exports = function (app) {
useLocalProxy ? proxyGetCall(req, res) : mockCall();
});

app.get('/yki/auth/logout', (req, res) => {
const mockCall = () => {
try {
const { redirect } = req.query;
res.redirect(redirect);
} catch (err) {
printError(req, err);
res.status(404).send(err.message);
}
};
useLocalProxy ? proxyGetCall(req, res) : mockCall();
})

app.delete('/yki/api/registration/:id', (req, res) => {
const mockCall = () => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ export const CommonRegistrationDetails = () => {

return (
<>
<div>
<Text>
<b>{t('certificateLanguage')}</b>
</Text>
<fieldset className="registration-details__radio-group">
<legend>
<Text>
<b>{t('certificateLanguage')}</b>
</Text>
</legend>
<FormControl error={!!registrationErrors['certificateLanguage']}>
<RadioGroup
row={!isPhone}
Expand Down Expand Up @@ -114,12 +116,14 @@ export const CommonRegistrationDetails = () => {
/>
</RadioGroup>
</FormControl>
</div>
</fieldset>
{hideInstructionLanguageSelection ? null : (
<div>
<Text>
<b>{t('instructionLanguage')}</b>
</Text>
<fieldset className="registration-details__radio-group">
<legend>
<Text>
<b>{t('instructionLanguage')}</b>
</Text>
</legend>
<FormControl error={!!registrationErrors['instructionLanguage']}>
<RadioGroup
row={!isPhone}
Expand All @@ -141,7 +145,7 @@ export const CommonRegistrationDetails = () => {
/>
</RadioGroup>
</FormControl>
</div>
</fieldset>
)}
<H2 className="public-registration__grid__form-container__terms-and-conditions">
{t('termsAndConditions.title')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ export const EmailRegistrationDetails = () => {
/>
</div>
</div>
<div>
<Text>
<b>{t('finnishSSN')}</b>
</Text>
<fieldset className="registration-details__radio-group">
<legend>
<Text>
<b>{t('finnishSSN')}</b>
</Text>
</legend>
<FormControl error={showErrors && !!registrationErrors['hasSSN']}>
<RadioGroup
row={!isPhone}
Expand Down Expand Up @@ -248,7 +250,7 @@ export const EmailRegistrationDetails = () => {
/>
)}
</FormControl>
</div>
</fieldset>
</>
);
};
2 changes: 1 addition & 1 deletion frontend/packages/yki/src/pages/InitRegistrationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { examSessionSelector } from 'redux/selectors/examSession';
import { registrationSelector } from 'redux/selectors/registration';
import { ExamSessionUtils } from 'utils/examSession';

const ContentSelector = () => {
export const ContentSelector = () => {
const examSession = useAppSelector(examSessionSelector).examSession;
if (!examSession) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/yki/src/redux/reducers/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface RegistrationState {
showErrors: boolean;
}

const initialState: RegistrationState = {
export const initialState: RegistrationState = {
activeStep: PublicRegistrationFormStep.Identify,
initRegistration: {
status: APIResponseStatus.NotStarted,
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/yki/src/redux/reducers/reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const reservationSlice = createSlice({
},
rejectReservationRequest(
state,
action: PayloadAction<ReservationErrorCause>
action: PayloadAction<ReservationErrorCause>,
) {
state.status = APIResponseStatus.Error;
state.errorCause = action.payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
display: grid;
grid-template-columns: 1fr 1fr;
}

&__radio-group {
border: 0;
padding: 0;
}
}

.radio-group-label {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { APIEndpoints } from 'enums/api';
import { onExamDetailsPage } from 'tests/cypress/support/page-objects/examDetailsPage';
import { examSessions } from 'tests/msw/fixtures/examSession';

const examSessionResponse = examSessions.exam_sessions.find(
(es) => es.id === 999,
);

const expectedSuomiFiRegistrationDetails = {
first_name: 'Teuvo',
last_name: 'Testitapaus',
ssn: '030594W903B',
post_office: 'Helsinki',
zip: '00100',
street_address: 'Unioninkatu 1',
};

const getInitRegistrationResponse = (is_strongly_identified: boolean) => {
if (is_strongly_identified) {
const { first_name, last_name, ssn, post_office, zip, street_address } =
expectedSuomiFiRegistrationDetails;

return {
is_strongly_identified,
exam_session: examSessionResponse,
registration_id: 1337,
user: {
first_name,
last_name,
ssn,
post_office,
zip,
street_address,
},
};
} else {
return {
is_strongly_identified,
exam_session: examSessionResponse,
registration_id: 1337,
user: {
email: '[email protected]',
},
};
}
};

const handleRedirect = () => {
// When browser attempts to logout, send browser instead directly to
// successful submission page.
// Note that mocking the response with msw doesn't currently work,
// as the request to logout is sent to an absolute URL (including hostname).
cy.intercept(
{ url: /^.*\/yki\/auth\/logout\?redirect=/, method: 'GET' },
(req) => {
const { redirect } = req.query;
req.continue((res) => {
res.send(301, {}, { location: redirect as string });
});
},
);
};

describe('ExamDetailsPage', () => {
describe('allows filling registration form', () => {
it('with credentials from Suomi.fi authentication', () => {
cy.openExamSessionRegistrationForm(examSessionResponse.id);
cy.intercept('POST', APIEndpoints.InitRegistration, {
statusCode: 200,
body: getInitRegistrationResponse(true),
}).as('initRegistration');
cy.wait('@initRegistration');
onExamDetailsPage.isVisible();
onExamDetailsPage.fillFieldByLabel(
'Sähköpostiosoite *',
'[email protected]',
);
onExamDetailsPage.fillFieldByLabel(
'Vahvista sähköpostiosoite *',
'[email protected]',
);
onExamDetailsPage.fillFieldByLabel('Puhelinnumero *', '+358501234567');
onExamDetailsPage.selectNationality('Serbia');
onExamDetailsPage.selectCertificateLanguage('englanti');

onExamDetailsPage.acceptTermsOfRegistration();
onExamDetailsPage.acceptPrivacyPolicy();

handleRedirect();

onExamDetailsPage.submitForm();
onExamDetailsPage.isFormSubmitted();
});

it('by authenticating via a login link', () => {
cy.openExamSessionRegistrationForm(examSessionResponse.id);
cy.intercept('POST', APIEndpoints.InitRegistration, {
statusCode: 200,
body: getInitRegistrationResponse(false),
}).as('initRegistration');
cy.wait('@initRegistration');
onExamDetailsPage.isVisible();

const { first_name, last_name, street_address, zip, post_office, ssn } = expectedSuomiFiRegistrationDetails;

onExamDetailsPage.fillFieldByLabel('Etunimet *', first_name);
onExamDetailsPage.fillFieldByLabel('Sukunimi *', last_name);

onExamDetailsPage.fillFieldByLabel('Katuosoite *', street_address);
onExamDetailsPage.fillFieldByLabel('Postinumero *', zip);
onExamDetailsPage.fillFieldByLabel('Postitoimipaikka *', post_office);

onExamDetailsPage.selectGender('Mies');
onExamDetailsPage.selectNationality('Serbia');

onExamDetailsPage.fillFieldByLabel('Puhelinnumero *', '+358501234567');

onExamDetailsPage.selectHasSSN(true);
onExamDetailsPage.fillFieldByLabel('Henkilötunnus *', ssn);
onExamDetailsPage.selectCertificateLanguage('englanti');

onExamDetailsPage.acceptTermsOfRegistration();
onExamDetailsPage.acceptPrivacyPolicy();

handleRedirect();

onExamDetailsPage.submitForm();
onExamDetailsPage.isFormSubmitted();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { onInitRegistrationPage } from 'tests/cypress/support/page-objects/initRegistrationPage';
import { onPublicRegistrationPage } from 'tests/cypress/support/page-objects/publicRegistrationPage';
import { findDialogByText } from 'tests/cypress/support/utils/dialog';

Expand Down Expand Up @@ -49,4 +50,35 @@ describe('PublicRegistrationPage', () => {
onPublicRegistrationPage.expectResultRowsCount(3);
});
});

describe('allows starting the exam registration process', () => {
it('by selecting an identification method', () => {
onPublicRegistrationPage.selectExamLanguage('kaikki kielet');
onPublicRegistrationPage.selectExamLevel('kaikki tasot');
onPublicRegistrationPage.toggleShowOnlyIfAvailablePlaces();
onPublicRegistrationPage.toggleShowOnlyIfOngoingAdmission();
onPublicRegistrationPage.showResults();

onPublicRegistrationPage
.getResultRows()
.findByRole('button', { name: /Ilmoittaudu/ })
.click();

onInitRegistrationPage.expectTitle('Tunnistaudu ilmoittautumista varten');
});

it('or by subscribing to notifications of available seats', () => {
onPublicRegistrationPage.selectExamLanguage('suomi');
onPublicRegistrationPage.selectExamLevel('perustaso');
onPublicRegistrationPage.toggleShowOnlyIfOngoingAdmission();
onPublicRegistrationPage.showResults();

onPublicRegistrationPage
.getResultRows()
.findByRole('button', { name: /Tilaa ilmoitus peruutuspaikoista/ })
.click();

onInitRegistrationPage.expectTitle('Tilaa ilmoitus peruutuspaikoista');
});
});
});
6 changes: 6 additions & 0 deletions frontend/packages/yki/src/tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Cypress.Commands.add('openEvaluationOrderPage', (id: number) => {
Cypress.Commands.add('isOnPage', (page: string) => {
cy.url().should('include', page);
});

Cypress.Commands.add('openExamSessionRegistrationForm', (id: number) => {
cy.visit(
AppRoutes.ExamSessionRegistration.replace(/:examSessionId/, `${id}`),
);
});
Loading

0 comments on commit b70e2b7

Please sign in to comment.