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

implement revert logic by using originalSelector #603

Merged
merged 1 commit into from
Jun 1, 2022
Merged

Conversation

cescoferraro
Copy link
Contributor

This PR add revert logic to individual assertions

Changes

  • implement field originalSelector on assertions

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

@@ -18,6 +19,7 @@ const AssertionCardSelectorList: React.FC<IProps> = ({selectorList, pseudoSelect
<S.SelectorValueText>{value}</S.SelectorValueText>
</S.Selector>
))}
<S.SelectorValueText>{originalSelector}</S.SelectorValueText>
{pseudoSelector && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only showing for debugging proposes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, should we remove it then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -11,6 +11,7 @@ const AssertionResults = ({allPassed = false, results = []}: TRawAssertionResult
id: uniqueId(),
selector,
spanIds: AssertionService.getSpanIds(resultList),
originalSelector: selector,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

creating the field on AsserionResult

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this in the model? I see we also have a assertionResultsToDefinitionList in web/src/redux/slices/TestDefinition.slice.ts

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is good here for the moment, but I get your point

setSelectedAssertion: CaseReducer<ITestDefinitionState, PayloadAction<string>>;
},
'testDefinition'
>({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add better typescript typings

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always up for this. Should this mean that we can drop the types from each of the reducer functions as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm 🤔 I'm not sure about this. IMO we should let typescript infer it when possible. It's doing it already.

Screen Shot 2022-06-01 at 10 23 59

return {
...def,
...definition,
originalSelector: def.originalSelector,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to ensure originalDefinition is carried over

Copy link
Collaborator

@xoscar xoscar left a comment

Choose a reason for hiding this comment

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

Hey @cescoferraro gj man, I left some comments and concerns. Let me know what you think

@@ -17,8 +18,15 @@ interface TAssertionCardProps {
onEdit(assertionResult: TAssertionResultEntry): void;
}

export function useRevertDefinitionCallback(originalSelector: string): () => void {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of having the dispatch here, we should be able to wrap it up at the TestDefinitionProvider like the rest of the functions.

{isDraft && (
<>
<S.StatusTag>draft</S.StatusTag>
<Tooltip color="white" title="Revert Assertion">
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is kind of weird that both the tooltip an the actual message have the same text

@@ -18,6 +19,7 @@ const AssertionCardSelectorList: React.FC<IProps> = ({selectorList, pseudoSelect
<S.SelectorValueText>{value}</S.SelectorValueText>
</S.Selector>
))}
<S.SelectorValueText>{originalSelector}</S.SelectorValueText>
{pseudoSelector && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, should we remove it then?

setSelectedAssertion: CaseReducer<ITestDefinitionState, PayloadAction<string>>;
},
'testDefinition'
>({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always up for this. Should this mean that we can drop the types from each of the reducer functions as well?

console.log('==========');
console.log(current(d));
console.log(originalSelector);
if (d?.originalSelector === originalSelector) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens when the user tries to revert a newly created assertion? in that case we should wipe it from the store isn't it?

if (def.selector === selector) return definition;
if (def.originalSelector === selector)
return {
...def,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can avoid spreading the original dev, we can just do it for the new def + the original selector

Copy link
Collaborator

@xoscar xoscar left a comment

Choose a reason for hiding this comment

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

Hey @cescoferraro I added some questions 😬

@@ -11,6 +11,7 @@ const AssertionResults = ({allPassed = false, results = []}: TRawAssertionResult
id: uniqueId(),
selector,
spanIds: AssertionService.getSpanIds(resultList),
originalSelector: selector,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is good here for the moment, but I get your point

{payload: {definition, selector}}: PayloadAction<{definition: TTestDefinitionEntry; selector: string}>
) {
revertDefinition(state, {payload: {originalSelector}}) {
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are we ignoring here?

// @ts-ignore
state.definitionList = state.definitionList
.map(d => {
if (d?.originalSelector === originalSelector) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this cover the scenario of reverting a newly created assertion?

{isDraft && (
<>
<S.StatusTag>draft</S.StatusTag>
<Button type="link" data-cy="assertion-action-revert" onClick={resetDefinition}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this onClick also needs the e.stopPropagation(); similar to what we have in the Edit/Delete icons.

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.

3 participants