Skip to content

Conversation

@inc-man
Copy link

@inc-man inc-man commented Apr 7, 2025

For the new e2e environment of OISY Wallet, we need a way to manually sign in with an existing II. This could be done in a way such as this.

@inc-man inc-man requested a review from peterpeterparker April 7, 2025 07:22
@inc-man inc-man marked this pull request as ready for review April 7, 2025 09:55
@inc-man inc-man requested a review from a team as a code owner April 7, 2025 09:55
@inc-man
Copy link
Author

inc-man commented Apr 8, 2025

I have corrected a few things already, but unsure about the waitFor timeout. Since we always have an "alternative" it can be set to a minimum too.

@AntonioVentilii just for notifications :)

expect(iiPage.isClosed()).toBe(true);
};

createNewIdentity = async (params?: {
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between this new function and signInWithNewIdentity? i.e. Why introduce a new function instead of enhancing the existing one, since they seem to share quite a bit of code?

Copy link
Author

Choose a reason for hiding this comment

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

Its a mixture of what is already there, yes. But I feel like its a very abstract case, so having it as a new function gives clarity and helps for testing purposes. The first PR was basically what you suggest, but then the test didnt check all options, so having it "standalone" just makes it easier to go through all scenarios.

Copy link
Member

@peterpeterparker peterpeterparker Apr 9, 2025

Choose a reason for hiding this comment

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

Thanks for the feedback. I'm not convinced it should be two distinct functions, but I can live with it.

However, in that case, we should improve the naming, as it wasn’t clear to me at first glance which function does what.

Please also add a TODO (and create a follow-up PR once this one is merged) for some post-merge cleanup/refactoring, as the new function duplicates code. This will be especially useful since I’d not like to maintain various chunks of code that reflect the exact same II flow.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, aside from iiPage.locator('#displayUserContinue'), this new createNewIdentity function is almost identical to the existing signInWithNewIdentity. So I don't think we need to add it.

If we need different behavior, let's just add an option to the existing signInWithNewIdentity instead.

return createdIdentity;
}

manuallySignInWithIdentity = async ({
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between manuallySignInWithIdentity and signInWithIdentity? While they do differ, the naming suggests a similar intent.

Copy link
Author

Choose a reason for hiding this comment

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

The naming should be better, agreed. Basically as mentioned in the other comment, the manuallySignIn is an extended form that checks for "all possible" ways to login. Since we need a "clean start" where no Identity is "known", we have the possibility to cycle through all available options. This is done inside of manuallySignInWithIdentity

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the feedback, I guess same as my previous comment.

Copy link
Member

Choose a reason for hiding this comment

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

Here a few naming alternative:

  • enterIdentityAndSignIn
  • signInWithPromptedIdentity
  • inputIdentityAndSignIn

The first doesn't sound too bad?

Also, the JS Docs is missing, can you please add it as well.

await iiPage.fill('input[data-role="anchor-input"]', identity.toString());
await iiPage.locator('[data-action="continue"]').click();
} else {
throw new Error('No locator found for identity, first time, or fallback');
Copy link
Member

Choose a reason for hiding this comment

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

Can we improve the error message? I guess we can parse the effective locator that was used and I'm unsure what's "fallback".

Copy link
Author

Choose a reason for hiding this comment

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

We can, I just wrote something so we have a certain error. Basically we have "Identity" which is the locator for the Identity button when login in again. "first time" is the "initial login button that only shows when no Identity is known" and "fallback" is the "Other Options" button to sign in by manually typing in the Identity.

Copy link
Member

Choose a reason for hiding this comment

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

For context: the point is, it’s not just "we". This library can also be used by the community. That’s why having a clear API and comprehensive error messages matters.

That's why I think we should introduce the locator value and improve the error msg.

Copy link
Author

Choose a reason for hiding this comment

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

I changed the naming of the types and also the error message, maybe have a look and if not satisfied I can display the exact locator value

Copy link
Member

Choose a reason for hiding this comment

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

Actually, displaying the actual locator value was the most important part of my feedback 😉. If a developer’s test fails in CI, a stack trace like 'No locator found...' would require them to dig through their code. On the other hand, showing something like 'No locator [testId="identity-login"] found...' is more user-friendly and handy.

createdIdentity = await iiPage.createNewIdentity();
});

testWithII('sign in using identity from list or fallback manually', async ({page, iiPage}) => {
Copy link
Member

Choose a reason for hiding this comment

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

Is the title of the test accurate, from the code is seems that we login, logout and then login again.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, the title can be somewhat missleading. Basically the login, logout and login are used to simulate the exact flow. There is an initial login, the "automated" if the Identity is showing in the list, or the fallback if the initial Login happened but the Identity is not showing in the list.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can review the title or add a comment about the flow then?

Copy link
Author

Choose a reason for hiding this comment

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

Any suggestion on what to name it?

Copy link
Member

Choose a reason for hiding this comment

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

There is an initial login, the "automated" if the Identity is showing in the list, or the fallback

Reading your feedback again and noticing the mention of or make me think: shouldn't it be two tests actually? Or did you meant and?

createdIdentity = await iiPage.createNewIdentity();
});

testWithII('sign in using identity from list or fallback manually', async ({page, iiPage}) => {
Copy link
Member

Choose a reason for hiding this comment

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

There is an initial login, the "automated" if the Identity is showing in the list, or the fallback

Reading your feedback again and noticing the mention of or make me think: shouldn't it be two tests actually? Or did you meant and?


type RaceResult = 'existingIdentityLogin' | 'firstRunManualLogin' | 'moreOptionsLogin' | 'none';

async function getRaceResult(
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: for consistency with our codebase I would use a const getRaceResult = () ...

type RaceResult = 'existingIdentityLogin' | 'firstRunManualLogin' | 'moreOptionsLogin' | 'none';

async function getRaceResult(
locator: { waitFor: (options: any) => Promise<any> },
Copy link
Member

Choose a reason for hiding this comment

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

The linter disallow any

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