mirror of https://github.com/portainer/portainer
				
				
				
			chore(gitops): upgrade parse-duration dep [r8s-608] (#1328)
							parent
							
								
									e5f98e6145
								
							
						
					
					
						commit
						cb0efae81c
					
				| 
						 | 
				
			
			@ -1,26 +0,0 @@
 | 
			
		|||
import angular from 'angular';
 | 
			
		||||
import parse from 'parse-duration';
 | 
			
		||||
 | 
			
		||||
angular.module('portainer.app').directive('intervalFormat', function () {
 | 
			
		||||
  return {
 | 
			
		||||
    restrict: 'A',
 | 
			
		||||
    require: 'ngModel',
 | 
			
		||||
    link: function ($scope, $element, $attrs, ngModel) {
 | 
			
		||||
      ngModel.$validators.invalidIntervalFormat = function (modelValue) {
 | 
			
		||||
        try {
 | 
			
		||||
          return modelValue && modelValue.toUpperCase().match(/^P?(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T?(?=\d+[HMS])(\d+H)?(\d+M)?(\d+S)?)?$/gm) !== null;
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      ngModel.$validators.minimumInterval = function (modelValue) {
 | 
			
		||||
        try {
 | 
			
		||||
          return modelValue && parse(modelValue, 'minute') >= 1;
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
      };
 | 
			
		||||
    },
 | 
			
		||||
  };
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
import { describe, it, expect } from 'vitest';
 | 
			
		||||
 | 
			
		||||
import { intervalValidation } from './IntervalField';
 | 
			
		||||
 | 
			
		||||
describe('intervalValidation', () => {
 | 
			
		||||
  it('rejects empty value with required message', async () => {
 | 
			
		||||
    const schema = intervalValidation();
 | 
			
		||||
    await expect(schema.validate('')).rejects.toThrow(
 | 
			
		||||
      'This field is required.'
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('accepts simple minute values', async () => {
 | 
			
		||||
    const schema = intervalValidation();
 | 
			
		||||
    await expect(schema.validate('1m')).resolves.toBe('1m');
 | 
			
		||||
    await expect(schema.validate('5m')).resolves.toBe('5m');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('accepts complex duration values', async () => {
 | 
			
		||||
    const schema = intervalValidation();
 | 
			
		||||
    await expect(schema.validate('6h40m')).resolves.toBe('6h40m');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('accepts seconds >= 60s (treated as >= 1 minute)', async () => {
 | 
			
		||||
    const schema = intervalValidation();
 | 
			
		||||
    await expect(schema.validate('90s')).resolves.toBe('90s');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('rejects sub-minute durations and invalid formats with minimum-interval message', async () => {
 | 
			
		||||
    const schema = intervalValidation();
 | 
			
		||||
    await expect(schema.validate('30s')).rejects.toThrow(
 | 
			
		||||
      'Minimum interval is 1m'
 | 
			
		||||
    );
 | 
			
		||||
    await expect(schema.validate('abc')).rejects.toThrow(
 | 
			
		||||
      'Minimum interval is 1m'
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -52,10 +52,12 @@ export function intervalValidation() {
 | 
			
		|||
      //   /[-+]?([0-9]*(\.[0-9]*)?[a-z]+)+/g,
 | 
			
		||||
      //   'Please enter a valid time interval.'
 | 
			
		||||
      // )
 | 
			
		||||
      .test(
 | 
			
		||||
        'minimumInterval',
 | 
			
		||||
        'Minimum interval is 1m',
 | 
			
		||||
        (value) => !!value && parse(value, 'minute') >= 1
 | 
			
		||||
      )
 | 
			
		||||
      .test('minimumInterval', 'Minimum interval is 1m', (value) => {
 | 
			
		||||
        if (!value) {
 | 
			
		||||
          return false;
 | 
			
		||||
        }
 | 
			
		||||
        const minutes = parse(value, 'minute');
 | 
			
		||||
        return minutes !== null && minutes >= 1;
 | 
			
		||||
      })
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,8 @@
 | 
			
		|||
    "storybook": "storybook dev -p 6006",
 | 
			
		||||
    "storybook:build": "storybook build -o ./dist/storybook",
 | 
			
		||||
    "analyze-webpack": "webpack --config ./webpack/webpack.analyze.js",
 | 
			
		||||
    "prepare": "cd ../.. && husky install package/server-ce/.husky && husky install .husky" },
 | 
			
		||||
    "prepare": "cd ../.. && husky install package/server-ce/.husky && husky install .husky"
 | 
			
		||||
  },
 | 
			
		||||
  "engines": {
 | 
			
		||||
    "node": ">= 16"
 | 
			
		||||
  },
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +113,7 @@
 | 
			
		|||
    "moment-timezone": "^0.5.40",
 | 
			
		||||
    "mustache": "^4.2.0",
 | 
			
		||||
    "ng-file-upload": "~12.2.13",
 | 
			
		||||
    "parse-duration": "^1.0.2",
 | 
			
		||||
    "parse-duration": "^2.1.4",
 | 
			
		||||
    "qs": "^6.14.0",
 | 
			
		||||
    "rc-slider": "^10.0.0",
 | 
			
		||||
    "react": "^17.0.2",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14439,10 +14439,10 @@ parent-module@^1.0.0:
 | 
			
		|||
  dependencies:
 | 
			
		||||
    callsites "^3.0.0"
 | 
			
		||||
 | 
			
		||||
parse-duration@^1.0.2:
 | 
			
		||||
  version "1.0.2"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-1.0.2.tgz#b9aa7d3a1363cc7e8845bea8fd3baf8a11df5805"
 | 
			
		||||
  integrity sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg==
 | 
			
		||||
parse-duration@^2.1.4:
 | 
			
		||||
  version "2.1.4"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-2.1.4.tgz#02918736726f657eaf70b52bb8da7910316df51d"
 | 
			
		||||
  integrity sha512-b98m6MsCh+akxfyoz9w9dt0AlH2dfYLOBss5SdDsr9pkhKNvkWBXU/r8A4ahmIGByBOLV2+4YwfCuFxbDDaGyg==
 | 
			
		||||
 | 
			
		||||
parse-filepath@^1.0.2:
 | 
			
		||||
  version "1.0.2"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue