Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
This commit is contained in:
Alexander Piskun 2024-09-02 20:45:45 +03:00 коммит произвёл GitHub
Родитель e3e88610e3
Коммит 9d18b41a3f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 16 добавлений и 15 удалений

Просмотреть файл

@ -76,16 +76,16 @@ export function convertRating(rating: IApiRating, lang: string): IRating {
}
const translation = rating.translations[lang] || {comment: ''};
return {
id: rating.id,
appeal: rating.appeal,
comment: translation.comment,
fullUserName: fullName.trim(),
id: rating.id,
ratedAt: rating.ratedAt,
rating: {
name: createRatingName(rating.rating),
value: rating.rating,
},
relativeRatedAt: rating.relativeRatedAt,
appeal: rating.appeal,
};
}
@ -124,22 +124,22 @@ export function findUserComment(result: IRatings): Maybe<string> {
export function appealRating(url: string, token: string, rating: IRating, appeal = true) {
return pageRequest({
url,
data: {
appeal: +appeal,
comment_id: rating.id,
},
method: HttpMethod.POST,
url,
}, token);
}
export function deleteRating(url: string, token: string, rating: IRating, admin = false) {
return pageRequest({
url,
data: {
decision: +!admin,
comment_id: rating.id,
decision: +!admin,
},
method: HttpMethod.POST,
url,
}, token);
}

Просмотреть файл

@ -8,6 +8,7 @@ describe('Ratings and comments', () => {
lastName: 'jones',
};
const data = [{
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:37.168975Z',
rating: 0.5,
@ -18,8 +19,8 @@ describe('Ratings and comments', () => {
},
},
user,
appeal: false,
}, {
appeal: true,
id: 66,
ratedAt: '2017-03-22T16:54:37.168975Z',
rating: 0.5,
@ -30,8 +31,8 @@ describe('Ratings and comments', () => {
},
},
user,
appeal: true,
}, {
appeal: true,
id: 66,
ratedAt: '2017-03-22T16:54:37.168975Z',
rating: 0.5,
@ -42,15 +43,14 @@ describe('Ratings and comments', () => {
},
},
user,
appeal: true,
}, {
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:37.168975Z',
rating: 0.5,
relativeRatedAt: '',
translations: {},
user,
appeal: false,
}];
const result = filterEmptyComments(data, 'de');
expect(result.length).toBe(1);
@ -58,6 +58,7 @@ describe('Ratings and comments', () => {
it('convert and parse ratings', () => {
const data = {
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:37.168975Z',
rating: 0.5,
@ -71,7 +72,6 @@ describe('Ratings and comments', () => {
firstName: ' Tom',
lastName: 'Jones',
},
appeal: false,
};
const result = convertRating(data, 'de');
@ -84,6 +84,7 @@ describe('Ratings and comments', () => {
it('convert and parse ratings with empty user names', () => {
const data = {
appeal: true,
id: 66,
ratedAt: '2017-03-22T16:54:32.168975Z',
rating: 1.0,
@ -97,7 +98,6 @@ describe('Ratings and comments', () => {
firstName: '',
lastName: ' ',
},
appeal: true,
};
const result = convertRating(data, 'de');
@ -109,6 +109,7 @@ describe('Ratings and comments', () => {
it('convert and parse bad rating', () => {
const data = {
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:32.168975Z',
rating: 0.0,
@ -122,7 +123,6 @@ describe('Ratings and comments', () => {
firstName: '',
lastName: ' ',
},
appeal: false,
};
const result = convertRating(data, 'de');

Просмотреть файл

@ -18,14 +18,14 @@ export function renderRating(template: HTMLTemplateElement,
}
export function renderRatingActions(template: HTMLTemplateElement,
rating: IRating, lang: string, fallbackLang: string): HTMLElement {
rating: IRating, lang: string, fallbackLang: string): HTMLElement {
const root = render(template, {});
if (!rating.appeal) {
// Remove these buttons from template if comment has no appeal for spam
const buttonsToRemove = [
'button.comment-actions__delete',
'button.comment-actions__appeal_cancel',
'button.comment-actions__appeal_cancel_admin'
'button.comment-actions__appeal_cancel_admin',
];
buttonsToRemove.forEach((buttonSelector) => {
try {

Просмотреть файл

@ -8,6 +8,7 @@
"max-line-length": [true, 120],
"prefer-const": true,
"no-console": ["log", {"allow": ["warn", "error"]}],
"no-shadowed-variable": false
"no-shadowed-variable": false,
"ordered-imports": false
}
}