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

[Zucchini][Front][Back] Restitution de l'action effectuée lors de l'analyse sur la vue détail d'un scenario #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class Comment extends BaseEntity<String> {
@Embedded(concreteClass = HashSet.class)
private Set<ItemReference> references;

private String analyseAction;

/**
* Private constructor for Morphia.
*/
Expand All @@ -54,11 +56,12 @@ private Comment() {
* @param references References
* @param content Comment content
*/
public Comment(final Iterable<ItemReference> references, final String content) {
public Comment(final Iterable<ItemReference> references, final String content, final String analyseAction) {
id = UUID.randomUUID().toString();
date = ZonedDateTime.now();
this.references = Sets.newHashSet(references);
this.content = Objects.requireNonNull(content);
this.analyseAction = analyseAction;
}

public void setContent(final String content) {
Expand All @@ -81,9 +84,16 @@ public Set<ItemReference> getReferences() {
return Collections.unmodifiableSet(references);
}

public String getAnalyseAction() {
return analyseAction;
}

public void setAnalyseAction(String analyseAction) {
this.analyseAction = analyseAction;
}

@Override
protected String getEntityId() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Response create(@Valid @NotNull final CreateCommentRequest request) {

LOGGER.info("Create comment with references {}", references);

final Comment comment = new Comment(references, request.getContent());
final Comment comment = new Comment(references, request.getContent(), request.getAnalyseAction());
commentRepository.save(comment);

final URI location = UriBuilder.fromUri(baseUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class CreateCommentRequest {
@NotEmpty
private String content;

private String analyseAction;

public String getContent() {
return content;
}
Expand All @@ -16,4 +18,11 @@ public void setContent(final String content) {
this.content = content;
}

public String getAnalyseAction() {
return analyseAction;
}

public void setAnalyseAction(String analyseAction) {
this.analyseAction = analyseAction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ public class CommentTest {

private static final String CONTENT = "content";

private static final String ANALYSE_ACTION = "analyseAction";

@Test
public void should_create_comment() throws Exception {
// given
final ZonedDateTime testStartDate = ZonedDateTime.now();

// when
final Comment comment = new Comment(REFERENCES, CONTENT);
final Comment comment = new Comment(REFERENCES, CONTENT, ANALYSE_ACTION);

// then
assertThat(comment.getId()).isNotEmpty();
Assertions.assertThat(comment.getReferences()).isEqualTo(REFERENCES);
assertThat(comment.getContent()).isEqualTo(CONTENT);
assertThat(comment.getAnalyseAction()).isEqualTo(ANALYSE_ACTION);
assertThat(comment.getDate()).isAfterOrEqualTo(testStartDate);

assertThat(comment.getEntityId()).isEqualTo(comment.getId());
Expand All @@ -42,7 +45,7 @@ public void should_set_description() throws Exception {
// given
final String newContent = "newContent";

final Comment comment = new Comment(REFERENCES, CONTENT);
final Comment comment = new Comment(REFERENCES, CONTENT, ANALYSE_ACTION);

// when
comment.setContent(newContent);
Expand Down
7 changes: 5 additions & 2 deletions zucchini-ui-frontend/src/api/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ class ScenariosApi {
});
}

addComment({ scenarioId, comment }) {
addComment({ scenarioId, comment, analyseAction }) {
return this.client.post({
path: `/${scenarioId}/comments/create`,
body: { content: comment },
body: {
content: comment,
analyseAction: analyseAction
},
hasOutput: false
});
}
Expand Down
19 changes: 17 additions & 2 deletions zucchini-ui-frontend/src/scenario/components/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Comment extends React.PureComponent {
static propTypes = {
comment: PropTypes.object.isRequired,
testRunId: PropTypes.string,
config: PropTypes.object,
onChange: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired
};
Expand Down Expand Up @@ -55,8 +56,7 @@ export default class Comment extends React.PureComponent {
};

render() {
const { comment, testRunId } = this.props;

const { comment, testRunId, config } = this.props;
let testRunInfo = null;
if (comment.testRunId === testRunId) {
testRunInfo = <i>(tir de test actuel)</i>;
Expand All @@ -81,11 +81,26 @@ export default class Comment extends React.PureComponent {
commentComponent = <CommentText comment={comment} onEdit={this.onEdit} onDelete={this.onDelete} />;
}

let correctionAction = null;
if (comment.analyseAction != null) {
let action = config.correctionActionConfig.find(a => {
return a.actionCode == comment.analyseAction;
});
if (action != null) {
correctionAction = (
<div>
<b>Action pour analyse : </b> {action.actionLabel}
</div>
);
}
}

return (
<div>
<h4>
Le {toNiceDate(comment.date)} <small>{testRunInfo}</small>
</h4>
{correctionAction}
{commentComponent}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import Comment from "./Comment";

import { deleteComment, updateCommentThenReload } from "../redux";

const selectConfig = createSelector(
state => state.scenario.config,
config => config
);

const selectTestRunId = createSelector(
state => state.scenario.scenario.testRunId || null,
testRunId => testRunId
);

const selectProps = createStructuredSelector({
testRunId: selectTestRunId
testRunId: selectTestRunId,
config: selectConfig
});

const CommentContainer = connect(selectProps, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class CommentList extends React.PureComponent {
};

render() {
console.log("CommentList", this.props);
const { comments } = this.props;

const commentList = comments.map(comment => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class ScenarioPage extends React.Component {
<hr />

<h2>Commentaires</h2>
<CommentListContainer />
<CommentListContainer config={config} />

<h4>Ajouter un nouveau commentaire</h4>
<AddCommentFormContainer scenarioId={scenarioId} />
Expand Down
4 changes: 2 additions & 2 deletions zucchini-ui-frontend/src/scenario/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function updateScenarioState({ scenarioId, newState }) {
return scenariosApi.updateScenarioState({ scenarioId, newState });
}

export function addScenarioComment({ scenarioId, comment }) {
return scenariosApi.addComment({ scenarioId, comment });
export function addScenarioComment({ scenarioId, comment, analyseAction }) {
return scenariosApi.addComment({ scenarioId, comment, analyseAction });
}

export function deleteScenario({ scenarioId }) {
Expand Down
10 changes: 6 additions & 4 deletions zucchini-ui-frontend/src/scenario/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ export function updateScenarioState({ scenarioId, newState }) {
};
}

export function addScenarioComment({ scenarioId, comment }) {
export function addScenarioComment({ scenarioId, comment, analyseAction }) {
console.log(analyseAction);
return {
type: ADD_SCENARIO_COMMENT,
payload: model.addScenarioComment({ scenarioId, comment }),
payload: model.addScenarioComment({ scenarioId, comment, analyseAction }),
meta: {
scenarioId
}
Expand All @@ -153,9 +154,10 @@ export function updateScenarioStateAndComment({ scenarioId, newState, comment })
newState
})
);

let analyseAction = newState.analyseAction;
console.log("updateScenarioStateAndComment", analyseAction);
if (comment) {
await dispatch(addScenarioComment({ scenarioId, comment }));
await dispatch(addScenarioComment({ scenarioId, comment, analyseAction }));
}

await dispatch(loadScenarioPage({ scenarioId }));
Expand Down