Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Nov 12, 2024
1 parent f463a2b commit 8cd3d73
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 52 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/homePage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { formatDistanceToNow } from 'date-fns';
import { StatusCodes } from 'http-status-codes';

import { getLocalForDateFns } from '../../src/components/langs';
import i18n from '../../src/config/i18n';
import { ACCOUNT_HOME_PATH } from '../../src/config/paths';
import {
AVATAR_UPLOAD_ICON_ID,
Expand Down Expand Up @@ -139,9 +138,10 @@ describe('Check member info', () => {
'contain',
MEMBER_WITH_AVATAR.name,
);
const lang = MEMBER_WITH_AVATAR.extra.lang || 'en';
// displays the correct creation date
const formattedDate = formatDistanceToNow(MEMBER_WITH_AVATAR.createdAt, {
locale: getLocalForDateFns(i18n.language),
locale: getLocalForDateFns(lang),
});
cy.get(`#${MEMBER_CREATED_AT_ID}`).should('contain', formattedDate);
});
Expand Down
58 changes: 16 additions & 42 deletions cypress/e2e/settings/password.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { FAILURE_MESSAGES, namespaces } from '@graasp/translations';

import i18n, { ACCOUNT_NAMESPACE } from '../../../src/config/i18n';
import { ACCOUNT_SETTINGS_PATH } from '../../../src/config/paths';
import {
PASSWORD_CREATE_CONTAINER_ID,
Expand All @@ -12,7 +9,6 @@ import {
PASSWORD_INPUT_NEW_PASSWORD_ID,
PASSWORD_SAVE_BUTTON_ID,
} from '../../../src/config/selectors';
import { ACCOUNT } from '../../../src/langs/constants';
import { BOB } from '../../fixtures/members';

const MOCK_CURRENT_PASSWORD = 'qwertzuiop1!D';
Expand Down Expand Up @@ -51,20 +47,14 @@ describe('Create new password', () => {
});
cy.visit(ACCOUNT_SETTINGS_PATH);
cy.wait('@getCurrentMember');

i18n.changeLanguage(BOB.extra.lang);
i18n.setDefaultNamespace(ACCOUNT_NAMESPACE);
});

it('Show configure message when no password is set', () => {
cy.get(`#${PASSWORD_DISPLAY_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_SETTINGS_INFORMATION_NEW_PASSWORD),
);
cy.get(`#${PASSWORD_EDIT_BUTTON_ID}`).should(
'contain',
i18n.t(ACCOUNT.CONFIGURE_BUTTON_LABEL),
"Add a password by clicking on the 'Configure' button",
);
cy.get(`#${PASSWORD_EDIT_BUTTON_ID}`).should('contain', 'Configure');
});

