Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BZ-1211257 - Comments always show the 'current' time
(cherry picked from commit 7a51dcd)
- Loading branch information
Showing
7 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...rc/main/java/org/kie/workbench/common/widgets/client/discussion/CommentLinePresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2014 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.widgets.client.discussion; | ||
|
||
import com.google.gwt.user.client.ui.IsWidget; | ||
import com.google.gwt.user.client.ui.Widget; | ||
import org.guvnor.common.services.shared.metadata.model.DiscussionRecord; | ||
import org.kie.workbench.common.widgets.client.util.DateFormatHelper; | ||
|
||
public class CommentLinePresenter | ||
implements IsWidget, | ||
CommentLineView.Presenter { | ||
|
||
private CommentLineView view; | ||
|
||
public CommentLinePresenter() { | ||
this( new CommentLineViewImpl() ); | ||
} | ||
|
||
public CommentLinePresenter( CommentLineView view ) { | ||
this.view = view; | ||
view.setPresenter( this ); | ||
} | ||
|
||
protected String formatTimestamp( long timestamp ) { | ||
return DateFormatHelper.shortFormat( timestamp ); | ||
} | ||
|
||
@Override | ||
public Widget asWidget() { | ||
return view.asWidget(); | ||
} | ||
|
||
public void setRecord( DiscussionRecord record ) { | ||
view.setAuthor( record.getAuthor() + ":" ); | ||
view.setComment( "\"" + record.getNote() + "\"" ); | ||
view.setDate( formatTimestamp( record.getTimestamp() ) ); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...-ui/src/main/java/org/kie/workbench/common/widgets/client/discussion/CommentLineView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2015 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.widgets.client.discussion; | ||
|
||
import com.google.gwt.user.client.ui.IsWidget; | ||
|
||
public interface CommentLineView | ||
extends IsWidget { | ||
|
||
interface Presenter { | ||
|
||
} | ||
|
||
void setPresenter( Presenter presenter ); | ||
|
||
void setAuthor( String author ); | ||
|
||
void setComment( String comment ); | ||
|
||
void setDate( String date ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ommon-ui/src/main/java/org/kie/workbench/common/widgets/client/util/DateFormatHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2015 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.widgets.client.util; | ||
|
||
import java.util.Date; | ||
|
||
import com.google.gwt.i18n.client.DateTimeFormat; | ||
|
||
public class DateFormatHelper { | ||
|
||
public static String shortFormat( long timestamp ) { | ||
return format( timestamp, DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT ); | ||
} | ||
|
||
public static String format( long timestamp, DateTimeFormat.PredefinedFormat format ) { | ||
return DateTimeFormat.getFormat( format ).format( | ||
new Date( timestamp ) ); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...est/java/org/kie/workbench/common/widgets/client/discussion/CommentLinePresenterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2015 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.widgets.client.discussion; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import org.guvnor.common.services.shared.metadata.model.DiscussionRecord; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith( MockitoJUnitRunner.class ) | ||
public class CommentLinePresenterTest { | ||
|
||
@Mock | ||
private CommentLineView view; | ||
|
||
@InjectMocks | ||
CommentLinePresenter presenter; | ||
|
||
@Test | ||
public void testVisualization() { | ||
|
||
CommentLineView view = mock( CommentLineView.class ); | ||
CommentLinePresenter presenter = new CommentLinePresenterWithNOGWTCode( view ); | ||
|
||
Date commentDate = new Date( ); | ||
DiscussionRecord record = new DiscussionRecord( commentDate.getTime(), "test user", "test note" ); | ||
presenter.setRecord( record ); | ||
|
||
verify( view, times( 1 ) ).setAuthor( eq ( expectedAuthorFormat( "test user" ) ) ); | ||
verify( view, times( 1 ) ).setComment( eq( expectedCommentFormat( "test note" ) ) ); | ||
verify( view, times( 1 ) ).setDate( expectedDateFormat( commentDate.getTime() ) ); | ||
} | ||
|
||
private String expectedDateFormat( long timestamp ) { | ||
//expected format to see in the UI -> "2015-10-21 12:09" | ||
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm" ); | ||
return sdf.format( new Date( timestamp ) ); | ||
} | ||
|
||
private String expectedCommentFormat( String comment ) { | ||
return "\"" + comment + "\""; | ||
} | ||
|
||
private String expectedAuthorFormat( String author ) { | ||
return author + ":"; | ||
} | ||
|
||
private class CommentLinePresenterWithNOGWTCode extends CommentLinePresenter { | ||
|
||
public CommentLinePresenterWithNOGWTCode( CommentLineView view ) { | ||
super( view ); | ||
} | ||
|
||
@Override | ||
protected String formatTimestamp( long timestamp ) { | ||
//override method to avoid GWT invocation during test | ||
return expectedDateFormat( timestamp ); | ||
} | ||
} | ||
} |