Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verified ability to save a 'Last name' containing allowed special characters #2929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/unit/containers/edit-profile/ProfileTab.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ vi.mock(
required
value={data.firstName}
/>
<input
onBlur={handleBlur('lastName')}
onChange={handleInputChange('lastName')}
placeholder={'lastName'}
required
value={data.lastName}
/>
</div>
)
})
Expand Down Expand Up @@ -155,4 +162,18 @@ describe('ProfileTab', () => {
expect(firstNameInput).toBeInTheDocument()
expect(firstNameInput).toHaveFocus()
})

it('should place cursor in the "Last name" field when clicked', async () => {
renderWithMockData();

const lastNameInput = screen.getByPlaceholderText('lastName');
expect(lastNameInput).toBeInTheDocument();
expect(document.activeElement).not.toBe(lastNameInput);

await userEvent.click(lastNameInput);

expect(document.activeElement).toBe(lastNameInput);
expect(lastNameInput).toHaveFocus()
});

})
37 changes: 37 additions & 0 deletions tests/unit/pages/edit-profile/EditProfile.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ const userMock = {

const mockData = {
firstName: '',
lastName: '',
photo: null,
videoLink: '',
errors: {
firstName: '',
lastName: '',
videoLink: '',
},
};
Expand Down Expand Up @@ -473,4 +475,39 @@ describe('EditProfile', () => {
expect(updateButton).not.toBeDisabled();
}
});

it('should replace the existing text in the "Last name" field with test data and Update button becomes anable and active', () => {
const testData = ["Mc'Neil", "O'Neill-Johnson", "Van Gogh"];

const mockT = vi.fn((key) => {
const translations = {
'common.labels.lastName': 'Last Name',
'editProfilePage.updateBtn': 'Update',
};
return translations[key] || key;
});

const mockHandleInputChange = vi.fn();

render(
<ProfileTabForm
t={mockT}
data={mockData}
errors={mockData.errors}
handleInputChange={mockHandleInputChange}
handleBlur={() => {}}
openAlert={() => {}}
/>
);

const lastNameInput = screen.getByLabelText(/common.labels.lastName/i)
expect(lastNameInput).toBeInTheDocument();

for (const data of testData) {
fireEvent.change(lastNameInput, { target: { value: data } });

const updateButton = screen.getByText('editProfilePage.updateBtn')
expect(updateButton).not.toBeDisabled();
}
});
});
42 changes: 30 additions & 12 deletions tests/unit/utils/common.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ const mockedValues = {
longText: 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwww',
emptyField: '',
spaceField: ' ',
nameWithApostropheEn: "O'braian",
nameWithApostropheUa: "Мар'яна",
nameWithHyphen: "Анна-Марія",
nameWithSpace: "Анна Марія",
firstNameWithApostropheEn: "O'braian",
firstNameWithApostropheUa: "Мар'яна",
firstNameWithHyphen: "Анна-Марія",
firstNameWithSpace: "Анна Марія",
lastNameWithApostrophe: "Mc'Neil",
lastNameWithApostropheAndHyphen: "O'Neill-Johnson",
lastNameWithSpace: "Van Gogh",
}

const errorMessages = {
Expand Down Expand Up @@ -51,23 +54,38 @@ export const passwordField = (value) => {
}

describe('commonValidation', () => {
it('Should accept name in English with apostrophe', () => {
const result = nameField(mockedValues.nameWithApostropheEn)
it('Should accept firstName in English with apostrophe', () => {
const result = nameField(mockedValues.firstNameWithApostropheEn)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept name in Ukrainian with apostrophe', () => {
const result = nameField(mockedValues.nameWithApostropheUa)
it('Should accept firstName in Ukrainian with apostrophe', () => {
const result = nameField(mockedValues.firstNameWithApostropheUa)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept name with space', () => {
const result = nameField(mockedValues.nameWithSpace)
it('Should accept firstName with space', () => {
const result = nameField(mockedValues.firstNameWithSpace)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept name with hyphen', () => {
const result = nameField(mockedValues.nameWithHyphen)
it('Should accept firstName with hyphen', () => {
const result = nameField(mockedValues.firstNameWithHyphen)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept lastName with apostrophe', () => {
const result = nameField(mockedValues.lastNameWithApostrophe)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept lastName with apostrophe and hyphen', () => {
const result = nameField(mockedValues.lastNameWithApostropheAndHyphen)
expect(result).not.toBe(errorMessages.nameCharacters)
})

it('Should accept lastName with space', () => {
const result = nameField(mockedValues.lastNameWithSpace)
expect(result).not.toBe(errorMessages.nameCharacters)
})

Expand Down
Loading