Skip to content

Commit

Permalink
Retains support for Infinity and adds a dev note on what using the va…
Browse files Browse the repository at this point in the history
…lue does
  • Loading branch information
TinaHeiligers committed Apr 19, 2021
1 parent 5aa86e3 commit 3e614a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
80 changes: 44 additions & 36 deletions src/core/server/ui_settings/settings/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ describe('notifications settings', () => {

it('should only accept positive numeric values or `Infinity`', () => {
expect(() => validate(42)).not.toThrow();
expect(() => validate('Infinity')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(
`"Value must be equal to or greater than [0]."`
);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate('Infinity')).not.toThrow();
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: Value must be equal to or greater than [0].
- [1]: expected value to equal [Infinity]"
`);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: expected value of type [number] but got [string]
- [1]: expected value to equal [Infinity]"
`);
});
});

Expand All @@ -51,15 +53,17 @@ describe('notifications settings', () => {

it('should only accept positive numeric values or `Infinity`', () => {
expect(() => validate(42)).not.toThrow();
expect(() => validate('Infinity')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(
`"Value must be equal to or greater than [0]."`
);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate('Infinity')).not.toThrow();
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: Value must be equal to or greater than [0].
- [1]: expected value to equal [Infinity]"
`);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: expected value of type [number] but got [string]
- [1]: expected value to equal [Infinity]"
`);
});
});

Expand All @@ -68,15 +72,17 @@ describe('notifications settings', () => {

it('should only accept positive numeric values or `Infinity`', () => {
expect(() => validate(42)).not.toThrow();
expect(() => validate('Infinity')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(
`"Value must be equal to or greater than [0]."`
);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate('Infinity')).not.toThrow();
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: Value must be equal to or greater than [0].
- [1]: expected value to equal [Infinity]"
`);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: expected value of type [number] but got [string]
- [1]: expected value to equal [Infinity]"
`);
});
});

Expand All @@ -85,15 +91,17 @@ describe('notifications settings', () => {

it('should only accept positive numeric values or `Infinity`', () => {
expect(() => validate(42)).not.toThrow();
expect(() => validate('Infinity')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(
`"Value must be equal to or greater than [0]."`
);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [number] but got [string]"`
);
expect(() => validate('Infinity')).not.toThrow();
expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: Value must be equal to or greater than [0].
- [1]: expected value to equal [Infinity]"
`);
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(`
"types that failed validation:
- [0]: expected value of type [number] but got [string]
- [1]: expected value to equal [Infinity]"
`);
});
});
});
8 changes: 4 additions & 4 deletions src/core/server/ui_settings/settings/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const getNotificationsSettings = (): Record<string, UiSettingsParams> =>
}),
type: 'number',
category: ['notifications'],
schema: schema.number({ min: 0 }),
schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), // Setting to 'Infinity' will disable the countdown.
},
'notifications:lifetime:error': {
name: i18n.translate('core.ui_settings.params.notifications.errorLifetimeTitle', {
Expand All @@ -62,7 +62,7 @@ export const getNotificationsSettings = (): Record<string, UiSettingsParams> =>
}),
type: 'number',
category: ['notifications'],
schema: schema.number({ min: 0 }),
schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), // Setting to 'Infinity' will disable
},
'notifications:lifetime:warning': {
name: i18n.translate('core.ui_settings.params.notifications.warningLifetimeTitle', {
Expand All @@ -75,7 +75,7 @@ export const getNotificationsSettings = (): Record<string, UiSettingsParams> =>
}),
type: 'number',
category: ['notifications'],
schema: schema.number({ min: 0 }),
schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), // Setting to 'Infinity' will disable
},
'notifications:lifetime:info': {
name: i18n.translate('core.ui_settings.params.notifications.infoLifetimeTitle', {
Expand All @@ -88,7 +88,7 @@ export const getNotificationsSettings = (): Record<string, UiSettingsParams> =>
}),
type: 'number',
category: ['notifications'],
schema: schema.number({ min: 0 }),
schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), // Setting to 'Infinity' will disable
},
};
};

0 comments on commit 3e614a7

Please sign in to comment.