Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {assert, expect} from 'chai'; |
| 6 | import {IssueWizardPersona, IssueCategory, CustomQuestionType} from '../issue-wizard/IssueWizardTypes.tsx'; |
| 7 | import {GetCategoriesByPersona, GetQuestionsByCategory, buildIssueDescription, getChromeVersion} from '../issue-wizard/IssueWizardUtils.tsx'; |
| 8 | |
| 9 | describe('IssueWizardUtils', () => { |
| 10 | it('generate the issue categories to user persona map', () => { |
| 11 | const categories: IssueCategory[]= [ |
| 12 | { |
| 13 | name: 't1', |
| 14 | description: 'd1', |
| 15 | persona: IssueWizardPersona.EndUser, |
| 16 | enabled: true, |
| 17 | }, |
| 18 | { |
| 19 | name: 't2', |
| 20 | description: 'd2', |
| 21 | persona: IssueWizardPersona.EndUser, |
| 22 | enabled: false, |
| 23 | }, |
| 24 | ]; |
| 25 | |
| 26 | const categoriesByPersonaMap = GetCategoriesByPersona(categories); |
| 27 | const validCategories = categoriesByPersonaMap.get(IssueWizardPersona.EndUser); |
| 28 | |
| 29 | assert.equal(validCategories?.length, 1); |
| 30 | assert.equal(validCategories[0].name, 't1'); |
| 31 | assert.equal(validCategories[0].description, 'd1'); |
| 32 | }); |
| 33 | |
| 34 | it('generate custom questions to issue categories map', () => { |
| 35 | const categories: IssueCategory[]= [ |
| 36 | { |
| 37 | name: 't1', |
| 38 | description: 'd1', |
| 39 | persona: IssueWizardPersona.EndUser, |
| 40 | enabled: true, |
| 41 | customQuestions: [ |
| 42 | { |
| 43 | type: CustomQuestionType.Text, |
| 44 | question: 'q1', |
| 45 | } |
| 46 | ] |
| 47 | }, |
| 48 | ]; |
| 49 | |
| 50 | const questionsByCategoryMap = GetQuestionsByCategory(categories); |
| 51 | const questions = questionsByCategoryMap.get('t1'); |
| 52 | |
| 53 | assert.equal(questions?.length, 1); |
| 54 | assert.equal(questions[0].question, 'q1'); |
| 55 | }); |
| 56 | |
| 57 | it('create issue description', () => { |
| 58 | const description = buildIssueDescription('reproduce', 'description', 'comments', 'Mac', 'Chrome'); |
| 59 | expect(description).to.contains('Steps to reproduce the problem:'); |
| 60 | expect(description).to.contains('Problem Description:'); |
| 61 | expect(description).to.contains('Additional Comments:'); |
| 62 | }); |
| 63 | |
| 64 | it('test the chrome version regex match', () => { |
| 65 | const navigatorMock = { |
| 66 | userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36' |
| 67 | }; |
| 68 | Object.defineProperty(window, 'navigator', { |
| 69 | value: navigatorMock |
| 70 | }); |
| 71 | const chrome_version = getChromeVersion(); |
| 72 | assert(chrome_version, '98.0.4758.109'); |
| 73 | }); |
| 74 | }); |