Skip to content

test: add missing unit tests for project utils path conversion - #457

Open
Ayush4958 wants to merge 1 commit into
StatTag:masterfrom
Ayush4958:test/project-utils-coverage
Open

test: add missing unit tests for project utils path conversion#457
Ayush4958 wants to merge 1 commit into
StatTag:masterfrom
Ayush4958:test/project-utils-coverage

Conversation

@Ayush4958

Copy link
Copy Markdown
Contributor

Description

I had resolves two // TODO - unit tests!! comments in app/utils/project.js by adding test coverage for the following methods:

  • ProjectUtil.absoluteToRelativePathForAssetGroups
  • ProjectUtil.relativeToAbsolutePathForAssetGroups

Changes Made

  • Added a describe block for both methods in test/utils/project.spec.js ensuring proper null/undefined handling and verifying delegation to AssetUtil.
  • Imported AssetUtil into the test suite.
  • Removed the TODO comments from app/utils/project.js.

Adds unit test coverage for absoluteToRelativePathForAssetGroups and relativeToAbsolutePathForAssetGroups in ProjectUtil, resolving existing TODO comments.

@lrasmus lrasmus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests make sense conceptually but I think they are going to give the wrong idea about expected behavior. Please see more detailed comment on request for change. Thanks!

});

it('should call AssetUtil.absoluteToRelativePathForArray for each asset group', () => {
const spy = jest.spyOn(AssetUtil, 'absoluteToRelativePathForArray').mockImplementation((p, a) => a);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize the intent of this test isn't to actually verify the functionality of absoluteToRelativePathForArray (we have other tests for that), however my concern is that by mocking the function so it changes how it behaves, this test (if someone were to read it as documentation) would get the wrong idea of what this function does.

I think we need the original absoluteToRelativePathForArray functionality to be applied. The result of calling the function under test should never be the same as the input, and this is what the test says it expects.

Same for the relative -> absolute tests too.

ProjectUtil.removeExternalAsset(project, asset);
expect(project.externalAssets.children.length).toEqual(1);
});
describe('absoluteToRelativePathForAssetGroups', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test blocks are embedded within describe('removeExternalAsset', () => { - could we please move them out of that block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants