Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe('Test "other regions" functions', () => {
- const titles = [
- {
- scrapedText: 'Byggmester Bob - Kan det Fikses? [SLES-03563]',
- expect: 'Byggmester Bob - Kan det Fikses?',
- }, {
- scrapedText: 'A Sangue Freddo [SCES-02152 & SCES-12152]',
- expect: 'A Sangue Freddo',
- }, {
- scrapedText: 'Asterix [All your Cartoon Favourites Version] (SLES-01748)',
- expect: 'Asterix [All your Cartoon Favourites Version]',
- }, {
- scrapedText: 'Asterix (All your Cartoon Favourites Version) [SLES-01748]',
- expect: 'Asterix (All your Cartoon Favourites Version)',
- }, {
- scrapedText: 'Final Fantasy Collection Anniversary Package [SLPS-01945~7]',
- expect: 'Final Fantasy Collection Anniversary Package',
- }, {
- scrapedText: 'Final Fantasy VIII [SLES-02084, SLES-12084, SLES-22084 & SLES-32084]',
- expect: 'Final Fantasy VIII',
- }, {
- scrapedText: 'Final Fantasy VIII [Ultimate Hits] [SLPM-87384~7]',
- expect: 'Final Fantasy VIII [Ultimate Hits]',
- },
- ];
- new Using(titles).describe('check response from getTitleFromOtherRegion():', (test: any) => {
- it(` check title for: ${test.scrapedText}`, () => {
- const returnedTitle = game.getTitleFromOtherRegion(test.scrapedText);
- expect(returnedTitle).toBe(test.expect);
- });
- });
- });
- // somewhere on game.class.ts
- private getTitleFromOtherRegion(gameTitle: string): string {
- // let title = gameTitle.remove('img').text();
- let title = gameTitle;
- title = title.trim();
- title = this.getLastCharacterOfString(title, '-') ? title.slice(0, -1) : title;
- title = title.trim();
- const titleRegexp = /\(([^)]+)\)/gm.exec(title);
- const titleRegexpSquare: string[] | null = title.match(/\[([^\]]+)\]/gm);
- if (titleRegexpSquare && titleRegexp) {
- }
- if (titleRegexpSquare && titleRegexp === null) {
- if (titleRegexpSquare.length > 1) {
- return `${title.split(titleRegexpSquare[0])[0].trim()} ${titleRegexpSquare[0]}`;
- }
- return title.split(titleRegexpSquare[0])[0].trim();
- }
- return title;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement