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

chore: add-tests #15

Merged
merged 6 commits into from
Mar 6, 2025
Merged

chore: add-tests #15

merged 6 commits into from
Mar 6, 2025

Conversation

ryanbas21
Copy link
Collaborator

@ryanbas21 ryanbas21 commented Feb 11, 2025

JIRA Ticket

https://pingidentity.atlassian.net/browse/SDKS-3677

Description

Adds some testing, added a test to the "basic" suite because i wanted to make sure logout worked.

This is probably dependent on a WIP story because the fields flow uses things like password verify and label which im purposefully asserting as undefined.

When that work is done and this gets rebased, i'd expect these tests to fail

Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: 194133a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@forgerock/davinci-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented Feb 11, 2025

View your CI Pipeline Execution ↗ for commit 194133a.

Command Status Duration Result
nx affected -t build typecheck lint test e2e-ci ✅ Succeeded 1m 4s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-06 10:25:46 UTC

Copy link
Contributor

github-actions bot commented Feb 11, 2025

Deployed eb19543 to https://ForgeRock.github.io/ping-javascript-sdk/pr-15/eb195434f2a94373d5644417ee57680979364276 branch gh-pages in ForgeRock/ping-javascript-sdk

@@ -112,6 +112,7 @@ export function returnSingleValueCollector<
CollectorType extends SingleValueCollectorTypes = 'SingleValueCollector',
>(field: Field, idx: number, collectorType: CollectorType, data?: string) {
let error = '';
console.log('the field ', field);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

debugging because label was resolving to an error during normalization.

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 50.23%. Comparing base (c2ba0e7) to head (194133a).

Files with missing lines Patch % Lines
packages/davinci-client/src/lib/client.store.ts 0.00% 19 Missing ⚠️
packages/davinci-client/src/lib/davinci.utils.ts 89.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   50.00%   50.23%   +0.23%     
==========================================
  Files          21       21              
  Lines        1232     1256      +24     
  Branches      163      166       +3     
==========================================
+ Hits          616      631      +15     
- Misses        616      625       +9     
Files with missing lines Coverage Δ
packages/davinci-client/src/lib/node.reducer.ts 76.92% <100.00%> (+0.78%) ⬆️
packages/davinci-client/src/lib/davinci.utils.ts 72.61% <89.47%> (+1.28%) ⬆️
packages/davinci-client/src/lib/client.store.ts 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -1,6 +1,5 @@
name: ForgeRock Pull Request CI
on:
pull_request_target:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was a mistake to add. sorry. its not what i thought it would do.

const config: DaVinciConfig = {
clientId: '724ec718-c41c-4d51-98b0-84a583f450f9',
redirectUri: window.location.origin + '/',
const qs = window.location.search;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added logic to add clientId param to tests for variability of flows.

@@ -79,9 +97,9 @@ const config: DaVinciConfig = {

const loginBtn = document.getElementById('logoutButton') as HTMLButtonElement;
loginBtn.addEventListener('click', async () => {
await FRUser.logout({ logoutRedirectUri: window.location.href });
await FRUser.logout({ logoutRedirectUri: `${window.location.origin}/` });
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because of the above changes , fixed this to use origin so it doesnt include the clientId param

return true;
}
});
await logoutButton.click();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extended this test to include logout for my own sanity.

@ryanbas21 ryanbas21 force-pushed the support-field-tests branch 3 times, most recently from 9424cab to e89b4e4 Compare February 18, 2025 23:06
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is why i'm adding a changeset.

Copy link
Collaborator

@cerebrl cerebrl left a comment

Choose a reason for hiding this comment

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

Got some questions and some suggestions. The biggest concern I have is the test suite code that seems like to have quite a bit of redundancy that doesn't provide any value that I can see.

await expect(page.getByRole('link', { name: 'Vite logo' })).toBeVisible();
await expect(page.getByRole('button', { name: 'Form Validation' })).toBeVisible();
await expect(page.locator('#form')).toContainText('Form Validation');
await page.getByRole('button', { name: 'Form Validation' }).click();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is there a button called "Form Validation"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the way the connector is it renders two buttons, one is form validation and one is form fields and then we render those fields out.

Comment on lines 47 to 41
await page.getByRole('textbox', { name: 'Username' }).click();
await page.getByRole('textbox', { name: 'Username' }).fill('sdk-user');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like the clicking is not really doing anything, since your reselecting the element to .fill it. We probably should just remove these unneeded .click calls.

Comment on lines 42 to 43
await expect(page.getByText('Username')).toBeVisible();
await expect(page.getByRole('textbox', { name: 'Username' })).toBeVisible();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't these two lines be collapsed into a .getByLabel selector?

await page.getByRole('textbox', { name: 'Username' }).fill('sdk-user');
await expect(page.getByRole('textbox', { name: 'Username' })).toHaveValue('sdk-user');
await page.getByRole('textbox', { name: 'Email Address' }).click();
await page.getByRole('textbox', { name: 'Email Address' }).fill('[email protected]');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this is quite redundant. I personally feel this could be reduced to a page.getByLabel('Username').fill('demouser');. That would, how I understand it, reproduce the same result with no loss of testing.

Comment on lines 5 to 31
await page.getByRole('heading', { name: 'Select Test Form' }).click();
await page.getByRole('button', { name: 'Form Fields' }).click();
await page.getByRole('textbox', { name: 'Text Input Label' }).click();
await page.getByRole('textbox', { name: 'Text Input Label' }).click();

const txtInput = page.getByRole('textbox', { name: 'Text Input Label' });
await txtInput.fill('This is some text');
expect(txtInput).toHaveValue('This is some text');

const flowLink = page.getByRole('button', { name: 'Flow Link' });
await flowLink.click();

const flowButton = page.getByRole('button', { name: 'Flow Button' });
await flowButton.click();

const requestPromise = page.waitForRequest((request) => request.url().includes('/customForm'));
await page.getByRole('button', { name: 'Submit' }).click();
const request = await requestPromise;
const parsedData = JSON.parse(request.postData());
const data = parsedData.parameters.data;
expect(data.actionKey).toBe('submit');
expect(data.formData).toEqual({
// leaving this here because it should be fixed and we would have a failing test when we do fix import { } from "// to remind us to update the test"
['undefined']: '',
['text-input-key']: 'This is some text',
['dropdown-field-key']: '',
['radio-group-key']: '',
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't figure out what this is actually doing/testing. Can you elaborate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well we are going to test that when we click to send off the customForm request, we are sending the data correctly in the actual request.

Comment on lines 61 to 66
expect(data.formData).toEqual({
['undefined']: '',
'user.username': '',
'user.password': '',
'user.email': '',
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we expecting these values to be empty strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because i was leaving this here so the test would fail once your PR was merged. which happened

Comment on lines +175 to +192
const hasNextUrl = () => {
const data = cacheEntry.data;

if ('_links' in data) {
if ('next' in data._links) {
if ('href' in data._links.next) {
return true;
}
}
}
return false;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this should be a pure, stateless utility that could be used for fetching any property within _links. This could be reused in other portions of the project.

@ryanbas21 ryanbas21 force-pushed the support-field-tests branch from d495187 to d430d9e Compare March 5, 2025 12:32
@@ -151,6 +157,7 @@ export async function davinci({ config }: { config: DaVinciConfig }) {

return function (value: string, index?: number) {
try {
console.log('the value', value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably remove this.

Comment on lines 139 to 181
if (
collectorToUpdate.category !== 'SingleValueCollector' &&
collectorToUpdate.category !== 'ValidatedSingleValueCollector'
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did I miss checking for MultiValueCollectors as well?

@cerebrl cerebrl force-pushed the support-field-tests branch from c3d1da1 to 33d3bb3 Compare March 6, 2025 10:16
@cerebrl cerebrl force-pushed the support-field-tests branch from 33d3bb3 to 194133a Compare March 6, 2025 10:23
@cerebrl cerebrl merged commit 9d96a9b into main Mar 6, 2025
3 checks passed
@cerebrl cerebrl deleted the support-field-tests branch March 6, 2025 10:28
@ryanbas21 ryanbas21 mentioned this pull request Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants