Skip to content

Commit

Permalink
Merge pull request #89 from SensCritique/feat/add-rating-disney
Browse files Browse the repository at this point in the history
feat(provider): possibilité d'utiliser l'extension sur disney+ / les notes senscritique sont visible sur plus de produits
  • Loading branch information
audreylamy authored Feb 14, 2023
2 parents 7a63f89 + 3ecd162 commit cae262a
Show file tree
Hide file tree
Showing 61 changed files with 2,053 additions and 840 deletions.
35 changes: 25 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
// eslint-disable-next-line no-undef
module.exports = {
env: {
browser: true,
es2020: true,
jest: true
jest: true,
},
globals: {
chrome: true
chrome: true,
browser: true,
},
extends: [
'standard'
],
parser: "@typescript-eslint/parser",
plugins: [
'@typescript-eslint'
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
parserOptions: {
ecmaVersion: 11,
sourceType: 'module'
sourceType: 'module',
},
rules: {
"no-unused-vars": "off"
}
'no-unused-vars': 'error',
'no-console': ['error', { allow: ['error'] }],
semi: ['error', 'never'],
'comma-dangle': 'off',
'no-underscore-dangle': [2, { allowAfterThis: true }],
'prettier/prettier': [
'error',
{
trailingComma: 'es5',
singleQuote: true,
semi: false,
printWidth: 80,
},
],
},
}
1 change: 1 addition & 0 deletions CONTRIB.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All the code is the same for Chrome and Firefox except for the event system whic
# Workflow
##### Content_script
- Netflix: Fetch video info (name)
- Disney: Fetch video info (name)
##### Background
- SensCritique (HTTP): Fetch video ID and Type
- SensCritique (HTTP): Fetch video note
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
${RUN_NODE} npm install
.PHONY: test
test:
${RUN_NODE} npm test
${RUN_NODE} npm test ${FILE}
.PHONY: sh
sh:
${RUN_NODE} sh
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<img src="/images/logo-128.png" height=50/>

# SensCritique-extension
Permet d'avoir un score SensCritique sur les pages de descriptions Netflix
Permet d'avoir un score SensCritique sur les pages de descriptions __[Netflix](https://www.netflix.com)__ et __[Disney+](https://www.disneyplus.com)__

## Fonctionnement du score
Le score correspond à la note globale des spectateurs SensCritique en pourcentage plutôt qu'une note sur 5 ou sur 10.
Expand All @@ -15,11 +15,18 @@ Le score est cliquable et renvoie directement vers la page de la critique du fil

Si le score n'est pas trouvé, un point d'interrogation sera affiché. L'indicateur est cliquable et renvoie vers la page de recherche de SensCritique pré-remplie.

# Screenshots
# Extension disponible sur
## __[NETFLIX](https://www.netflix.com)__

![](images/screenshots/1.png)
![](images/screenshots/2.png)
![](images/screenshots/3.png)
![](images/screenshots/netflix/1.png)
![](images/screenshots/netflix/2.png)
![](images/screenshots/netflix/3.png)

## __[DISNEY+](https://www.disneyplus.com)__

![](images/screenshots/disney/1.png)
![](images/screenshots/disney/2.png)
![](images/screenshots/disney/3.png)

# Téléchargement
- [Chrome](https://chrome.google.com/webstore/detail/senscritique/enficnaijgnbdbdcpbplmbnhoenehllk?hl=fr)
Expand Down
6 changes: 3 additions & 3 deletions __tests__/dom/RatingFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test, expect } from '@jest/globals'
import RatingFactory from '../../src/dom/RatingFactory'
import { Service } from '../../src/http/Service'
import { Service } from '../../src/enum/Service'
import { SensCritiqueRating } from '../../src/dom/SensCritiqueRating'

test('It should create an SensCritiqueRating instance', () => {
const sensCritiqueRating = (new RatingFactory()).create(Service.SENSCRITIQUE, {
const sensCritiqueRating = new RatingFactory().create(Service.SENSCRITIQUE, {
name: 'test',
redirect: ''
redirect: '',
})
expect(sensCritiqueRating).toBeInstanceOf(SensCritiqueRating)
})
4 changes: 3 additions & 1 deletion __tests__/dom/Ratings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ test('It should render one div for SensCritique', () => {

expect(ratingsDiv).not.toBeNull()
expect(ratingsDiv.childNodes.length).toBe(1)
expect((ratingsDiv.childNodes[0] as Element).classList).toContain('senscritique_extension_XXX')
expect((ratingsDiv.childNodes[0] as Element).classList).toContain(
'senscritique_extension_XXX'
)
})
12 changes: 6 additions & 6 deletions __tests__/dom/SensCritiqueRating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const successDataset = [
['8.6', 86],
['10', 100],
['0,1', 1],
['0', 0]
['0', 0],
]
test.each(successDataset)(
'It should convert SensCritique note (%s) in percentage (%s)',
(sensCritiqueNote, expected) => {
const sensCritiqueRating = new SensCritiqueRating({
name: 'test',
redirect: ''
redirect: '',
})
const sensCritiqueExtensionScore =
sensCritiqueRating.ratingInPercent(sensCritiqueNote)
Expand All @@ -26,14 +26,14 @@ const errorDataset = [
['2,,5', null],
[null, null],
[undefined, null],
['11', null]
['11', null],
]
test.each(errorDataset)(
'It should convert wrong SensCritique note (%s) to null',
(sensCritiqueNote, expected) => {
const sensCritiqueRating = new SensCritiqueRating({
name: 'test',
redirect: ''
redirect: '',
})
const sensCritiqueExtensionScore =
sensCritiqueRating.ratingInPercent(sensCritiqueNote)
Expand All @@ -46,7 +46,7 @@ test('It should create instance with rights rating', () => {
const sensCritiqueRating = new SensCritiqueRating({
rating: '7',
name: 'test',
redirect: ''
redirect: '',
})

expect(sensCritiqueRating.rating).toBe('7')
Expand All @@ -57,7 +57,7 @@ test('It should render node with rights info', () => {
rating: '8,5',
redirect: 'https://google.fr',
hashId: 'XXX',
name: 'test'
name: 'test',
})
const sensCritiqueRatingRendered = sensCritiqueRating.render()

Expand Down
24 changes: 24 additions & 0 deletions __tests__/global/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
firefox: {
runtime: {
onMessage: {
addListener: jest.fn()
},
},
tabs: {
query: jest.fn(),
sendMessage: jest.fn()
}
},
chrome: {
runtime: {
onMessage: {
addListener: jest.fn()
},
},
tabs: {
query: jest.fn(),
sendMessage: jest.fn()
}
}
}
74 changes: 74 additions & 0 deletions __tests__/helper/ComparatorHelper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { test, expect } from '@jest/globals'
import browser from '../global/browser'
Object.assign(global, browser)
import { compare } from '../../src/helper/ComparatorHelper'
import {
matchByTitleAndYearDataset,
matchByMovieAndYearDataset,
matchYearAndSeasonIfTvShowDataset,
matchByTitleAndSeasonIfTvShowDataset,
notMatchByTypeOrProviderDataset,
notMatchByTitleAndYearIfMovieDataset,
notMatchByTitleYearAndSeasonsIfTvShowDataset,
} from '../../src/dataset/CamparatorHelper'
jest.mock('../../src/background')

describe('Test products matching with compare()', () => {
test.each(matchByTitleAndYearDataset)(
'It should return video infos if title and year match',
async (senscritiqueProduct, platformProduct, expectedVideoInfo) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toEqual(expectedVideoInfo)
}
)

test.each(matchByMovieAndYearDataset)(
'It should return video infos if the product is a movie and year match',
async (senscritiqueProduct, platformProduct, expectedVideoInfo) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toEqual(expectedVideoInfo)
}
)

test.each(matchYearAndSeasonIfTvShowDataset)(
'It should return video infos if the product is a tvShow and year, season match',
async (senscritiqueProduct, platformProduct, expectedVideoInfo) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toEqual(expectedVideoInfo)
}
)

test.each(matchByTitleAndSeasonIfTvShowDataset)(
'It should return video infos if the product is a tvShow and title, season match',
async (senscritiqueProduct, platformProduct, expectedVideoInfo) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toEqual(expectedVideoInfo)
}
)
})

describe('Test products does not match with compare()', () => {
test.each(notMatchByTypeOrProviderDataset)(
'It should return null if type or provider not match',
async (senscritiqueProduct, platformProduct) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toBeNull()
}
)

test.each(notMatchByTitleAndYearIfMovieDataset)(
'It should return null if the product is a movie but the title and year not match',
async (senscritiqueProduct, platformProduct) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toBeNull()
}
)

test.each(notMatchByTitleYearAndSeasonsIfTvShowDataset)(
'It should return null if the product is a tvShow but title, year and season not match',
async (senscritiqueProduct, platformProduct) => {
const videoInfo = await compare(senscritiqueProduct, platformProduct)
expect(videoInfo).toBeNull()
}
)
})
76 changes: 76 additions & 0 deletions __tests__/http/LevenshteinHelper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
levenshteinDistance,
shortStringMatchedLevenshtein,
longStringMatchedLevenshtein,
matchedWithLevenshtein,
} from '../../src/helper/LevenshteinHelper'
import { test, expect } from '@jest/globals'

describe('levenshteinDistance tests', () => {
test('It should render 0', () => {
expect(levenshteinDistance('mike', 'mike')).toBe(0)
})

test('It should render 2', () => {
expect(levenshteinDistance('mike ', 'mike 45')).toBe(2)
})

test('It should render 3', () => {
expect(levenshteinDistance('test test test', 'test test test 35')).toBe(3)
})
})

describe('shortStringMatchedLevenshtein tests', () => {
test('It should render true', () => {
expect(shortStringMatchedLevenshtein('mike', 0)).toBeTruthy()
})

test('It should render false', () => {
expect(shortStringMatchedLevenshtein('mike 36', 3)).toBeFalsy()
})

test('It should render false', () => {
expect(shortStringMatchedLevenshtein('test test test', 5)).toBeFalsy()
})
})

describe('longStringMatchedLevenshtein tests', () => {
test('It should render false', () => {
expect(longStringMatchedLevenshtein('mike', 0)).toBeFalsy()
})

test('It should render false', () => {
expect(longStringMatchedLevenshtein('mike 36', 3)).toBeFalsy()
})

test('It should render false', () => {
expect(longStringMatchedLevenshtein('test test test', 5)).toBeFalsy()
})

test('It should render true', () => {
expect(longStringMatchedLevenshtein('test test test', 4)).toBeTruthy()
})
})

describe('matchedWithLevenshtein tests', () => {
test('It should render false', () => {
expect(
matchedWithLevenshtein('Andor', 'Vader: A Star Wars Theory Fan Series')
).toBeFalsy()
})
test('It should render false', () => {
expect(matchedWithLevenshtein('Andor', 'Andor')).toBeTruthy()
})
test('It should render false', () => {
expect(matchedWithLevenshtein('Andor', 'Andors')).toBeTruthy()
})
test('It should render false', () => {
expect(matchedWithLevenshtein('Andor', 'Andors 34')).toBeFalsy()
})
test('It should render false', () => {
expect(matchedWithLevenshtein('Andor', '')).toBeFalsy()
})
test('It should render false', () => {
expect(matchedWithLevenshtein('', 'Andor')).toBeFalsy()
})
})
28 changes: 28 additions & 0 deletions __tests__/http/ProviderHelper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { matchedProviders } from '../../src/helper/ProviderHelper'

const matchByProvider = [
[['Netflix'], ['netflix']],
[['Netflix+', 'Disney'], ['netflix']],
[['test_Netflix+', 'amazon'], ['netflix']],
]

const notMatchByProvider = [
[[''], ['netflix']],
[['Disney'], ['netflix']],
]

describe('matchedProviders tests', () => {
test.each(matchByProvider)(
'It should be true',
async (senscritiqueProviders, platformName) => {
expect(matchedProviders(senscritiqueProviders, platformName)).toBeTruthy()
}
)

test.each(notMatchByProvider)(
'It should be false',
async (senscritiqueProviders, platformName) => {
expect(matchedProviders(senscritiqueProviders, platformName)).toBeFalsy()
}
)
})
Loading

0 comments on commit cae262a

Please sign in to comment.