Repository: facebook/docusaurus
File: packages/docusaurus-plugin-content-docs/src/client/__tests__/docsClientUtils.test.ts (TypeScript)

Code before:
    ];
    const test2 = [
      createVersion('current', '/docs/', false),
      createVersion('version2', '/docs/version2/', true),
      createVersion('version1', '/docs/version1/', false),
    ];

    // docs only website
    const test3 = [
      createVersion('current', '/', false),
      createVersion('version2', '/version2', true),
      createVersion('version1', '/version1', false),
    ];

    // docs only with trailing slash
    const test4 = [
      createVersion('current', '/', false),
      createVersion('version2', '/version2/', true),
      createVersion('version1', '/version1/', false),
    ];

    expect(sortVersionsByPathDepth(test1)).toEqual([
      test1[2], // version1
      test1[1], // version2
      test1[0], // current
    ]);
    expect(sortVersionsByPathDepth(test2)).toEqual([
      test2[2], // version1
      test2[1], // version2
      test2[0], // current
    ]);
    expect(sortVersionsByPathDepth(test3)).toEqual([
      test3[2], // version1
      test3[1], // version2
      test3[0], // current
    ]);
    expect(sortVersionsByPathDepth(test4)).toEqual([
      test4[2], // version1
      test4[1], // version2
      test4[0], // current
    ]);
  });

  it('getActiveDocContext', () => {
    const versionNext: GlobalVersion = {
      name: 'next',
      label: 'next',
      path: '/docs/next',
      isLast: false,
      mainDocId: 'doc1',
      docs: [

Review comment (suggestion):
Would be better if the expectaction was "closer" to the test setup, otherwise this test is hard to understand

It's better to create 4 tests rather than to put many tests into one

Code after:
        name: 'version2',
        path: '/docs/v2',
        isLast: false,
      });

      expect(testActiveVersion([v1, v2], '/docs')?.name).toBe('version1');
      expect(testActiveVersion([v1, v2], '/docs/v2')?.name).toBe('version2');

      expect(
        testActiveVersion([{...v1, isLast: true}, v2], '/docs')?.name,
      ).toBe('version1');
      expect(
        testActiveVersion([{...v1, isLast: true}, v2], '/docs/v2')?.name,
      ).toBe('version2');

      expect(
        testActiveVersion([v1, {...v2, isLast: true}], '/docs')?.name,
      ).toBe('version1');
      expect(
        testActiveVersion([v1, {...v2, isLast: true}], '/docs/v2')?.name,
      ).toBe('version2');
    });

    it('getActiveVersion matches first version when same paths', () => {
      const v1 = globalVersion({
        name: 'version1',
        path: '/docs',
      });
      const v2 = globalVersion({
        name: 'version2',
        path: '/docs',
      });

      expect(testActiveVersion([v1, v2], '/docs')?.name).toBe('version1');
      expect(testActiveVersion([v2, v1], '/docs')?.name).toBe('version2');
      expect(testActiveVersion([v1, v2], '/docs/myDoc')?.name).toBe('version1');
      expect(testActiveVersion([v2, v1], '/docs/myDoc')?.name).toBe('version2');
    });

    it('getActiveVersion without trailing slash', () => {
      const versions = [
        globalVersion({
          name: 'current',
          path: '/docs',
        }),
        globalVersion({
          name: 'version2',
          path: '/docs/version2',
        }),
        globalVersion({
          name: 'version1',