it('Show error on empty inputs', () => {
Expand All @@ -76,11 +66,11 @@ describe('Create new password', () => {
// should show input required message
cy.get(`#${PASSWORD_INPUT_NEW_PASSWORD_ID}-helper-text`).should(
'contain',
i18n.t(ACCOUNT.REQUIRED_FIELD_ERROR),
'This field is required',
);
cy.get(`#${PASSWORD_INPUT_CONFIRM_PASSWORD_ID}-helper-text`).should(
'contain',
i18n.t(ACCOUNT.REQUIRED_FIELD_ERROR),
'This field is required',
);
});

Expand All @@ -96,7 +86,7 @@ describe('Create new password', () => {
// should show weak message
cy.get(`#${PASSWORD_CREATE_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_WEAK_ERROR),
'This password is too weak, please follow the password requirements above.',
);
});

Expand All @@ -113,7 +103,7 @@ describe('Create new password', () => {
// should show not-matching new passwords
cy.get(`#${PASSWORD_CREATE_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_DO_NOT_MATCH_ERROR),
'This input does not match the new password.',
);
});

Expand Down Expand Up @@ -143,9 +133,6 @@ describe('Create new password - network error', () => {
cy.visit(ACCOUNT_SETTINGS_PATH);
cy.wait('@getCurrentMember');

i18n.changeLanguage(BOB.extra.lang);
i18n.setDefaultNamespace(ACCOUNT_NAMESPACE);

openPasswordEdition();

submitPasswordForm({
Expand All @@ -157,9 +144,7 @@ describe('Create new password - network error', () => {

cy.get(`#${PASSWORD_CREATE_CONTAINER_ID}`).should(
'contain',
i18n.t(FAILURE_MESSAGES.UNEXPECTED_ERROR, {
ns: namespaces.messages,
}),
'An unexpected error occurred',
);
});
});
Expand All @@ -172,9 +157,6 @@ describe('Update password', () => {
});
cy.visit(ACCOUNT_SETTINGS_PATH);
cy.wait('@getCurrentMember');

i18n.changeLanguage(BOB.extra.lang);
i18n.setDefaultNamespace(ACCOUNT_NAMESPACE);
});

it('Show error on empty inputs', () => {
Expand All @@ -186,27 +168,24 @@ describe('Update password', () => {
// should show input required message
cy.get(`#${PASSWORD_INPUT_NEW_PASSWORD_ID}-helper-text`).should(
'contain',
i18n.t(ACCOUNT.REQUIRED_FIELD_ERROR),
'This field is required',
);
cy.get(`#${PASSWORD_INPUT_CONFIRM_PASSWORD_ID}-helper-text`).should(
'contain',
i18n.t(ACCOUNT.REQUIRED_FIELD_ERROR),
'This field is required',
);
cy.get(`#${PASSWORD_INPUT_CURRENT_PASSWORD_ID}-helper-text`).should(
'contain',
i18n.t(ACCOUNT.REQUIRED_FIELD_ERROR),
'This field is required',
);
});

it('Show edit message when a password is set', () => {
cy.get(`#${PASSWORD_DISPLAY_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_SETTINGS_INFORMATION),
);
cy.get(`#${PASSWORD_EDIT_BUTTON_ID}`).should(
'contain',
i18n.t(ACCOUNT.EDIT_BUTTON_LABEL),
"Update your password by clicking on the 'Edit' button",
);
cy.get(`#${PASSWORD_EDIT_BUTTON_ID}`).should('contain', 'Edit');
});

it('Show error on weak new password', () => {
Expand All @@ -223,7 +202,7 @@ describe('Update password', () => {
// should show weak message
cy.get(`#${PASSWORD_EDIT_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_WEAK_ERROR),
'This password is too weak, please follow the password requirements above.',
);
});

Expand All @@ -241,7 +220,7 @@ describe('Update password', () => {
// should show not-matching new passwords
cy.get(`#${PASSWORD_EDIT_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.PASSWORD_DO_NOT_MATCH_ERROR),
'This input does not match the new password.',
);
});

Expand All @@ -259,7 +238,7 @@ describe('Update password', () => {
// should show matching current and new password
cy.get(`#${PASSWORD_EDIT_CONTAINER_ID}`).should(
'contain',
i18n.t(ACCOUNT.NEW_PASSWORD_SHOULD_NOT_MATCH_CURRENT_PASSWORD_ERROR),
'The new password should not match the current one.',
);
});

Expand Down Expand Up @@ -291,9 +270,6 @@ describe('Update password - network error', () => {
cy.visit(ACCOUNT_SETTINGS_PATH);
cy.wait('@getCurrentMember');

i18n.changeLanguage(BOB.extra.lang);
i18n.setDefaultNamespace(ACCOUNT_NAMESPACE);

openPasswordEdition();

// fill current password with mock password
Expand All @@ -307,9 +283,7 @@ describe('Update password - network error', () => {

cy.get(`#${PASSWORD_EDIT_CONTAINER_ID}`).should(
'contain',
i18n.t(FAILURE_MESSAGES.UNEXPECTED_ERROR, {
ns: namespaces.messages,
}),
'An unexpected error occurred',
);
});
});
6 changes: 1 addition & 5 deletions cypress/e2e/storage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { formatDate, formatFileSize } from '@graasp/sdk';

import i18n from '../../src/config/i18n';
import { ACCOUNT_STORAGE_PATH } from '../../src/config/paths';
import {
MEMBER_STORAGE_FILE_NAME_ID,
Expand Down Expand Up @@ -64,10 +63,7 @@ describe('Storage files', () => {
).should('contain', formatFileSize(file.size));
cy.get(
`#${getCellId(MEMBER_STORAGE_FILE_UPDATED_AT_ID, file.id)}`,
).should(
'contain',
formatDate(file.updatedAt, { locale: i18n.language }),
);
).should('contain', formatDate(file.updatedAt, { locale: 'en' }));
cy.get(
`#${getCellId(MEMBER_STORAGE_PARENT_FOLDER_ID, file.id)}`,
).should('contain', file.parent?.name ?? '-');
Expand Down
4 changes: 2 additions & 2 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"compilerOptions": {
"target": "ESNext",
"lib": ["ESNext", "dom", "ES2021.String"],
"types": ["cypress", "node", "vite/client"],
"types": ["cypress", "vite/client"],
"strictNullChecks": true,
"strict": true,
"sourceMap": false
},
"include": ["**/*.ts", "../cypress.config.ts"],
"include": ["**/*.ts"],
"exclude": ["coverage", ".nyc_output"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"prettier:write": "pnpm prettier --write 'src/**/*.{ts,tsx}'",
"check:format": "pnpm prettier --check 'src/**/*.{ts,tsx}'",
"check:type": "tsc --noEmit -p tsconfig.app.json",
"check:type-tests": "tsc --noEmit -p cypress/tsconfig.json",
"check:lint": "eslint .",
"check": "pnpm run \"/^check:.*/\"",
"hooks:install": "husky",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["vite-env.d.ts", "vite.config.ts"]
"include": ["vite-env.d.ts", "vite.config.ts", "cypress.config.ts"]
}

0 comments on commit 8cd3d73

Please sign in to comment.