add more testing for FileExplorer tests

Signed-off-by: Jeremy Guarini <jguarini@paloaltonetworks.com>
This commit is contained in:
Jeremy Guarini
2021-10-27 09:36:30 -07:00
parent 7ea444c78d
commit 72e7a87684
2 changed files with 144 additions and 2 deletions
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { groupByPath } from './FileExplorer';
import { groupByPath, buildFileStructure } from './FileExplorer';
const dummyFiles = [
{
@@ -40,6 +40,22 @@ const dummyFiles = [
tracked: 1,
path: '',
},
{
filename: 'dir3/dir2/dir1/file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
path: '',
},
{
filename: 'dir3/dir2/dir3/file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
path: '',
},
];
const dummyDataGroupedByPath = {
@@ -71,6 +87,124 @@ const dummyDataGroupedByPath = {
path: '',
},
],
dir3: [
{
filename: 'dir3/dir2/dir1/file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
path: '',
},
{
filename: 'dir3/dir2/dir3/file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
path: '',
},
],
};
const coverageTableRow = {
files: dummyFiles,
coverage: 1,
missing: 1,
tracked: 1,
path: '',
};
const coverageTableRowResults = {
files: [
{
path: 'dir1',
files: [
{
path: 'file1',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
},
{
path: 'file2',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
},
],
coverage: 1,
missing: 2,
tracked: 2,
},
{
path: 'dir2',
files: [
{
path: 'file3',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
},
],
coverage: 1,
missing: 1,
tracked: 1,
},
{
path: 'dir3',
files: [
{
path: 'dir2',
files: [
{
path: 'dir1',
files: [
{
path: 'file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
},
],
coverage: 1,
missing: 1,
tracked: 1,
},
{
path: 'dir3',
files: [
{
path: 'file4',
files: [],
coverage: 1,
missing: 1,
tracked: 1,
},
],
coverage: 1,
missing: 1,
tracked: 1,
},
],
coverage: 1,
missing: 2,
tracked: 2,
},
],
coverage: 1,
missing: 2,
tracked: 2,
},
],
coverage: 1,
missing: 1,
tracked: 1,
path: '',
};
describe('groupByPath function', () => {
@@ -78,3 +212,11 @@ describe('groupByPath function', () => {
expect(groupByPath(dummyFiles)).toStrictEqual(dummyDataGroupedByPath);
});
});
describe('buildFileStructure function', () => {
it('should group files by their root directory,as per their filename', () => {
expect(buildFileStructure(coverageTableRow)).toStrictEqual(
coverageTableRowResults,
);
});
});
@@ -82,7 +82,7 @@ const removeVisitedPathGroup = (
});
};
const buildFileStructure = (row: CoverageTableRow) => {
export const buildFileStructure = (row: CoverageTableRow) => {
const dataGroupedByPath: FileStructureObject = groupByPath(row.files);
row.files = Object.keys(dataGroupedByPath).map(pathGroup => {
return buildFileStructure({