Skip to content

Commit

Permalink
[sitecore-jss]: Unit test has been added for getPermutations function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Matkovskyi committed Oct 8, 2024
1 parent 760411d commit d750dd5
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/sitecore-jss/src/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit d750dd5

Please sign in to comment.