-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add ellipsis to shortened overivew
Also improved tests to make it easier to follow what's going on.
- Loading branch information
Showing
2 changed files
with
86 additions
and
23 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,24 +1,63 @@ | ||
import { getMovieInfo } from '@/actions/movie/get-movie-info.js'; | ||
import { | ||
getMovieInfo, | ||
getMovieOverview, | ||
} from '@/actions/movie/get-movie-info.js'; | ||
import { generateMovie } from '@/fakers/moviedb.js'; | ||
|
||
test('should return the movie info', () => { | ||
const movie = generateMovie({ | ||
releaseDate: new Date('1986-05-16'), | ||
describe('getMovieOverview', () => { | ||
test('should return the overview if it is less than 350 characters', () => { | ||
const overview = 'a'.repeat(349); | ||
const result = getMovieOverview(overview); | ||
|
||
expect(result).toBe(overview); | ||
}); | ||
|
||
const movieUrl = `https://www.themoviedb.org/movie/${movie.id}`; | ||
const result = getMovieInfo(movie); | ||
test('should return the overview truncated to 350 characters', () => { | ||
const overview = 'a'.repeat(351); | ||
const result = getMovieOverview(overview); | ||
|
||
expect(result).toContain(movie.overview); | ||
expect(result).toContain(movie.title); | ||
expect(result).toContain(movieUrl); | ||
expect(result).toContain('#movie #film #cinema'); | ||
expect(result).toBe('a'.repeat(347) + '...'); | ||
}); | ||
}); | ||
|
||
test('should trim the overview to 350 characters', () => { | ||
const movie = generateMovie(); | ||
movie.overview = 'a'.repeat(500); | ||
describe('getMovieInfo', () => { | ||
test('contains the movie title and release date', () => { | ||
const movie = generateMovie({ | ||
releaseDate: new Date('1986-05-16'), | ||
}); | ||
const result = getMovieInfo(movie); | ||
|
||
expect(result).toContain(movie.title); | ||
expect(result).toContain('May 16th, 1986'); | ||
}); | ||
|
||
test('contains the entry URL', () => { | ||
const movie = generateMovie(); | ||
const result = getMovieInfo(movie); | ||
|
||
expect(result).toContain(`https://www.themoviedb.org/movie/${movie.id}`); | ||
}); | ||
|
||
test('contains post tags', () => { | ||
const movie = generateMovie(); | ||
const result = getMovieInfo(movie); | ||
|
||
const result = getMovieInfo(movie); | ||
expect(result).toContain('a'.repeat(350)); | ||
expect(result).toContain('#movie #film #cinema'); | ||
}); | ||
|
||
test('contains the full overview if it is less than 350 characters', () => { | ||
const movie = generateMovie(); | ||
movie.overview = 'a'.repeat(300); | ||
const result = getMovieInfo(movie); | ||
|
||
expect(result).toContain(movie.overview); | ||
}); | ||
|
||
test('contains the truncated overview if it is more than 350 characters', () => { | ||
const movie = generateMovie(); | ||
movie.overview = 'a'.repeat(351); | ||
const result = getMovieInfo(movie); | ||
|
||
expect(result).toContain('a'.repeat(347) + '...'); | ||
}); | ||
}); |
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