diff --git a/packages/sitecore-jss/src/utils/utils.test.ts b/packages/sitecore-jss/src/utils/utils.test.ts index dff18894fe..0957791467 100644 --- a/packages/sitecore-jss/src/utils/utils.test.ts +++ b/packages/sitecore-jss/src/utils/utils.test.ts @@ -1,7 +1,7 @@ /* eslint-disable no-unused-expressions */ import { expect, spy } from 'chai'; import { isServer, resolveUrl } from '.'; -import { enforceCors, getAllowedOriginsFromEnv, isAbsoluteUrl, isTimeoutError } from './utils'; +import { enforceCors, getAllowedOriginsFromEnv, getPermutations, isAbsoluteUrl, isTimeoutError } from './utils'; import { IncomingMessage, OutgoingMessage } from 'http'; // must make TypeScript happy with `global` variable modification @@ -203,4 +203,36 @@ describe('utils', () => { delete process.env.JSS_ALLOWED_ORIGINS; }); }); + + describe('getPermutations', () => { + it('should return all permutations of an array with one pair', () => { + const input: [string, string][] = [['key1', 'value1']]; + const expectedOutput = [[['key1', 'value1']]]; + expect(getPermutations(input)).to.deep.equal(expectedOutput); + }); + + it('should return all permutations of an array with two pairs', () => { + const input: [string, string][] = [ + ['key1', 'value1'], + ['key2', 'value2'], + ]; + const expectedOutput = [ + [ + ['key1', 'value1'], + ['key2', 'value2'], + ], + [ + ['key2', 'value2'], + ['key1', 'value1'], + ], + ]; + expect(getPermutations(input)).to.deep.equal(expectedOutput); + }); + + it('should return an empty array when input is empty', () => { + const input: [string, string][] = []; + const expectedOutput = [[]]; + expect(getPermutations(input)).to.deep.equal(expectedOutput); + }); + }); });