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

upcoming: [M3-7696] - Edit Access key Drawer - Fix Save button is disabled #10118

Merged
merged 15 commits into from
Feb 7, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR - feedback - @DevDW
  • Loading branch information
cpathipa committed Feb 6, 2024
commit 93ac242a2f32ae99ed8df25406d87f603e259235
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ export const OMC_AccessKeyDrawer = (props: AccessKeyDrawerProps) => {

const updatePayload = generateUpdatePayload(values, initialValues);

if (mode !== 'creating' && Object.keys(updatePayload).length > 0) {
if (mode !== 'creating') {
onSubmit(updatePayload, formik);
} else {
onSubmit(payload, formik);
cpathipa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -10,26 +10,26 @@ describe('generateUpdatePayload', () => {
regions: ['region1', 'region2'],
};

test('should return empty object if no changes', () => {
it('should return empty object if no changes', () => {
const updatedValues = { ...initialValues };
expect(generateUpdatePayload(updatedValues, initialValues)).toEqual({});
});

test('should return updated label if only label changed', () => {
it('should return updated label if only label changed', () => {
const updatedValues = { ...initialValues, label: 'newLabel' };
expect(generateUpdatePayload(updatedValues, initialValues)).toEqual({
label: 'newLabel',
});
});

test('should return updated regions if only regions changed', () => {
it('should return updated regions if only regions changed', () => {
const updatedValues = { ...initialValues, regions: ['region3', 'region4'] };
expect(generateUpdatePayload(updatedValues, initialValues)).toEqual({
regions: ['region3', 'region4'],
});
});

test('should return updated label and regions if both changed', () => {
it('should return updated label and regions if both changed', () => {
const updatedValues = {
bucket_access: [],
label: 'newLabel',
@@ -62,11 +62,11 @@ describe('hasLabelOrRegionsChanged', () => {
secret_key: '',
};

test('returns false when both label and regions are unchanged', () => {
it('returns false when both label and regions are unchanged', () => {
expect(hasLabelOrRegionsChanged(updatedValues, initialValues)).toBe(false);
});

test('returns true when only the label has changed', () => {
it('returns true when only the label has changed', () => {
expect(
hasLabelOrRegionsChanged(
{ ...updatedValues, label: 'newLabel' },
@@ -75,7 +75,7 @@ describe('hasLabelOrRegionsChanged', () => {
).toBe(true);
});

test('returns true when only the regions have changed', () => {
it('returns true when only the regions have changed', () => {
expect(
hasLabelOrRegionsChanged(
{
@@ -87,7 +87,7 @@ describe('hasLabelOrRegionsChanged', () => {
).toBe(true);
});

test('returns true when both label and regions have changed', () => {
it('returns true when both label and regions have changed', () => {
expect(
hasLabelOrRegionsChanged(
{ ...updatedValues, label: 'newLabel', regions: ['region5'] },
10 changes: 6 additions & 4 deletions packages/validation/src/objectStorageKeys.schema.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { object, string, array } from 'yup';

const labelErrorMessage = 'Label must be between 3 and 50 characters.';

export const createObjectStorageKeysSchema = object({
label: string()
.required('Label is required.')
.min(3, 'Label must be between 3 and 50 characters.')
.max(50, 'Label must be between 3 and 50 characters.')
.min(3, labelErrorMessage)
.max(50, labelErrorMessage)
.trim(),
regions: array()
.of(string())
@@ -15,8 +17,8 @@ export const createObjectStorageKeysSchema = object({
export const updateObjectStorageKeysSchema = object({
label: string()
.notRequired()
.min(3, 'Label must be between 3 and 50 characters.')
.max(50, 'Label must be between 3 and 50 characters.')
.min(3, labelErrorMessage)
.max(50, labelErrorMessage)
.trim(),
regions: array()
.of(string())