-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [AAE-6269] added stories and mock, refactored tests * [AAE-6269] added interface for live and mock rating service * [AAE-6269] hide nodeId property
- Loading branch information
Showing
6 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
lib/content-services/src/lib/social/like.component.stories.ts
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,47 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 Alfresco Software, Ltd. | ||
* | ||
* 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. | ||
*/ | ||
|
||
import { Meta, moduleMetadata, Story } from '@storybook/angular'; | ||
import { RatingService } from './services/rating.service'; | ||
import { LikeComponent } from './like.component'; | ||
import { RatingServiceMock } from './mock/rating.service.mock'; | ||
import { SocialModule } from './social.module'; | ||
|
||
export default { | ||
component: LikeComponent, | ||
title: 'Content Services/Components/Like', | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [SocialModule], | ||
providers: [ | ||
{ provide: RatingService, useClass: RatingServiceMock } | ||
] | ||
}) | ||
], | ||
argTypes: { | ||
nodeId: { table: { disable: true } } | ||
} | ||
} as Meta; | ||
|
||
const template: Story<LikeComponent> = (args: LikeComponent) => ({ | ||
props: args | ||
}); | ||
|
||
export const primary = template.bind({}); | ||
primary.args = { | ||
nodeId: 'fake-like-node-id' | ||
}; |
34 changes: 34 additions & 0 deletions
34
lib/content-services/src/lib/social/mock/rating-response.mock.ts
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,34 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 Alfresco Software, Ltd. | ||
* | ||
* 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. | ||
*/ | ||
|
||
export const ratingOneMock = { | ||
entry: { | ||
myRating: '1', | ||
ratedAt: '2017-04-06T14:34:28.061+0000', | ||
id: 'fiveStar', | ||
aggregate: {numberOfRatings: 1, average: 1.0} | ||
} | ||
}; | ||
|
||
export const ratingThreeMock = { | ||
entry: { | ||
myRating: '3', | ||
ratedAt: '2017-04-06T14:36:40.731+0000', | ||
id: 'fiveStar', | ||
aggregate: {numberOfRatings: 1, average: 3.0} | ||
} | ||
}; |
60 changes: 60 additions & 0 deletions
60
lib/content-services/src/lib/social/mock/rating.service.mock.ts
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,60 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 Alfresco Software, Ltd. | ||
* | ||
* 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. | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { RatingEntry } from '@alfresco/js-api'; | ||
import { Observable, of } from 'rxjs'; | ||
import { ratingOneMock, ratingThreeMock } from './rating-response.mock'; | ||
import { RatingServiceInterface } from '../services/rating.service.interface'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class RatingServiceMock implements RatingServiceInterface { | ||
|
||
getRating(nodeId: string, _ratingType: any): Observable<RatingEntry | {}> { | ||
if (nodeId === 'fake-like-node-id') { | ||
return of(ratingOneMock); | ||
} | ||
|
||
return of(ratingThreeMock); | ||
} | ||
|
||
postRating(nodeId: string, _ratingType: string, _vote: any): Observable<RatingEntry | {}> { | ||
if (nodeId === 'ratingOneMock') { | ||
ratingOneMock.entry.aggregate.numberOfRatings = 1; | ||
ratingOneMock.entry.aggregate.average = 1.0; | ||
return of(ratingOneMock); | ||
} | ||
|
||
ratingThreeMock.entry.aggregate.numberOfRatings = 1; | ||
ratingThreeMock.entry.aggregate.average = 1.0; | ||
return of(ratingThreeMock); | ||
} | ||
|
||
deleteRating(nodeId: string, _ratingType: any): Observable<any> { | ||
if (nodeId === 'ratingOneMock') { | ||
ratingOneMock.entry.aggregate.numberOfRatings = 0; | ||
ratingOneMock.entry.aggregate.average = 0; | ||
return of(ratingOneMock); | ||
} | ||
|
||
ratingThreeMock.entry.aggregate.numberOfRatings = 0; | ||
ratingThreeMock.entry.aggregate.average = 0; | ||
return of(ratingThreeMock); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/content-services/src/lib/social/services/rating.service.interface.ts
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,26 @@ | ||
/*! | ||
* @license | ||
* Copyright 2019 Alfresco Software, Ltd. | ||
* | ||
* 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. | ||
*/ | ||
|
||
import { RatingEntry } from '@alfresco/js-api'; | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface RatingServiceInterface { | ||
|
||
getRating(nodeId: string, ratingType: any): Observable<RatingEntry | {}>; | ||
postRating(nodeId: string, ratingType: string, vote: any): Observable<RatingEntry | {}>; | ||
deleteRating(nodeId: string, ratingType: any): Observable<any>; | ||
} |
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
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