|
|
@ -9,41 +9,39 @@ import { of } from 'rxjs'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
import { IMock, It, Mock, Times } from 'typemoq'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
AppsState, |
|
|
|
|
|
CommentDto, |
|
|
CommentDto, |
|
|
CommentsDto, |
|
|
CommentsDto, |
|
|
CommentsService, |
|
|
CommentsService, |
|
|
CommentsState, |
|
|
CommentsState, |
|
|
DateTime, |
|
|
|
|
|
DialogService, |
|
|
DialogService, |
|
|
ImmutableArray, |
|
|
ImmutableArray, |
|
|
Version |
|
|
Version |
|
|
} from './../'; |
|
|
} from './../'; |
|
|
|
|
|
|
|
|
|
|
|
import { TestValues } from './_test-helpers'; |
|
|
|
|
|
|
|
|
describe('CommentsState', () => { |
|
|
describe('CommentsState', () => { |
|
|
const app = 'my-app'; |
|
|
const { |
|
|
|
|
|
app, |
|
|
|
|
|
appsState, |
|
|
|
|
|
creator, |
|
|
|
|
|
now |
|
|
|
|
|
} = TestValues; |
|
|
|
|
|
|
|
|
const commentsId = 'my-comments'; |
|
|
const commentsId = 'my-comments'; |
|
|
const now = DateTime.today(); |
|
|
|
|
|
const user = 'not-me'; |
|
|
|
|
|
|
|
|
|
|
|
const oldComments = new CommentsDto([ |
|
|
const oldComments = new CommentsDto([ |
|
|
new CommentDto('1', now, 'text1', user), |
|
|
new CommentDto('1', now, 'text1', creator), |
|
|
new CommentDto('2', now, 'text2', user) |
|
|
new CommentDto('2', now, 'text2', creator) |
|
|
], [], [], new Version('1')); |
|
|
], [], [], new Version('1')); |
|
|
|
|
|
|
|
|
let dialogs: IMock<DialogService>; |
|
|
let dialogs: IMock<DialogService>; |
|
|
let appsState: IMock<AppsState>; |
|
|
|
|
|
let commentsService: IMock<CommentsService>; |
|
|
let commentsService: IMock<CommentsService>; |
|
|
let commentsState: CommentsState; |
|
|
let commentsState: CommentsState; |
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
dialogs = Mock.ofType<DialogService>(); |
|
|
dialogs = Mock.ofType<DialogService>(); |
|
|
|
|
|
|
|
|
appsState = Mock.ofType<AppsState>(); |
|
|
|
|
|
|
|
|
|
|
|
appsState.setup(x => x.appName) |
|
|
|
|
|
.returns(() => app); |
|
|
|
|
|
|
|
|
|
|
|
commentsService = Mock.ofType<CommentsService>(); |
|
|
commentsService = Mock.ofType<CommentsService>(); |
|
|
|
|
|
|
|
|
commentsService.setup(x => x.getComments(app, commentsId, new Version('-1'))) |
|
|
commentsService.setup(x => x.getComments(app, commentsId, new Version('-1'))) |
|
|
@ -55,9 +53,9 @@ describe('CommentsState', () => { |
|
|
|
|
|
|
|
|
it('should load and merge comments', () => { |
|
|
it('should load and merge comments', () => { |
|
|
const newComments = new CommentsDto([ |
|
|
const newComments = new CommentsDto([ |
|
|
new CommentDto('3', now, 'text3', user) |
|
|
new CommentDto('3', now, 'text3', creator) |
|
|
], [ |
|
|
], [ |
|
|
new CommentDto('2', now, 'text2_2', user) |
|
|
new CommentDto('2', now, 'text2_2', creator) |
|
|
], ['1'], new Version('2')); |
|
|
], ['1'], new Version('2')); |
|
|
|
|
|
|
|
|
commentsService.setup(x => x.getComments(app, commentsId, new Version('1'))) |
|
|
commentsService.setup(x => x.getComments(app, commentsId, new Version('1'))) |
|
|
@ -67,15 +65,15 @@ describe('CommentsState', () => { |
|
|
|
|
|
|
|
|
expect(commentsState.snapshot.isLoaded).toBeTruthy(); |
|
|
expect(commentsState.snapshot.isLoaded).toBeTruthy(); |
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
new CommentDto('2', now, 'text2_2', user), |
|
|
new CommentDto('2', now, 'text2_2', creator), |
|
|
new CommentDto('3', now, 'text3', user) |
|
|
new CommentDto('3', now, 'text3', creator) |
|
|
])); |
|
|
])); |
|
|
|
|
|
|
|
|
commentsService.verify(x => x.getComments(app, commentsId, It.isAny()), Times.exactly(2)); |
|
|
commentsService.verify(x => x.getComments(app, commentsId, It.isAny()), Times.exactly(2)); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it('should add comment to snapshot when created', () => { |
|
|
it('should add comment to snapshot when created', () => { |
|
|
const newComment = new CommentDto('3', now, 'text3', user); |
|
|
const newComment = new CommentDto('3', now, 'text3', creator); |
|
|
|
|
|
|
|
|
const request = { text: 'text3' }; |
|
|
const request = { text: 'text3' }; |
|
|
|
|
|
|
|
|
@ -85,9 +83,9 @@ describe('CommentsState', () => { |
|
|
commentsState.create('text3').subscribe(); |
|
|
commentsState.create('text3').subscribe(); |
|
|
|
|
|
|
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
new CommentDto('1', now, 'text1', user), |
|
|
new CommentDto('1', now, 'text1', creator), |
|
|
new CommentDto('2', now, 'text2', user), |
|
|
new CommentDto('2', now, 'text2', creator), |
|
|
new CommentDto('3', now, 'text3', user) |
|
|
new CommentDto('3', now, 'text3', creator) |
|
|
])); |
|
|
])); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -100,8 +98,8 @@ describe('CommentsState', () => { |
|
|
commentsState.update('2', 'text2_2', now).subscribe(); |
|
|
commentsState.update('2', 'text2_2', now).subscribe(); |
|
|
|
|
|
|
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
new CommentDto('1', now, 'text1', user), |
|
|
new CommentDto('1', now, 'text1', creator), |
|
|
new CommentDto('2', now, 'text2_2', user) |
|
|
new CommentDto('2', now, 'text2_2', creator) |
|
|
])); |
|
|
])); |
|
|
|
|
|
|
|
|
commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once()); |
|
|
commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once()); |
|
|
@ -114,7 +112,7 @@ describe('CommentsState', () => { |
|
|
commentsState.delete('2').subscribe(); |
|
|
commentsState.delete('2').subscribe(); |
|
|
|
|
|
|
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ |
|
|
new CommentDto('1', now, 'text1', user) |
|
|
new CommentDto('1', now, 'text1', creator) |
|
|
])); |
|
|
])); |
|
|
|
|
|
|
|
|
commentsService.verify(x => x.deleteComment(app, commentsId, '2'), Times.once()); |
|
|
commentsService.verify(x => x.deleteComment(app, commentsId, '2'), Times.once()); |
|
|
|