Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-8291] - Enforce Factory.each to start increment at 1 #10619

Merged
merged 14 commits into from
Jun 29, 2024

Conversation

abailly-akamai
Copy link
Contributor

@abailly-akamai abailly-akamai commented Jun 26, 2024

Description 📝

This PR makes sure Factory.each always start iterating from 1 rather than 0. Having falsy entity IDs is responsible for for a few issues (unit tests false positives in, disabling queries based on a truthy entity id) and will help us with our "Next Gen MSW ©" where we will generate new entities based on factories and those can't have 0 as an id.

In order to do so I added a monkey patch (run time modifier) for Factory.each so that it increments from 1 in every factory without having to modify every factory instance. This means not only IDs but also every value relying on an each was modified. As a result, many tests asserting either for some order, value or array length needed to be updated. It also surfaced a few issues with some tests, tho more could have been fixed (outside of scope for this PR).

This PR does not touch any consumer code.

Changes 🔄

  • Patch Factory.js each to increment from 1
  • Fix tests affected

How to test 🧪

Verification steps

  • run yarn test and confirm all tests are passing locally and in CI
  • confirm e2e suites are passing in CI

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@@ -63,7 +63,7 @@ describe('database current configuration section', () => {
getByText('1 GB');

getByText('CPUs');
getByText('2');
getByText('4');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of databaseTypeFactory:

vcpus: Factory.each((i) => i * 2)

@@ -118,7 +168,7 @@ describe('KubeCheckoutBar', () => {
);

// 5 node pools * 3 linodes per pool * 12 per linode * 20% increase for Jakarta + UNKNOWN_PRICE
await findByText(/\$180\.00/);
await findByText(/\$183\.00/);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no entirely sure about how the prices are calculated but considering id: 0 k8 type may not have been taken into consideration before i assume this is right.

const stackscript = stackScriptFactory.build();
const stackscript = stackScriptFactory.build({
id: 1234,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

avoiding multiple 1 assertions on the page

margin: 0,
},
'-moz-appearance': 'textfield',
MozAppearance: 'textfield',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unrelated to PR but was really tired to see this warning in the logs 🧹

Copy link
Contributor

Choose a reason for hiding this comment

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

This has annoyed me forever too! 🙌

@@ -74,8 +77,9 @@ describe('ImageSelect', () => {
describe('ImageSelect component', () => {
it('should render', () => {
const { getByText } = renderWithTheme(<ImageSelect {...props} />);
getByText(/image-0/i);
getByText(/image-1(?!\d)/i);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

avoid matching image-10

@abailly-akamai abailly-akamai marked this pull request as ready for review June 27, 2024 03:28
@abailly-akamai abailly-akamai requested a review from a team as a code owner June 27, 2024 03:28
@abailly-akamai abailly-akamai requested review from dwiley-akamai and mjac0bs and removed request for a team June 27, 2024 03:28
Copy link

github-actions bot commented Jun 27, 2024

Coverage Report:
Base Coverage: 82.24%
Current Coverage: 82.24%

},
writable: false,
});
}
Copy link
Contributor Author

@abailly-akamai abailly-akamai Jun 27, 2024

Choose a reason for hiding this comment

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

@jdamore-linode this unblocks the issues we'll encounter with MSW however cypress is rather unhappy with overriding Factory.each.

We have a few options:

  • We find a way for cypress to accept the override (if you remove this check you'll see every test with a factory fail)
  • we go away from overriding the property and go a route of wrapping our factories in an HOC or use a custom Each for every factory or just add +1 everywhere, which I wanted to avoid
  • we leave as is and keep this change out of cypress
    Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jdamore-linode please see 886d981 and let me know what you think! I think this is clear and elegant enough to satisfy the requirements and have cypress benefit from this update

Copy link
Contributor

@dwiley-akamai dwiley-akamai left a comment

Choose a reason for hiding this comment

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

Tests pass in CI (I did observe a handful of failures locally) ✅

packages/manager/src/factories/factoryOverride.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mjac0bs mjac0bs left a comment

Choose a reason for hiding this comment

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

Looks good overall! I just saw and noted one case where we changed the expected output of the test instead of updated an id.

Unit tests passed locally and CI looks good.

Screenshot 2024-06-27 at 1 20 52 PM

@abailly-akamai abailly-akamai requested a review from a team as a code owner June 28, 2024 17:42
@abailly-akamai abailly-akamai requested review from AzureLatte and removed request for a team June 28, 2024 17:42
Copy link
Contributor

@jdamore-linode jdamore-linode left a comment

Choose a reason for hiding this comment

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

Nice, thanks for taking this on @abailly-akamai! Approved pending unit tests passing (seems there's currently a GHA incident which I'm assuming is the reason those jobs haven't run)

packages/manager/tsconfig.json Outdated Show resolved Hide resolved
@abailly-akamai abailly-akamai merged commit e64101c into linode:develop Jun 29, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants