From c86b46fee2c4c03f8cc72e6987174a6ba952b09f Mon Sep 17 00:00:00 2001 From: Louis Bompart Date: Wed, 8 Jul 2020 06:23:51 -0400 Subject: [PATCH] chore(SFINT-3308): Update prettier and ran it --- .prettierrc.js | 8 +- config/karma.config.js | 20 ++-- config/webpack.config.js | 24 ++--- config/webpack.config.karma.js | 22 ++--- cypress/integration/user_actions.spec.ts | 20 +--- cypress/plugins/index.js | 14 +-- package-lock.json | 6 +- package.json | 2 +- pages/action_button.html | 2 +- pages/attached_result.html | 16 +-- pages/copy_to_clipboard.html | 2 +- pages/toggle_action_button.html | 2 +- pages/user_actions.html | 8 +- scripts/css.js | 2 +- scripts/dev.server.js | 4 +- scripts/setup.js | 9 +- scripts/svg.js | 11 +-- src/components/ActionButton/ActionButton.ts | 2 +- .../ActionButton/ToggleActionButton.ts | 8 +- src/components/AttachResult/AttachResult.ts | 26 ++--- src/components/AttachResult/Events.ts | 2 +- src/components/AttachResult/Strings.ts | 2 +- .../CopyToClipboard/CopyToClipboard.ts | 6 +- src/components/CopyToClipboard/Strings.ts | 2 +- src/components/ResultAction/ResultAction.ts | 2 +- src/components/ResultsFilter/Events.ts | 2 +- src/components/ResultsFilter/ResultsFilter.ts | 16 +-- src/components/ResultsFilter/Strings.ts | 2 +- .../UserActions/ClickedDocumentList.ts | 28 +++--- src/components/UserActions/ExpandableList.ts | 6 +- src/components/UserActions/QueryList.ts | 16 +-- .../UserActions/ResponsiveUserActions.ts | 2 +- src/components/UserActions/Strings.ts | 2 +- src/components/UserActions/UserActions.ts | 36 +++---- src/components/UserActions/UserActivity.ts | 20 ++-- src/components/ViewedByCustomer/Strings.ts | 2 +- .../ViewedByCustomer/ViewedByCustomer.ts | 2 +- src/models/UserProfileModel.ts | 18 ++-- src/rest/UserProfilingEndpoint.ts | 8 +- src/utils/events.ts | 2 +- src/utils/time.ts | 10 +- src/utils/translation.ts | 4 +- tests/Utils/time.spec.ts | 2 +- tests/Utils/translation.spec.ts | 12 +-- .../ActionButton/ActionButton.spec.ts | 12 +-- .../ActionButton/ToggleActionButton.spec.ts | 4 +- .../AttachResult/AttachResult.spec.ts | 42 ++++---- tests/components/CopyPaste/CopyPaste.spec.ts | 2 +- .../ResultAction/ResultAction.spec.ts | 2 +- .../ResultsFilter/ResultsFilter.spec.ts | 6 +- .../UserActions/ClickedDocumentList.spec.ts | 36 +++---- .../UserActions/ExpandableList.spec.ts | 10 +- .../components/UserActions/QueryList.spec.ts | 32 +++--- .../UserActions/ResponsiveUserActions.spec.ts | 12 +-- .../UserActions/UserActions.spec.ts | 80 +++++++-------- .../UserActions/UserActivity.spec.ts | 52 +++++----- .../ViewedByCustomer/ViewedByCustomer.spec.ts | 2 +- tests/models/UserProfilingModel.spec.ts | 98 ++++++++++--------- tests/rest/UserProfilingEndpoint.spec.ts | 28 +++--- tests/utils.ts | 10 +- 60 files changed, 421 insertions(+), 419 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index f778b818..dfb80808 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -9,8 +9,8 @@ module.exports = { { files: '*.json', options: { - singleQuote: false - } - } - ] + singleQuote: false, + }, + }, + ], }; diff --git a/config/karma.config.js b/config/karma.config.js index fd64e971..22c05d31 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -10,19 +10,19 @@ var configuration = { // Both CoveoJsSearch and CoveoJsSearchTests are included as externals, so you need include them in your testing environment. { pattern: '../node_modules/coveo-search-ui/bin/js/CoveoJsSearch.js', - watched: false + watched: false, }, { pattern: '../node_modules/coveo-search-ui-tests/bin/js/CoveoJsSearchTests.js', - watched: false + watched: false, }, { pattern: '../src/Index.ts' }, - { pattern: '../tests/**/*.spec.ts' } + { pattern: '../tests/**/*.spec.ts' }, ], preprocessors: { // Builds both the components and the tests. '../src/**/*.ts': ['webpack'], - '../tests/**/*.spec.ts': ['webpack'] + '../tests/**/*.spec.ts': ['webpack'], }, // Required for Chrome, if you use it. mime: { 'text/x-typescript': ['ts'] }, @@ -31,22 +31,22 @@ var configuration = { coverageIstanbulReporter: { dir: path.resolve('./bin/coverage'), reports: ['html', 'cobertura', 'json', 'lcov', 'text-summary'], - fixWebpackSourcePaths: true + fixWebpackSourcePaths: true, }, webpack: webpackConfig, webpackMiddleware: { stats: 'minimal', - logLevel: 'warn' + logLevel: 'warn', }, browsers: ['ChromeHeadlessNoSandbox'], customLaunchers: { ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', - flags: ['--no-sandbox'] - } - } + flags: ['--no-sandbox'], + }, + }, }; -module.exports = function(config) { +module.exports = function (config) { config.set(configuration); }; diff --git a/config/webpack.config.js b/config/webpack.config.js index 1c72eded..138c882e 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -3,24 +3,24 @@ const path = require('path'); module.exports = { mode: 'development', entry: { - CoveoJsSearchExtensions: './src/Index' + CoveoJsSearchExtensions: './src/Index', }, output: { path: path.resolve('./bin/commonjs'), filename: `[name].js`, libraryTarget: 'umd', library: 'CoveoExtension', - publicPath: '/commonjs' + publicPath: '/commonjs', }, externals: [ { // Defines the module "coveo-search-ui" as external, "Coveo" is defined in the global scope. // This requires you to load the original CoveoJsSearch.js file in your page. - 'coveo-search-ui': 'Coveo' - } + 'coveo-search-ui': 'Coveo', + }, ], resolve: { - extensions: ['.js', '.ts'] + extensions: ['.js', '.ts'], }, devtool: 'source-map', module: { @@ -31,17 +31,17 @@ module.exports = { options: { configFile: path.resolve('./config/tsconfig.json'), compilerOptions: { - target: 'es5' - } - } + target: 'es5', + }, + }, }, { test: /\.svg$/, loader: 'raw-loader', - options: {} - } - ] + options: {}, + }, + ], }, plugins: [], - bail: true + bail: true, }; diff --git a/config/webpack.config.karma.js b/config/webpack.config.karma.js index 79f82400..8d245107 100644 --- a/config/webpack.config.karma.js +++ b/config/webpack.config.karma.js @@ -9,7 +9,7 @@ webpackConfig.module.rules = [ test: /\.ts$/, use: [ { - loader: 'ts-es5-istanbul-coverage' + loader: 'ts-es5-istanbul-coverage', }, { loader: 'ts-loader', @@ -19,16 +19,16 @@ webpackConfig.module.rules = [ module: 'commonjs', inlineSourceMap: true, sourceMap: undefined, - outDir: undefined - } - } - } - ] + outDir: undefined, + }, + }, + }, + ], }, { test: /\.svg$/, loader: 'raw-loader', - options: {} + options: {}, }, { enforce: 'post', @@ -36,13 +36,13 @@ webpackConfig.module.rules = [ loader: 'istanbul-instrumenter-loader', exclude: path.resolve('tests/'), query: { - esModules: true - } - } + esModules: true, + }, + }, ]; webpackConfig.externals.push({ - 'coveo-search-ui-tests': 'CoveoJsSearchTests' + 'coveo-search-ui-tests': 'CoveoJsSearchTests', }); /** diff --git a/cypress/integration/user_actions.spec.ts b/cypress/integration/user_actions.spec.ts index b25e8fd8..1baf17e9 100644 --- a/cypress/integration/user_actions.spec.ts +++ b/cypress/integration/user_actions.spec.ts @@ -9,9 +9,7 @@ describe('User actions', () => { describe('When I click on the user actions button', () => { beforeEach(() => { cy.get('.coveo-main-section').should('be.visible'); - cy.get('.coveo-user-actions-dropdown-header') - .should('be.visible') - .click(); + cy.get('.coveo-user-actions-dropdown-header').should('be.visible').click(); }); it('should hide user actions panel when I click on the user actions button', () => { @@ -26,25 +24,17 @@ describe('User actions', () => { it('should display user activity', () => { cy.get('.CoveoUserActivity').should('be.visible'); - cy.get('.coveo-activity > .coveo-search') - .should('be.visible') - .should('contain', 'some_query'); + cy.get('.coveo-activity > .coveo-search').should('be.visible').should('contain', 'some_query'); - cy.get('.coveo-activity > .coveo-click') - .should('be.visible') - .should('contain', 'some_document_title'); + cy.get('.coveo-activity > .coveo-click').should('be.visible').should('contain', 'some_document_title'); }); it('should display user clicked document', () => { - cy.get('.CoveoClickedDocumentList') - .should('be.visible') - .should('contain', 'some_document_title'); + cy.get('.CoveoClickedDocumentList').should('be.visible').should('contain', 'some_document_title'); }); it('should display user queries', () => { - cy.get('.CoveoQueryList') - .should('be.visible') - .should('contain', 'some_query'); + cy.get('.CoveoQueryList').should('be.visible').should('contain', 'some_query'); }); }); }); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index e732375c..9b556e6d 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -1,20 +1,20 @@ const wp = require('@cypress/webpack-preprocessor'); -module.exports = on => { +module.exports = (on) => { const options = { webpackOptions: { resolve: { - extensions: ['.ts', '.tsx', '.js'] + extensions: ['.ts', '.tsx', '.js'], }, module: { rules: [ { test: /\.tsx?$/, loader: 'ts-loader', - options: { transpileOnly: true } - } - ] - } - } + options: { transpileOnly: true }, + }, + ], + }, + }, }; on('file:preprocessor', wp(options)); }; diff --git a/package-lock.json b/package-lock.json index 832d8a36..eab93b99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11176,9 +11176,9 @@ "dev": true }, "prettier": { - "version": "1.16.4", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.16.4.tgz", - "integrity": "sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", + "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", "dev": true }, "private": { diff --git a/package.json b/package.json index 28181838..329b19b4 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "ncp": "^2.0.0", "node-sass": "^4.13.1", "pre-commit": "^1.2.2", - "prettier": "1.16.4", + "prettier": "2.0.5", "puppeteer": "^2.0.0", "raw-loader": "^1.0.0", "rimraf": "^2.6.3", diff --git a/pages/action_button.html b/pages/action_button.html index 7cda462d..1cb86ff7 100644 --- a/pages/action_button.html +++ b/pages/action_button.html @@ -10,7 +10,7 @@ diff --git a/pages/copy_to_clipboard.html b/pages/copy_to_clipboard.html index 87dac8f2..bd4e7984 100644 --- a/pages/copy_to_clipboard.html +++ b/pages/copy_to_clipboard.html @@ -10,7 +10,7 @@ diff --git a/scripts/css.js b/scripts/css.js index b20aea3c..0f12eef1 100644 --- a/scripts/css.js +++ b/scripts/css.js @@ -5,7 +5,7 @@ let fs = require('fs'); let basePath = './bin/css/'; let result = sass.renderSync({ file: './src/sass/Index.scss', - outFile: `${basePath}CoveoJsSearchExtensions.css` + outFile: `${basePath}CoveoJsSearchExtensions.css`, }); if (!fs.existsSync(basePath)) { diff --git a/scripts/dev.server.js b/scripts/dev.server.js index edb10db4..63bb3e4f 100644 --- a/scripts/dev.server.js +++ b/scripts/dev.server.js @@ -12,6 +12,6 @@ const compiler = webpack(webpackConfig); var server = new WebpackDevServer(compiler, { contentBase: ['bin/', 'node_modules/coveo-search-ui/bin/'], publicPath: '/commonjs', - compress: true + compress: true, }); -server.listen(port, 'localhost', function() {}); +server.listen(port, 'localhost', function () {}); diff --git a/scripts/setup.js b/scripts/setup.js index 282ce57d..4c47e21b 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -3,14 +3,17 @@ const { ncp } = require('ncp'); const { resolve } = require('path'); const { mkdirSync, existsSync } = require('fs'); -const folderToCopy = [{ src: resolve('./pages'), dest: resolve('./bin/pages') }, { src: resolve('./svg'), dest: resolve('./bin/img') }]; +const folderToCopy = [ + { src: resolve('./pages'), dest: resolve('./bin/pages') }, + { src: resolve('./svg'), dest: resolve('./bin/img') }, +]; if (!existsSync(resolve('./bin'))) { mkdirSync(resolve('./bin'), { recursive: true }); } -folderToCopy.forEach(folder => - ncp(folder.src, folder.dest, err => { +folderToCopy.forEach((folder) => + ncp(folder.src, folder.dest, (err) => { if (err) throw err; }) ); diff --git a/scripts/svg.js b/scripts/svg.js index b553cb4b..6159c910 100644 --- a/scripts/svg.js +++ b/scripts/svg.js @@ -4,9 +4,9 @@ const path = require('path'); const xml = require('xml2js'); const builder = new xml.Builder({ renderOpts: { - pretty: false + pretty: false, }, - headless: true + headless: true, }); const parser = new xml.Parser(); @@ -32,11 +32,8 @@ async function replaceSVGImport(line) { const iconFile = path.resolve('./bin/es6/utils/icons.js'); -const contents = fs - .readFileSync(iconFile, { encoding: 'utf8' }) - .split('\n') - .map(replaceSVGImport); +const contents = fs.readFileSync(iconFile, { encoding: 'utf8' }).split('\n').map(replaceSVGImport); -Promise.all(contents).then(data => { +Promise.all(contents).then((data) => { fs.writeFileSync(iconFile, data.join('\n'), { encoding: 'utf8' }); }); diff --git a/src/components/ActionButton/ActionButton.ts b/src/components/ActionButton/ActionButton.ts index e0945f17..d7d09982 100644 --- a/src/components/ActionButton/ActionButton.ts +++ b/src/components/ActionButton/ActionButton.ts @@ -71,7 +71,7 @@ export class ActionButton extends Component { * * This option must be set in JavaScript when initializing the component. */ - click: ComponentOptions.buildCustomOption(s => null, { required: true }) + click: ComponentOptions.buildCustomOption((s) => null, { required: true }), }; constructor(public element: HTMLElement, public options: IActionButtonOptions, public bindings?: IResultsComponentBindings) { diff --git a/src/components/ActionButton/ToggleActionButton.ts b/src/components/ActionButton/ToggleActionButton.ts index 1475d369..4a4e9011 100644 --- a/src/components/ActionButton/ToggleActionButton.ts +++ b/src/components/ActionButton/ToggleActionButton.ts @@ -84,7 +84,7 @@ export class ToggleActionButton extends Component { * * This option is set in JavaScript when initializing the component. */ - click: ComponentOptions.buildCustomOption(s => null), + click: ComponentOptions.buildCustomOption((s) => null), /** * Specifies the handler called when the button is activated. @@ -93,7 +93,7 @@ export class ToggleActionButton extends Component { * * This option is set in JavaScript when initializing the component. */ - activate: ComponentOptions.buildCustomOption(s => null), + activate: ComponentOptions.buildCustomOption((s) => null), /** * Specifies the handler called when the button is deactivated. @@ -102,7 +102,7 @@ export class ToggleActionButton extends Component { * * This option is set in JavaScript when initializing the component. */ - deactivate: ComponentOptions.buildCustomOption(s => null) + deactivate: ComponentOptions.buildCustomOption((s) => null), }; private _isActivated: boolean = false; @@ -154,7 +154,7 @@ export class ToggleActionButton extends Component { { icon: this.options.activateIcon, tooltip: this.options.activateTooltip, - click: () => this.onClick() + click: () => this.onClick(), }, bindings ); diff --git a/src/components/AttachResult/AttachResult.ts b/src/components/AttachResult/AttachResult.ts index 8edb8a49..6f6917d8 100644 --- a/src/components/AttachResult/AttachResult.ts +++ b/src/components/AttachResult/AttachResult.ts @@ -9,7 +9,7 @@ import { IAnalyticsCaseDetachMeta, analyticsActionCauseList, IAnalyticsActionCause, - l + l, } from 'coveo-search-ui'; import { paperclipIcon, wait } from '../../utils/icons'; import { AttachResultEvents, IAttachResultEventArgs } from './Events'; @@ -49,17 +49,17 @@ export class AttachResult extends Component { public static readonly options: IAttachResultOptions = { attachCaption: ComponentOptions.buildStringOption({ - defaultValue: l(`${AttachResult.ID}_Attach`) + defaultValue: l(`${AttachResult.ID}_Attach`), }), detachCaption: ComponentOptions.buildStringOption({ - defaultValue: l(`${AttachResult.ID}_Detach`) + defaultValue: l(`${AttachResult.ID}_Detach`), }), articleIdField: ComponentOptions.buildStringOption({ - defaultValue: 'permanentid' + defaultValue: 'permanentid', }), caseId: ComponentOptions.buildStringOption(), attach: ComponentOptions.buildCustomOption( - name => (result: IQueryResult) => + (name) => (result: IQueryResult) => new Promise((resolve, reject) => { console.log('attached ', result); resolve(); @@ -69,11 +69,11 @@ export class AttachResult extends Component { new Promise((resolve, reject) => { console.log('attached ', result); resolve(); - }) + }), } ), detach: ComponentOptions.buildCustomOption( - name => (result: IQueryResult) => + (name) => (result: IQueryResult) => new Promise((resolve, reject) => { console.log('detached ', result); resolve(); @@ -83,9 +83,9 @@ export class AttachResult extends Component { new Promise((resolve, reject) => { console.log('detached ', result); resolve(); - }) + }), } - ) + ), }; constructor( @@ -165,7 +165,7 @@ export class AttachResult extends Component { this.element.appendChild(this.buttonElement); this.tooltipElement = $$('div', { - className: 'coveo-caption-for-icon' + className: 'coveo-caption-for-icon', }).el; this.element.appendChild(this.tooltipElement); @@ -181,10 +181,10 @@ export class AttachResult extends Component { this.setLoading(true); this.options .isAttached(this.queryResult) - .then(attached => { + .then((attached) => { this.attached = attached; }) - .catch(error => { + .catch((error) => { this.logger.error('Error retrieving initial result attached state.', error); }) .finally(() => { @@ -204,7 +204,7 @@ export class AttachResult extends Component { resultUriHash: this.queryResult.raw.urihash, author: this.queryResult.raw.author, articleID: this.queryResult.raw[this.options.articleIdField], - caseID: this.options.caseId + caseID: this.options.caseId, }; this.usageAnalytics.logCustomEvent(cause, customData, this.element, this.queryResult); diff --git a/src/components/AttachResult/Events.ts b/src/components/AttachResult/Events.ts index e4a07fea..a6e3e188 100644 --- a/src/components/AttachResult/Events.ts +++ b/src/components/AttachResult/Events.ts @@ -6,7 +6,7 @@ import { IQueryResult } from 'coveo-search-ui'; */ export enum AttachResultEvents { Attach = 'attach', - Detach = 'detach' + Detach = 'detach', } /** diff --git a/src/components/AttachResult/Strings.ts b/src/components/AttachResult/Strings.ts index 3cd215e1..5d81438c 100644 --- a/src/components/AttachResult/Strings.ts +++ b/src/components/AttachResult/Strings.ts @@ -2,5 +2,5 @@ import { Translation, Language } from '../../utils/translation'; Translation.register(Language.English, { AttachResult_Attach: 'Attach Result', - AttachResult_Detach: 'Detach Result' + AttachResult_Detach: 'Detach Result', }); diff --git a/src/components/CopyToClipboard/CopyToClipboard.ts b/src/components/CopyToClipboard/CopyToClipboard.ts index 0e1135f4..ad84e730 100644 --- a/src/components/CopyToClipboard/CopyToClipboard.ts +++ b/src/components/CopyToClipboard/CopyToClipboard.ts @@ -39,11 +39,11 @@ export class CopyToClipboard extends ResultAction { static options: ICopyToClipboardOptions = { icon: ComponentOptions.buildStringOption({ defaultValue: copy }), - tooltip: ComponentOptions.buildCustomOption(tooltip => tooltip, { defaultFunction: () => l('CopyToClipboard_copy') }), + tooltip: ComponentOptions.buildCustomOption((tooltip) => tooltip, { defaultFunction: () => l('CopyToClipboard_copy') }), - successTooltip: ComponentOptions.buildCustomOption(tooltip => tooltip, { defaultFunction: () => l('CopyToClipboard_copied') }), + successTooltip: ComponentOptions.buildCustomOption((tooltip) => tooltip, { defaultFunction: () => l('CopyToClipboard_copied') }), - template: ComponentOptions.buildStringOption({ defaultValue: '${title}\n${clickUri}' }) + template: ComponentOptions.buildStringOption({ defaultValue: '${title}\n${clickUri}' }), }; /** diff --git a/src/components/CopyToClipboard/Strings.ts b/src/components/CopyToClipboard/Strings.ts index 4203c583..89253972 100644 --- a/src/components/CopyToClipboard/Strings.ts +++ b/src/components/CopyToClipboard/Strings.ts @@ -2,5 +2,5 @@ import { Translation, Language } from '../../utils/translation'; Translation.register(Language.English, { CopyToClipboard_copy: 'Copy', - CopyToClipboard_copied: 'Copied!' + CopyToClipboard_copied: 'Copied!', }); diff --git a/src/components/ResultAction/ResultAction.ts b/src/components/ResultAction/ResultAction.ts index e69337e7..82e34746 100644 --- a/src/components/ResultAction/ResultAction.ts +++ b/src/components/ResultAction/ResultAction.ts @@ -41,7 +41,7 @@ export abstract class ResultAction extends Component { * See {@link IResultActionOptions.tooltip} * Optional. If no tooltip is provided, the tooltip popup will not appear. */ - tooltip: ComponentOptions.buildStringOption() + tooltip: ComponentOptions.buildStringOption(), }; /** diff --git a/src/components/ResultsFilter/Events.ts b/src/components/ResultsFilter/Events.ts index 3f08028c..53350c88 100644 --- a/src/components/ResultsFilter/Events.ts +++ b/src/components/ResultsFilter/Events.ts @@ -2,7 +2,7 @@ * Events triggered by the **ResultsFilter** component. */ export enum ResultsFilterEvents { - Click = 'click' + Click = 'click', } /** diff --git a/src/components/ResultsFilter/ResultsFilter.ts b/src/components/ResultsFilter/ResultsFilter.ts index b47945f8..824f9c7d 100644 --- a/src/components/ResultsFilter/ResultsFilter.ts +++ b/src/components/ResultsFilter/ResultsFilter.ts @@ -10,7 +10,7 @@ import { QueryStateModel, load, IAttributesChangedEventArg, - l + l, } from 'coveo-search-ui'; import { ResultsFilterEvents, IResultsFilterEventArgs } from './Events'; import './Strings'; @@ -45,14 +45,14 @@ export class ResultsFilter extends Component { static options: IResultsFilterOptions = { text: ComponentOptions.buildStringOption({ - defaultValue: l(`${ResultsFilter.ID}_Label`) + defaultValue: l(`${ResultsFilter.ID}_Label`), }), field: ComponentOptions.buildStringOption({ - defaultValue: 'urihash' + defaultValue: 'urihash', + }), + getValues: ComponentOptions.buildCustomOption((name) => () => new Array(), { + defaultFunction: () => () => new Array(), }), - getValues: ComponentOptions.buildCustomOption(name => () => new Array(), { - defaultFunction: () => () => new Array() - }) }; constructor(public element: HTMLElement, public options: IResultsFilterOptions, public bindings?: IComponentBindings) { @@ -83,12 +83,12 @@ export class ResultsFilter extends Component { const mainSection = $$('div', { className: 'CoveoFacet' }); const headerSection = $$('div', { className: 'coveo-facet-header' }); const labelDiv = $$('label', { - className: 'coveo-facet-value-label-wrapper' + className: 'coveo-facet-value-label-wrapper', }).el; headerSection.append(labelDiv); mainSection.append(headerSection.el); - this.createCheckbox().then(checkbox => { + this.createCheckbox().then((checkbox) => { this.checkbox = checkbox; labelDiv.appendChild(this.checkbox.getElement()); }); diff --git a/src/components/ResultsFilter/Strings.ts b/src/components/ResultsFilter/Strings.ts index 0e89ee77..ad52c21f 100644 --- a/src/components/ResultsFilter/Strings.ts +++ b/src/components/ResultsFilter/Strings.ts @@ -1,5 +1,5 @@ import { Translation, Language } from '../../utils/translation'; Translation.register(Language.English, { - ResultsFilter_Label: 'Filter Results' + ResultsFilter_Label: 'Filter Results', }); diff --git a/src/components/UserActions/ClickedDocumentList.ts b/src/components/UserActions/ClickedDocumentList.ts index 06a778f7..7feacfe4 100644 --- a/src/components/UserActions/ClickedDocumentList.ts +++ b/src/components/UserActions/ClickedDocumentList.ts @@ -8,7 +8,7 @@ import { HtmlTemplate, QueryUtils, l, - get + get, } from 'coveo-search-ui'; import { UserProfileModel, UserAction } from '../../models/UserProfileModel'; import { ExpandableList } from './ExpandableList'; @@ -64,10 +64,10 @@ export class ClickedDocumentList extends Component { static readonly options: IClickedDocumentList = { numberOfItems: ComponentOptions.buildNumberOption({ defaultValue: 4, - min: 1 + min: 1, }), listLabel: ComponentOptions.buildStringOption({ - defaultValue: 'Recent Clicked Documents' + defaultValue: 'Recent Clicked Documents', }), userId: ComponentOptions.buildStringOption({ required: true }), template: ComponentOptions.buildTemplateOption({ @@ -77,10 +77,10 @@ export class ClickedDocumentList extends Component { `, { - layout: 'list' + layout: 'list', } - ) - }) + ), + }), }; private userProfileModel: UserProfileModel; @@ -105,13 +105,13 @@ export class ClickedDocumentList extends Component { this.userProfileModel = get(this.root, UserProfileModel) as UserProfileModel; - this.userProfileModel.getActions(this.options.userId).then(actions => { + this.userProfileModel.getActions(this.options.userId).then((actions) => { this.sortedDocumentsList = actions - .filter(action => action.document && action.type === UserActionType.Click) + .filter((action) => action.document && action.type === UserActionType.Click) .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) .reverse() .reduce(this.filterDuplicatesClickAction, []) - .map(action => { + .map((action) => { action.document.searchInterface = this.searchInterface; return action.document; }); @@ -120,22 +120,22 @@ export class ClickedDocumentList extends Component { } private filterDuplicatesClickAction(accumulator: UserAction[], action: UserAction): UserAction[] { - return !accumulator.find(existing => existing.raw.uri_hash === action.raw.uri_hash) ? [...accumulator, action] : accumulator; + return !accumulator.find((existing) => existing.raw.uri_hash === action.raw.uri_hash) ? [...accumulator, action] : accumulator; } private render() { new ExpandableList(this.element, this.sortedDocumentsList, { maximumItemsShown: this.sortedDocumentsList.length, minimumItemsShown: this.options.numberOfItems, - transform: result => { + transform: (result) => { QueryUtils.setStateObjectOnQueryResult(this.queryStateModel.get(), result); QueryUtils.setSearchInterfaceObjectOnQueryResult(this.searchInterface, result); return (>this.options.template.instantiateToElement(result, { wrapInDiv: true, checkCondition: true, currentLayout: 'list', - responsiveComponents: this.searchInterface.responsiveComponents - })).then(element => { + responsiveComponents: this.searchInterface.responsiveComponents, + })).then((element) => { Initialization.automaticallyCreateComponentsInsideResult(element, result); return element; }); @@ -143,7 +143,7 @@ export class ClickedDocumentList extends Component { listLabel: this.options.listLabel, messageWhenEmpty: l(`${ClickedDocumentList.ID}_no_clicked_documents`), showMoreMessage: l(`${ClickedDocumentList.ID}_more`), - showLessMessage: l(`${ClickedDocumentList.ID}_less`) + showLessMessage: l(`${ClickedDocumentList.ID}_less`), }); } } diff --git a/src/components/UserActions/ExpandableList.ts b/src/components/UserActions/ExpandableList.ts index 58384603..f77182be 100644 --- a/src/components/UserActions/ExpandableList.ts +++ b/src/components/UserActions/ExpandableList.ts @@ -49,7 +49,7 @@ export class ExpandableList { MORE_LABEL: 'Show More', LIST_LABEL: 'Items', MAXIMUM_ITEMS_SHOWN: 8, - MINIMUM_ITEMS_SHOWN: 4 + MINIMUM_ITEMS_SHOWN: 4, }); private static readonly COMPONENT_CLASS = 'coveo-expandable-list'; private static readonly EMPTY_CLASS = 'coveo-empty'; @@ -165,14 +165,14 @@ export class ExpandableList { private async update(items: Promise[], buttonText: string) { const list = this.element.querySelector('.coveo-list') as HTMLElement; - const listItems = (await Promise.all(items)).map(itemElement => { + const listItems = (await Promise.all(items)).map((itemElement) => { const listItem = document.createElement('li'); listItem.appendChild(itemElement); return listItem; }); list.innerHTML = ''; - listItems.forEach(itemElement => { + listItems.forEach((itemElement) => { $$(list).append(itemElement); }); diff --git a/src/components/UserActions/QueryList.ts b/src/components/UserActions/QueryList.ts index 4eba4b8e..a1702c1b 100644 --- a/src/components/UserActions/QueryList.ts +++ b/src/components/UserActions/QueryList.ts @@ -74,18 +74,18 @@ export class QueryList extends Component { numberOfItems: ComponentOptions.buildNumberOption({ defaultValue: 4, min: 1, - required: true + required: true, }), listLabel: ComponentOptions.buildStringOption({ - defaultValue: 'Recent Queries' + defaultValue: 'Recent Queries', }), transform: ComponentOptions.buildCustomOption<(query: string) => Promise>(DEFAULT_TRANSFORMATION, { - defaultValue: DEFAULT_TRANSFORMATION() + defaultValue: DEFAULT_TRANSFORMATION(), }), - userId: ComponentOptions.buildStringOption({ required: true }) + userId: ComponentOptions.buildStringOption({ required: true }), }; private userProfileModel: UserProfileModel; @@ -109,12 +109,12 @@ export class QueryList extends Component { } this.userProfileModel = get(this.root, UserProfileModel) as UserProfileModel; - this.userProfileModel.getActions(this.options.userId).then(actions => { + this.userProfileModel.getActions(this.options.userId).then((actions) => { this.sortedQueryList = [...actions] - .filter(action => action.query) + .filter((action) => action.query) .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()) .reverse() - .map(action => action.query) + .map((action) => action.query) .reduce(this.removeDuplicateQueries, []); this.render(); }, this.logger.error.bind(this.logger)); @@ -132,7 +132,7 @@ export class QueryList extends Component { listLabel: this.options.listLabel, messageWhenEmpty: l(`${QueryList.ID}_no_queries`), showMoreMessage: l(`${QueryList.ID}_more`), - showLessMessage: l(`${QueryList.ID}_less`) + showLessMessage: l(`${QueryList.ID}_less`), }); } diff --git a/src/components/UserActions/ResponsiveUserActions.ts b/src/components/UserActions/ResponsiveUserActions.ts index e0ed9f20..2a4c8e21 100644 --- a/src/components/UserActions/ResponsiveUserActions.ts +++ b/src/components/UserActions/ResponsiveUserActions.ts @@ -5,7 +5,7 @@ import { Dom, ResponsiveComponentsManager, IResponsiveComponentOptions, - ResponsiveDropdownHeader + ResponsiveDropdownHeader, } from 'coveo-search-ui'; import { UserActions } from './UserActions'; diff --git a/src/components/UserActions/Strings.ts b/src/components/UserActions/Strings.ts index 3a7317e6..fb6febc3 100644 --- a/src/components/UserActions/Strings.ts +++ b/src/components/UserActions/Strings.ts @@ -22,5 +22,5 @@ Translation.register(Language.English, { UserActivity_query: 'User Query', UserActivity_click: 'Clicked Document', UserActivity_view: 'Page View', - UserActivity_custom: 'Custom Action' + UserActivity_custom: 'Custom Action', }); diff --git a/src/components/UserActions/UserActions.ts b/src/components/UserActions/UserActions.ts index 7ff2b613..a722ebd1 100644 --- a/src/components/UserActions/UserActions.ts +++ b/src/components/UserActions/UserActions.ts @@ -8,7 +8,7 @@ import { get, ResultListEvents, IDisplayedNewResultEventArgs, - ResultList + ResultList, } from 'coveo-search-ui'; import { ResponsiveUserActions } from './ResponsiveUserActions'; import { arrowDown } from '../../utils/icons'; @@ -22,7 +22,7 @@ import { ViewedByCustomer } from '../ViewedByCustomer/ViewedByCustomer'; enum ResultLayoutType { LIST = 'list', TABLE = 'table', - CARD = 'card' + CARD = 'card', } /** @@ -87,20 +87,20 @@ export class UserActions extends Component { static readonly options: IUserActionsOptions = { userId: ComponentOptions.buildStringOption({ required: true }), buttonLabel: ComponentOptions.buildStringOption({ - defaultValue: 'User Actions' + defaultValue: 'User Actions', }), summaryLabel: ComponentOptions.buildStringOption({ - defaultValue: 'Session Summary' + defaultValue: 'Session Summary', }), activityLabel: ComponentOptions.buildStringOption({ - defaultValue: "User's Recent Activity" + defaultValue: "User's Recent Activity", }), viewedByCustomer: ComponentOptions.buildBooleanOption({ - defaultValue: true + defaultValue: true, }), hidden: ComponentOptions.buildBooleanOption({ - defaultValue: false - }) + defaultValue: false, + }), }; private static readonly USER_ACTION_OPENED = 'coveo-user-actions-opened'; @@ -154,8 +154,8 @@ export class UserActions extends Component { if (!this.isOpened) { (get(this.root, UserProfileModel) as UserProfileModel) .getActions(this.options.userId) - .then(actions => (actions.length > 0 ? this.render() : this.renderNoActions())) - .catch(e => (e && e.statusCode === 404 ? this.renderEnablePrompt() : this.renderNoActions())); + .then((actions) => (actions.length > 0 ? this.render() : this.renderNoActions())) + .catch((e) => (e && e.statusCode === 404 ? this.renderEnablePrompt() : this.renderNoActions())); this.bindings.usageAnalytics.logCustomEvent({ name: 'openUserActions', type: 'User Actions' }, {}, this.element); this.root.classList.add(UserActions.USER_ACTION_OPENED); @@ -201,7 +201,7 @@ export class UserActions extends Component { const foldable = document.createElement('div'); foldable.classList.add('coveo-accordion-foldable'); - elements.forEach(el => foldable.appendChild(el)); + elements.forEach((el) => foldable.appendChild(el)); div.appendChild(header); div.appendChild(foldable); @@ -236,18 +236,18 @@ export class UserActions extends Component { ...originalOptions, QueryList: { ...originalOptions.QueryList, - userId: this.options.userId + userId: this.options.userId, }, ClickedDocumentList: { ...originalOptions.ClickedDocumentList, - userId: this.options.userId + userId: this.options.userId, }, UserActivity: { ...originalOptions.UserActivity, - userId: this.options.userId - } + userId: this.options.userId, + }, }, - bindings: this.bindings + bindings: this.bindings, }); } @@ -256,7 +256,7 @@ export class UserActions extends Component { const summarySection = this.buildAccordion(this.options.summaryLabel, [ this.buildCoveoElement(ClickedDocumentList), - this.buildCoveoElement(QueryList) + this.buildCoveoElement(QueryList), ]); summarySection.classList.add(`coveo-summary`); @@ -308,7 +308,7 @@ export class UserActions extends Component { Coveo.$$(this.root).on('buildingQuery', (e, args) => { try { args.queryBuilder.userActions = { - tagViewsOfUser: this.options.userId + tagViewsOfUser: this.options.userId, }; } catch (e) { this.logger.warn("CreatedBy Email wasn't found", e); diff --git a/src/components/UserActions/UserActivity.ts b/src/components/UserActions/UserActivity.ts index 2124e058..24142c0e 100644 --- a/src/components/UserActions/UserActivity.ts +++ b/src/components/UserActions/UserActivity.ts @@ -68,14 +68,14 @@ export class UserActivity extends Component { 'omniboxFromLink', 'searchboxSubmit', 'searchFromLink', - 'userActionsSubmit' + 'userActionsSubmit', ], - required: true + required: true, }), unfoldExclude: ComponentOptions.buildListOption({ defaultValue: [], - required: true - }) + required: true, + }), }; private actions: UserAction[]; @@ -101,9 +101,9 @@ export class UserActivity extends Component { this.userProfileModel = get(this.root, UserProfileModel) as UserProfileModel; - this.userProfileModel.getActions(this.options.userId).then(actions => { + this.userProfileModel.getActions(this.options.userId).then((actions) => { this.actions = actions.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()); - this.foldedActions = this.actions.filter(action => !this.isUnfoldByDefault(action)); + this.foldedActions = this.actions.filter((action) => !this.isUnfoldByDefault(action)); this.render(); }); } @@ -130,7 +130,7 @@ export class UserActivity extends Component { const timestampSection = document.createElement('div'); timestampSection.classList.add(HEADER_CLASS); - this.buildTimestampSection().forEach(el => timestampSection.appendChild(el)); + this.buildTimestampSection().forEach((el) => timestampSection.appendChild(el)); const activitySection = this.buildActivitySection(); activitySection.classList.add(ACTIVITY_CLASS); @@ -178,7 +178,7 @@ export class UserActivity extends Component { return [...acc, action]; } }, []) - .map(item => { + .map((item) => { if (Array.isArray(item)) { return this.buildFolded(item); } else { @@ -221,7 +221,7 @@ export class UserActivity extends Component { hr.appendChild(span); li.addEventListener('click', () => { - this.foldedActions = this.foldedActions.filter(action => actions.indexOf(action) === -1); + this.foldedActions = this.foldedActions.filter((action) => actions.indexOf(action) === -1); this.render(); }); @@ -357,7 +357,7 @@ export class UserActivity extends Component { return [ this.buildTimestampCell({ title: l(`${UserActivity.ID}_start_date`), data: formatDate(startDate.timestamp) }), this.buildTimestampCell({ title: l(`${UserActivity.ID}_start_time`), data: formatTime(startDate.timestamp) }), - this.buildTimestampCell({ title: l(`${UserActivity.ID}_duration`), data: formatTimeInterval(duration) }) + this.buildTimestampCell({ title: l(`${UserActivity.ID}_duration`), data: formatTimeInterval(duration) }), ]; } diff --git a/src/components/ViewedByCustomer/Strings.ts b/src/components/ViewedByCustomer/Strings.ts index ffc93af5..be597783 100644 --- a/src/components/ViewedByCustomer/Strings.ts +++ b/src/components/ViewedByCustomer/Strings.ts @@ -1,5 +1,5 @@ import { Translation, Language } from '../../utils/translation'; Translation.register(Language.English, { - ViewedByCustomer_DefaultLabel: 'Viewed by Customer' + ViewedByCustomer_DefaultLabel: 'Viewed by Customer', }); diff --git a/src/components/ViewedByCustomer/ViewedByCustomer.ts b/src/components/ViewedByCustomer/ViewedByCustomer.ts index 9a1d8937..5a207662 100644 --- a/src/components/ViewedByCustomer/ViewedByCustomer.ts +++ b/src/components/ViewedByCustomer/ViewedByCustomer.ts @@ -34,7 +34,7 @@ export class ViewedByCustomer extends Component { */ public static readonly options: IViewedByCustomerOptions = { showIcon: ComponentOptions.buildBooleanOption({ defaultValue: true }), - label: ComponentOptions.buildStringOption({ defaultValue: l(`${ViewedByCustomer.ID}_DefaultLabel`) }) + label: ComponentOptions.buildStringOption({ defaultValue: l(`${ViewedByCustomer.ID}_DefaultLabel`) }), }; // Internal CSS selectors. diff --git a/src/models/UserProfileModel.ts b/src/models/UserProfileModel.ts index 0f47826d..14750366 100644 --- a/src/models/UserProfileModel.ts +++ b/src/models/UserProfileModel.ts @@ -56,12 +56,12 @@ export class UserProfileModel extends Model { public static readonly ID = 'UserProfileModel'; private static readonly ERROR_MESSAGE = Object.freeze({ - FETCH_CLICKED_DOCUMENT_FAIL: 'Fetching clicked documents details failed' + FETCH_CLICKED_DOCUMENT_FAIL: 'Fetching clicked documents details failed', }); private static readonly MODEL_CONFIG = { customAttribute: true, - silent: true + silent: true, }; private endpoint: UserProfilingEndpoint; @@ -85,7 +85,7 @@ export class UserProfileModel extends Model { this.endpoint = new UserProfilingEndpoint({ uri: this.options.restUri, accessToken: this.options.accessToken || (this.options.searchEndpoint as SearchEndpoint).accessToken, - organization: this.options.organizationId + organization: this.options.organizationId, }); } @@ -116,7 +116,7 @@ export class UserProfileModel extends Model { private fetchActions(userId: string) { const pendingFetch = this.getOrFetchCache[userId]; const doFetch = () => { - this.getOrFetchCache[userId] = this.endpoint.getActions(userId).then(actions => this.parseGetActionsResponse(userId, actions)); + this.getOrFetchCache[userId] = this.endpoint.getActions(userId).then((actions) => this.parseGetActionsResponse(userId, actions)); return this.getOrFetchCache[userId]; }; return pendingFetch || doFetch(); @@ -136,7 +136,11 @@ export class UserProfileModel extends Model { } const query = new QueryBuilder(); - query.advancedExpression.addFieldExpression('@urihash', '==', urihashes.filter(x => x)); + query.advancedExpression.addFieldExpression( + '@urihash', + '==', + urihashes.filter((x) => x) + ); // Ensure we fetch the good amount of document. query.numberOfResults = urihashes.length; @@ -154,7 +158,7 @@ export class UserProfileModel extends Model { const urihashes = actions .filter(this.isClick) - .map(action => action.value.uri_hash) + .map((action) => action.value.uri_hash) // Remove duplicates. .filter((value, index, list) => list.indexOf(value) === index); @@ -164,7 +168,7 @@ export class UserProfileModel extends Model { this.logger.error(UserProfileModel.ERROR_MESSAGE.FETCH_CLICKED_DOCUMENT_FAIL, error); } - return actions.map(action => { + return actions.map((action) => { return new UserAction( action.name, new Date(action.time), diff --git a/src/rest/UserProfilingEndpoint.ts b/src/rest/UserProfilingEndpoint.ts index e77637c7..01d25ea5 100644 --- a/src/rest/UserProfilingEndpoint.ts +++ b/src/rest/UserProfilingEndpoint.ts @@ -29,7 +29,7 @@ export enum UserActionType { Search = 'SEARCH', Click = 'CLICK', PageView = 'VIEW', - Custom = 'CUSTOM' + Custom = 'CUSTOM', } /** @@ -113,7 +113,7 @@ export class UserProfilingEndpoint { responseType: 'json', requestDataType: 'application/json', requestData: { objectId: userId }, - errorsAsSuccess: false + errorsAsSuccess: false, }); if (this.isResponseEmpty(response)) { @@ -124,11 +124,11 @@ export class UserProfilingEndpoint { } private parseResponse(response: IActionsHistoryResponse) { - return response.value.map(v => { + return response.value.map((v) => { return { time: parseInt(v.time), value: JSON.parse(v.value) as { [key: string]: string }, - name: v.name as UserActionType + name: v.name as UserActionType, }; }); } diff --git a/src/utils/events.ts b/src/utils/events.ts index 1ed90a9f..46830000 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -4,5 +4,5 @@ export const MANUAL_SEARCH_EVENT_CAUSE = Object.freeze([ 'omniboxFromLink', 'searchboxAsYouType', 'searchboxSubmit', - 'searchFromLink' + 'searchFromLink', ]); diff --git a/src/utils/time.ts b/src/utils/time.ts index 110c1ae4..48745b1e 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -11,7 +11,7 @@ export function formatDate(date: Date) { weekday: 'short', day: '2-digit', month: 'short', - year: 'numeric' + year: 'numeric', }); } @@ -24,7 +24,7 @@ export function formatDate(date: Date) { export function formatDateShort(date: Date) { return date.toLocaleDateString('default', { day: '2-digit', - month: 'short' + month: 'short', }); } @@ -38,7 +38,7 @@ export function formatTime(date: Date) { return date.toLocaleTimeString('default', { hour: '2-digit', minute: '2-digit', - second: '2-digit' + second: '2-digit', }); } @@ -51,7 +51,7 @@ export function formatTime(date: Date) { export function formatTimeShort(date: Date) { return date.toLocaleTimeString('default', { hour: '2-digit', - minute: '2-digit' + minute: '2-digit', }); } @@ -107,7 +107,7 @@ export function formatTimeInterval(interval: number): string { [nb_day, `${day_str}${nb_hour > 0 ? ` ${hour_str}` : ''}`], [nb_hour, `${hour_str}${nb_minutes > 0 ? ` ${minutes_str}` : ''}`], [nb_minutes, `${minutes_str}${nb_seconds > 0 ? ` ${seconds_str}` : ''}`], - [nb_seconds, seconds_str] + [nb_seconds, seconds_str], ]; const first_meaningful_tuple = (time_per_unit.find(([amount, _]) => amount > 0) as [number, string]) || [0, '0 seconds']; diff --git a/src/utils/translation.ts b/src/utils/translation.ts index e6b339e2..e8d99213 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -2,7 +2,7 @@ * Supported languages. */ export enum Language { - English = 'en' + English = 'en', } /** @@ -23,7 +23,7 @@ export class Translation { * @param translationDictionary Key-Value dictionary that contain all traslation for a language. */ public static register(language: Language, translationDictionary: ILanguageDictionary) { - Object.keys(translationDictionary).forEach(key => { + Object.keys(translationDictionary).forEach((key) => { (String as any)['locales'] = (String as any)['locales'] || {}; (String as any)['locales'][language] = (String as any)['locales'][language] || {}; (String as any)['locales'][language][key] = translationDictionary[key]; diff --git a/tests/Utils/time.spec.ts b/tests/Utils/time.spec.ts index 4efc8a12..0fe13ed3 100644 --- a/tests/Utils/time.spec.ts +++ b/tests/Utils/time.spec.ts @@ -5,7 +5,7 @@ import { formatTimeShort, formatDateAndTime, formatDateAndTimeShort, - formatTimeInterval + formatTimeInterval, } from '../../src/utils/time'; const UTC_TEST_TIME = '2019-04-29T20:53:13'; diff --git a/tests/Utils/translation.spec.ts b/tests/Utils/translation.spec.ts index 16c5cc1d..b2d34a9a 100644 --- a/tests/Utils/translation.spec.ts +++ b/tests/Utils/translation.spec.ts @@ -7,11 +7,11 @@ describe('Translation', () => { (String as any)['locales']['en'] = {}; const dict: { [key: string]: string } = { '1': 'someTest1', - '2': '' + '2': '', }; Translation.register(Language.English, dict); - Object.keys(dict).forEach(key => { + Object.keys(dict).forEach((key) => { expect((String as any)['locales'][Language.English][key]).toBe(dict[key]); expect(key.toLocaleString()).toBe(dict[key]); }); @@ -22,11 +22,11 @@ describe('Translation', () => { (String as any)['locales'] = undefined; const dict: { [key: string]: string } = { '1': 'someTest1', - '2': '' + '2': '', }; Translation.register(Language.English, dict); - Object.keys(dict).forEach(key => { + Object.keys(dict).forEach((key) => { expect((String as any)['locales'][Language.English][key]).toBe(dict[key]); expect(key.toLocaleString()).toBe(dict[key]); }); @@ -36,11 +36,11 @@ describe('Translation', () => { it('should enable toLocaleString for each registered strings', () => { const dict: { [key: string]: string } = { '1': 'someTest1', - '2': '' + '2': '', }; Translation.register(Language.English, dict); - Object.keys(dict).forEach(key => { + Object.keys(dict).forEach((key) => { expect(key.toLocaleString()).toBe(dict[key]); }); expect('3'.toLocaleString()).toBe('3'); diff --git a/tests/components/ActionButton/ActionButton.spec.ts b/tests/components/ActionButton/ActionButton.spec.ts index 41af615e..8ad3fba3 100644 --- a/tests/components/ActionButton/ActionButton.spec.ts +++ b/tests/components/ActionButton/ActionButton.spec.ts @@ -20,7 +20,7 @@ describe('ActionButton', () => { title: 'a default title', tooltip: 'a default tooltip', icon: icons.copy, - click: () => {} + click: () => {}, }; testSubject = createActionButton(options); @@ -136,19 +136,19 @@ describe('ActionButton', () => { { optionName: 'title', optionValue: 'some title', - expectedSelector: '.coveo-actionbutton_title' + expectedSelector: '.coveo-actionbutton_title', }, { optionName: 'icon', optionValue: icons.copy, - expectedSelector: '.coveo-actionbutton_icon' + expectedSelector: '.coveo-actionbutton_icon', }, { optionName: 'tooltip', optionValue: 'Some Tooltip', - expectedSelector: '.CoveoActionButton[title]' - } - ].forEach(testCase => { + expectedSelector: '.CoveoActionButton[title]', + }, + ].forEach((testCase) => { describe(`with empty ${testCase.optionName} option`, () => { beforeEach(() => { setOption(testCase.optionName, null); diff --git a/tests/components/ActionButton/ToggleActionButton.spec.ts b/tests/components/ActionButton/ToggleActionButton.spec.ts index e9bc2721..4c6ddef6 100644 --- a/tests/components/ActionButton/ToggleActionButton.spec.ts +++ b/tests/components/ActionButton/ToggleActionButton.spec.ts @@ -34,7 +34,7 @@ describe('ToggleActionButton', () => { deactivateTooltip: 'Deactivate feature', click: clickSpy, activate: activateSpy, - deactivate: deactivateSpy + deactivate: deactivateSpy, }; testSubject = createToggleButton(options); @@ -141,7 +141,7 @@ describe('ToggleActionButton', () => { { legacy: 'activatedIcon', current: 'deactivateIcon' }, { legacy: 'activatedTooltip', current: 'deactivateTooltip' }, { legacy: 'deactivatedIcon', current: 'activateIcon' }, - { legacy: 'deactivatedTooltip', current: 'activateTooltip' } + { legacy: 'deactivatedTooltip', current: 'activateTooltip' }, ].forEach(({ legacy, current }) => { it(`should support legacy '${legacy}' option through '${current}'`, () => { const option = getOption(current); diff --git a/tests/components/AttachResult/AttachResult.spec.ts b/tests/components/AttachResult/AttachResult.spec.ts index bc516bb7..4279ecc9 100644 --- a/tests/components/AttachResult/AttachResult.spec.ts +++ b/tests/components/AttachResult/AttachResult.spec.ts @@ -35,9 +35,9 @@ describe('AttachResult', () => { let isAttachedSpy: jasmine.Spy; beforeEach(() => { faker = { - isAttached: function(result: IQueryResult) { + isAttached: function (result: IQueryResult) { return Promise.resolve(true); - } + }, }; isAttachedSpy = spyOn(faker, 'isAttached').and.callThrough(); @@ -48,7 +48,7 @@ describe('AttachResult', () => { expect(faker.isAttached).toHaveBeenCalledWith(fakeResult); }); - it('should be attached when isAttached returns true', done => { + it('should be attached when isAttached returns true', (done) => { isAttachedSpy.and.returnValue(Promise.resolve(true)); attachResult = Mock.optionsResultComponentSetup(AttachResult, { isAttached: faker.isAttached }, fakeResult); setTimeout(() => { @@ -64,7 +64,7 @@ describe('AttachResult', () => { expect(attachResult.cmp.element.querySelector('.coveo-caption-for-icon').textContent).toBe('Attach Result'); }); - it('should be detached when isAttached returns false', done => { + it('should be detached when isAttached returns false', (done) => { isAttachedSpy.and.returnValue(Promise.resolve(false)); attachResult = Mock.optionsResultComponentSetup(AttachResult, { isAttached: faker.isAttached }, fakeResult); setTimeout(() => { @@ -73,7 +73,7 @@ describe('AttachResult', () => { }, 50); }); - it('should be detached when isAttached throws', done => { + it('should be detached when isAttached throws', (done) => { isAttachedSpy.and.returnValue(Promise.reject('error')); attachResult = Mock.optionsResultComponentSetup(AttachResult, { isAttached: faker.isAttached }, fakeResult); setTimeout(() => { @@ -86,11 +86,11 @@ describe('AttachResult', () => { describe('attach', () => { let faker: IAttachResultOptions; let attachSpy: jasmine.Spy; - beforeEach(done => { + beforeEach((done) => { faker = { - attach: function(result: IQueryResult) { + attach: function (result: IQueryResult) { return Promise.resolve(); - } + }, }; attachSpy = spyOn(faker, 'attach').and.callThrough(); @@ -105,9 +105,9 @@ describe('AttachResult', () => { detachCaption: 'detach me', attachCaption: 'attach me', caseId: 'testcase', - articleIdField: 'article' + articleIdField: 'article', }, - env => { + (env) => { env.searchInterface.usageAnalytics = env.usageAnalytics; return env; } @@ -126,11 +126,11 @@ describe('AttachResult', () => { expect(faker.attach).toHaveBeenCalledTimes(1); }); - it('should not change state if attach fails', done => { + it('should not change state if attach fails', (done) => { attachSpy.and.returnValue(Promise.reject('error')); expect(attachResult.cmp.isAttached()).toBeFalsy(); - attachResult.cmp.attach().catch(error => { + attachResult.cmp.attach().catch((error) => { expect(error).toBe('error'); expect(attachResult.cmp.isAttached()).toBeFalsy(); done(); @@ -148,7 +148,7 @@ describe('AttachResult', () => { expect(attachResult.cmp.element.querySelector('.coveo-caption-for-icon').innerHTML).toBe('detach me'); }); - it('should trigger the attach event', done => { + it('should trigger the attach event', (done) => { Coveo.$$(attachResult.env.root).on(AttachResultEvents.Attach, (evt: Event, args: IAttachResultEventArgs) => { expect(args.queryResult).not.toBeNull(); done(); @@ -176,11 +176,11 @@ describe('AttachResult', () => { describe('detach', () => { let faker: IAttachResultOptions; let detachSpy: jasmine.Spy; - beforeEach(done => { + beforeEach((done) => { faker = { - detach: function(result: IQueryResult) { + detach: function (result: IQueryResult) { return Promise.resolve(); - } + }, }; detachSpy = spyOn(faker, 'detach').and.callThrough(); @@ -195,9 +195,9 @@ describe('AttachResult', () => { detachCaption: 'detach me', attachCaption: 'attach me', caseId: 'testcase', - articleIdField: 'article' + articleIdField: 'article', }, - env => { + (env) => { env.searchInterface.usageAnalytics = env.usageAnalytics; return env; } @@ -216,11 +216,11 @@ describe('AttachResult', () => { expect(faker.detach).toHaveBeenCalledTimes(1); }); - it('should not change state if attach fails', done => { + it('should not change state if attach fails', (done) => { detachSpy.and.returnValue(Promise.reject('error')); expect(attachResult.cmp.isAttached()).toBeTruthy(); - attachResult.cmp.detach().catch(error => { + attachResult.cmp.detach().catch((error) => { expect(error).toBe('error'); expect(attachResult.cmp.isAttached()).toBeTruthy(); done(); @@ -238,7 +238,7 @@ describe('AttachResult', () => { expect(attachResult.cmp.element.querySelector('.coveo-caption-for-icon').innerHTML).toBe('attach me'); }); - it('should trigger the detach event', done => { + it('should trigger the detach event', (done) => { Coveo.$$(attachResult.env.root).on(AttachResultEvents.Detach, (evt: Event, args: IAttachResultEventArgs) => { expect(args.queryResult).not.toBeNull(); done(); diff --git a/tests/components/CopyPaste/CopyPaste.spec.ts b/tests/components/CopyPaste/CopyPaste.spec.ts index 257abae3..f71d084c 100644 --- a/tests/components/CopyPaste/CopyPaste.spec.ts +++ b/tests/components/CopyPaste/CopyPaste.spec.ts @@ -41,7 +41,7 @@ describe('CopyToClipboard ResultAction', () => { sandbox.restore(); $$(document.body) .children() - .forEach(el => el.remove()); + .forEach((el) => el.remove()); }); describe('on click', () => { diff --git a/tests/components/ResultAction/ResultAction.spec.ts b/tests/components/ResultAction/ResultAction.spec.ts index 4a34a8a6..b50c2113 100644 --- a/tests/components/ResultAction/ResultAction.spec.ts +++ b/tests/components/ResultAction/ResultAction.spec.ts @@ -40,7 +40,7 @@ describe('ResultAction', () => { sandbox.restore(); $$(document.body) .children() - .forEach(el => el.remove()); + .forEach((el) => el.remove()); }); describe('after construction', () => { diff --git a/tests/components/ResultsFilter/ResultsFilter.spec.ts b/tests/components/ResultsFilter/ResultsFilter.spec.ts index b97a76a4..bf1a6870 100644 --- a/tests/components/ResultsFilter/ResultsFilter.spec.ts +++ b/tests/components/ResultsFilter/ResultsFilter.spec.ts @@ -44,7 +44,7 @@ describe('ResultsFilter', () => { }); it('should trigger event with checked true when first toggling', () => { - return new Promise(resolve => { + return new Promise((resolve) => { Coveo.$$(filter.env.root).on(ResultsFilterEvents.Click, (evt: Event, args: IResultsFilterEventArgs) => { expect(args.checked).toBeTruthy(); resolve(); @@ -54,7 +54,7 @@ describe('ResultsFilter', () => { }); it('should trigger event with checked false when toggling twice', () => { - return new Promise(resolve => { + return new Promise((resolve) => { filter.cmp.toggle(); Coveo.$$(filter.env.root).on(ResultsFilterEvents.Click, (evt: Event, args: IResultsFilterEventArgs) => { expect(args.checked).toBeFalsy(); @@ -73,7 +73,7 @@ describe('ResultsFilter', () => { filter = Mock.optionsComponentSetup(ResultsFilter, { text: 'much rain', field: 'myField', - getValues: () => ['foo', 'bar'] + getValues: () => ['foo', 'bar'], }); return Promise.resolve(); }); diff --git a/tests/components/UserActions/ClickedDocumentList.spec.ts b/tests/components/UserActions/ClickedDocumentList.spec.ts index 90a71e49..32d04464 100644 --- a/tests/components/UserActions/ClickedDocumentList.spec.ts +++ b/tests/components/UserActions/ClickedDocumentList.spec.ts @@ -13,7 +13,7 @@ describe('ClickedDocumentList', () => { return new UserAction(UserActionType.Click, new Date(i), { origin_level_1: 'foo', uri_hash: document.uri }, document); }; - const TEST_CLICKS = generate(20, i => { + const TEST_CLICKS = generate(20, (i) => { return BUILD_ACTION(`document${i}`, i); }); @@ -38,7 +38,7 @@ describe('ClickedDocumentList', () => { it('should show a text when there is no document clicked', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve([])); return env; }) @@ -54,7 +54,7 @@ describe('ClickedDocumentList', () => { it('should show "Documents Clicked" as title', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -69,7 +69,7 @@ describe('ClickedDocumentList', () => { const customTitle = 'Custom Title'; const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', listLabel: customTitle }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', listLabel: customTitle }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -85,7 +85,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -103,7 +103,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -121,7 +121,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -142,7 +142,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -168,14 +168,14 @@ describe('ClickedDocumentList', () => { BUILD_ACTION('someQuery2', 3), BUILD_ACTION('someQuery2', 2), BUILD_ACTION('someQuery2', 1), - BUILD_ACTION('someQuery', 0) + BUILD_ACTION('someQuery', 0), ]; const SORTED_AND_TRIMMED_CLICK_EVENTS = [CLICK_EVENTS[0], CLICK_EVENTS[1]]; const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(CLICK_EVENTS)); return env; }) @@ -199,7 +199,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; }) @@ -222,7 +222,7 @@ describe('ClickedDocumentList', () => { Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { model = fakeUserProfileModel(env.root, sandbox); model.getActions.returns(Promise.resolve(TEST_CLICKS)); return env; @@ -237,7 +237,7 @@ describe('ClickedDocumentList', () => { const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -253,7 +253,7 @@ describe('ClickedDocumentList', () => { let getActionStub: SinonStub<[HTMLElement, ClickedDocumentList], void>; const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: null }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: null }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) @@ -268,7 +268,7 @@ describe('ClickedDocumentList', () => { let getActionStub: SinonStub<[HTMLElement, ClickedDocumentList], void>; const mock = Mock.advancedComponentSetup( ClickedDocumentList, - new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) @@ -293,10 +293,10 @@ describe('ClickedDocumentList', () => { max: TEST_CLICKS.length, show: TEST_CLICKS.length, template: { - instantiateToElement: instantiateToElementStub - } + instantiateToElement: instantiateToElementStub, + }, }, - env => { + (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_CLICKS)); return env; } diff --git a/tests/components/UserActions/ExpandableList.spec.ts b/tests/components/UserActions/ExpandableList.spec.ts index 8d143d75..487ae3ba 100644 --- a/tests/components/UserActions/ExpandableList.spec.ts +++ b/tests/components/UserActions/ExpandableList.spec.ts @@ -38,7 +38,7 @@ describe('ExpandableList', () => { it('should render a button with "Show More" as text', () => { const list = new ExpandableList(document.createElement('div'), TEST_ITEM_LIST, { - transform: spanItemGenerator + transform: spanItemGenerator, }); return delay(() => { @@ -73,7 +73,7 @@ describe('ExpandableList', () => { const list = new ExpandableList(document.createElement('div'), TEST_ITEM_LIST, { transform: spanItemGenerator, maximumItemsShown: 10, - minimumItemsShown: 5 + minimumItemsShown: 5, }); return delay(() => { @@ -89,7 +89,7 @@ describe('ExpandableList', () => { const list = new ExpandableList(document.createElement('div'), TEST_ITEM_LIST, { transform: spanItemGenerator, maximumItemsShown: 5, - minimumItemsShown: 5 + minimumItemsShown: 5, }); const el = list.element.querySelector('.coveo-more-less'); @@ -103,7 +103,7 @@ describe('ExpandableList', () => { const list = new ExpandableList(document.createElement('div'), TEST_ITEM_LIST, { transform: spanItemGenerator, maximumItemsShown: 10, - minimumItemsShown: 5 + minimumItemsShown: 5, }); const el = list.element.querySelector('.coveo-more-less'); @@ -121,7 +121,7 @@ describe('ExpandableList', () => { const list = new ExpandableList(document.createElement('div'), TEST_ITEM_LIST, { transform: spanItemGenerator, maximumItemsShown: TEST_ITEM_LIST.length, - minimumItemsShown: 5 + minimumItemsShown: 5, }); const el = list.element.querySelector('.coveo-more-less'); diff --git a/tests/components/UserActions/QueryList.spec.ts b/tests/components/UserActions/QueryList.spec.ts index 74ab5366..13db8048 100644 --- a/tests/components/UserActions/QueryList.spec.ts +++ b/tests/components/UserActions/QueryList.spec.ts @@ -9,7 +9,7 @@ import { UserActionType } from '../../../src/rest/UserProfilingEndpoint'; describe('QueryList', () => { const sortUserActions = (a: UserAction, b: UserAction) => a.timestamp.getTime() - b.timestamp.getTime(); - const TEST_QUERIES = generate(20, i => { + const TEST_QUERIES = generate(20, (i) => { const query = `${Math.random()}`; return new UserAction(UserActionType.Search, new Date(i), { query_expression: query, origin_level_1: 'foo' }, null, query); }); @@ -34,7 +34,7 @@ describe('QueryList', () => { it('should show "No queries made by this user" when no query were made', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve([])); return env; }) @@ -51,7 +51,7 @@ describe('QueryList', () => { it('should show "Recent Queries" as title', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -65,7 +65,7 @@ describe('QueryList', () => { it('should show 4 queries by default', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -81,7 +81,7 @@ describe('QueryList', () => { it('should show a number of queries equal to the "numberOfItems" option', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -97,7 +97,7 @@ describe('QueryList', () => { it('should display a search icon on every list item', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -116,7 +116,7 @@ describe('QueryList', () => { it('should show all queries when expanded', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -138,14 +138,14 @@ describe('QueryList', () => { new UserAction(UserActionType.Search, new Date(1), { query_expression: 'someQuery2', origin_level_1: 'foo' }, null, 'someQuery2'), new UserAction(UserActionType.Search, new Date(2), { query_expression: 'someQuery2', origin_level_1: 'foo' }, null, 'someQuery2'), new UserAction(UserActionType.Search, new Date(3), { query_expression: 'someQuery2', origin_level_1: 'foo' }, null, 'someQuery2'), - new UserAction(UserActionType.Search, new Date(4), { query_expression: 'someQuery', origin_level_1: 'foo' }, null, 'someQuery') + new UserAction(UserActionType.Search, new Date(4), { query_expression: 'someQuery', origin_level_1: 'foo' }, null, 'someQuery'), ]; const SORTED_AND_TRIMMED_SEARCH_EVENT = ['someQuery', 'someQuery2']; const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(SEARCH_EVENTS)); return env; }) @@ -173,7 +173,7 @@ describe('QueryList', () => { it('should render a list of queries made by a user as a list and put the most recent queries on top', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -195,7 +195,7 @@ describe('QueryList', () => { Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { model = fakeUserProfileModel(env.root, sandbox); model.getActions.returns(Promise.reject()); return env; @@ -211,7 +211,7 @@ describe('QueryList', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -227,7 +227,7 @@ describe('QueryList', () => { it('should do a query in the omnibox if the search interface has an omnibox', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -253,7 +253,7 @@ describe('QueryList', () => { it('should not do a query if the search interface does not have an omnibox', () => { const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', numberOfItems: 10 }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(TEST_QUERIES)); return env; }) @@ -273,7 +273,7 @@ describe('QueryList', () => { let getActionStub: SinonStub<[HTMLElement, QueryList], void>; const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: null }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: null }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) @@ -288,7 +288,7 @@ describe('QueryList', () => { let getActionStub: SinonStub<[HTMLElement, QueryList], void>; const mock = Mock.advancedComponentSetup( QueryList, - new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) diff --git a/tests/components/UserActions/ResponsiveUserActions.spec.ts b/tests/components/UserActions/ResponsiveUserActions.spec.ts index 256a5141..98253efd 100644 --- a/tests/components/UserActions/ResponsiveUserActions.spec.ts +++ b/tests/components/UserActions/ResponsiveUserActions.spec.ts @@ -35,7 +35,7 @@ describe('ResponsiveUserActions', () => { const userActions = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -61,7 +61,7 @@ describe('ResponsiveUserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -87,7 +87,7 @@ describe('ResponsiveUserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -120,7 +120,7 @@ describe('ResponsiveUserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -149,7 +149,7 @@ describe('ResponsiveUserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'someId', buttonLabel: title }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'someId', buttonLabel: title }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -173,7 +173,7 @@ describe('ResponsiveUserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'someId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'someId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) diff --git a/tests/components/UserActions/UserActions.spec.ts b/tests/components/UserActions/UserActions.spec.ts index 38e8254b..12d4564a 100644 --- a/tests/components/UserActions/UserActions.spec.ts +++ b/tests/components/UserActions/UserActions.spec.ts @@ -16,27 +16,27 @@ describe('UserActions', () => { new UserAction(UserActionType.Search, new Date('2:00:00 AM'), { origin_level_1: 'not relevant' + Math.random(), query_expression: 'not relevant', - cause: 'interfaceLoad' + cause: 'interfaceLoad', }), new UserAction(UserActionType.PageView, new Date('2:10:00 AM'), { origin_level_1: 'not relevant' + Math.random(), content_id_key: '@sysurihash', - content_id_value: 'product1' + content_id_value: 'product1', }), new UserAction(UserActionType.Custom, new Date('2:20:00 AM'), { origin_level_1: 'not relevant' + Math.random(), c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' + event_value: 'headphones-gaming', }), new UserAction(UserActionType.Custom, new Date('2:30:00 AM'), { origin_level_1: 'relevant' + Math.random(), c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' - }) + event_value: 'headphones-gaming', + }), ]; beforeAll(() => { @@ -61,7 +61,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) @@ -79,7 +79,7 @@ describe('UserActions', () => { Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', hidden: true }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId', hidden: true }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -95,7 +95,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -111,7 +111,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -128,7 +128,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -149,7 +149,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -172,7 +172,7 @@ describe('UserActions', () => { Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: FAKE_USER_ID }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: FAKE_USER_ID }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -181,7 +181,7 @@ describe('UserActions', () => { return delay(() => { expect(automaticallyCreateComponentsInsideStub.called).toBe(true); - [ClickedDocumentList.ID, QueryList.ID, UserActivity.ID].forEach(component => { + [ClickedDocumentList.ID, QueryList.ID, UserActivity.ID].forEach((component) => { expect(automaticallyCreateComponentsInsideStub.args[0][1].options[component]).toBeDefined(); expect(automaticallyCreateComponentsInsideStub.args[0][1].options[component].userId).toBe(FAKE_USER_ID); }); @@ -193,24 +193,24 @@ describe('UserActions', () => { const initOptions = { QueryList: { listLabel: 'Custom Query List Title', - numberOfItems: 1 + numberOfItems: 1, }, ClickedDocumentList: { listLabel: 'Custom Clicked Document List Title', template: 'Custom Template', - numberOfItems: 2 + numberOfItems: 2, }, UserActivity: { unfoldInclude: ['includedField'], - unfoldExclude: ['excludedField'] - } + unfoldExclude: ['excludedField'], + }, } as { [key: string]: any }; const automaticallyCreateComponentsInsideStub = sandbox.stub(Initialization, 'automaticallyCreateComponentsInside'); const component: UserActions = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: FAKE_USER_ID }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: FAKE_USER_ID }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -224,7 +224,7 @@ describe('UserActions', () => { const actualInitOptions = automaticallyCreateComponentsInsideStub.args[0][1].options; - [QueryList.ID, ClickedDocumentList.ID, UserActivity.ID].forEach(component => { + [QueryList.ID, ClickedDocumentList.ID, UserActivity.ID].forEach((component) => { const actualComponentOptions = actualInitOptions[component]; expect(actualComponentOptions).toBeDefined(); expect(actualComponentOptions).toEqual(jasmine.objectContaining(initOptions[component])); @@ -237,7 +237,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -256,7 +256,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject({ statusCode: 404 })); return env; }) @@ -276,7 +276,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve([])); return env; }) @@ -294,7 +294,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.reject()); return env; }) @@ -312,7 +312,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -323,7 +323,7 @@ describe('UserActions', () => { const accordionSections = mock.cmp.element.querySelectorAll('.coveo-accordion'); expect(automaticallyCreateComponentsInsideStub.called).toBe(true); - accordionSections.forEach(el => { + accordionSections.forEach((el) => { el.classList.remove('coveo-folded'); el.querySelector('.coveo-accordion-header').click(); expect(el.classList).toContain('coveo-folded'); @@ -336,7 +336,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(ACTIONS)); return env; }) @@ -348,7 +348,7 @@ describe('UserActions', () => { expect(automaticallyCreateComponentsInsideStub.called).toBe(true); - accordionSections.forEach(el => { + accordionSections.forEach((el) => { el.classList.add('coveo-folded'); el.querySelector('.coveo-accordion-header').click(); expect(el.classList).not.toContain('coveo-folded'); @@ -363,7 +363,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -383,7 +383,7 @@ describe('UserActions', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -409,7 +409,7 @@ describe('UserActions', () => { mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: someUserId }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: someUserId }, (env) => { modelMock = fakeUserProfileModel(env.root, sandbox); modelMock.getActions.returns(new Promise(() => {})); return env; @@ -464,7 +464,7 @@ describe('UserActions', () => { mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: someUserId }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: someUserId }, (env) => { modelMock = fakeUserProfileModel(env.root, sandbox); modelMock.getActions.returns(new Promise(() => {})); return env; @@ -516,7 +516,7 @@ describe('UserActions', () => { it('should add email to query', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -535,7 +535,7 @@ describe('UserActions', () => { it('should catch error', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', record: undefined }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', record: undefined }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -577,7 +577,7 @@ describe('UserActions', () => { describe('if the viewedByCustomer option is true', () => { const setResultList = (el: HTMLElement, layout: 'list' | 'card' | 'table') => { - ['list', 'card', 'table'].forEach(key => { + ['list', 'card', 'table'].forEach((key) => { const resultList = document.createElement('div'); resultList.classList.add('CoveoResultList'); if (key !== layout) { @@ -595,7 +595,7 @@ describe('UserActions', () => { it('should add a ViewedByCustomer Component when the result list layout is card', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { setResultList(env.root, 'card'); fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; @@ -614,7 +614,7 @@ describe('UserActions', () => { it('should add a ViewedByCustomer Component when the result list layout is list', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { setResultList(env.root, 'list'); fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; @@ -633,7 +633,7 @@ describe('UserActions', () => { it('should not add a ViewedByCustomer Component when the result list layout is table', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { setResultList(env.root, 'table'); fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; @@ -652,7 +652,7 @@ describe('UserActions', () => { it('It should not add a viewedByCustomer if one is already there', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -677,7 +677,7 @@ describe('UserActions', () => { it('should not add a ViewedByCustomer Component', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) @@ -695,7 +695,7 @@ describe('UserActions', () => { it('It should not add a viewedByCustomer if one is already there', () => { const mock = Mock.advancedComponentSetup( UserActions, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testUserId', viewedByCustomer: viewedByCustomerOption }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(new Promise(() => {})); return env; }) diff --git a/tests/components/UserActions/UserActivity.spec.ts b/tests/components/UserActions/UserActivity.spec.ts index cd3d91cd..947b5983 100644 --- a/tests/components/UserActions/UserActivity.spec.ts +++ b/tests/components/UserActions/UserActivity.spec.ts @@ -15,84 +15,84 @@ describe('UserActivity', () => { origin_level_1: 'relevant' + Math.random(), uri_hash: 'product' + Math.random(), c_contentidkey: '@sysurihash', - c_contentidvalue: '' + Math.random() + c_contentidvalue: '' + Math.random(), }); FAKE_CLICK_EVENT.document = Fake.createFakeResult(); const FAKE_SEARCH_EVENT = new UserAction(UserActionType.Search, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), - cause: 'interfaceLoad' + cause: 'interfaceLoad', }); const FAKE_USER_SEARCH_EVENT = new UserAction(UserActionType.Search, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), query_expression: 'someSearch' + Math.random(), - cause: 'searchboxSubmit' + cause: 'searchboxSubmit', }); FAKE_USER_SEARCH_EVENT.query = FAKE_USER_SEARCH_EVENT.raw.query_expression; const FAKE_VIEW_EVENT = new UserAction(UserActionType.PageView, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), content_id_key: '@someKey' + Math.random(), - content_id_value: 'someValue' + Math.random() + content_id_value: 'someValue' + Math.random(), }); const FAKE_CUSTOM_EVENT = new UserAction(UserActionType.Custom, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), event_type: 'Submit' + Math.random(), - event_value: 'Case Submit' + Math.random() + event_value: 'Case Submit' + Math.random(), }); const FAKE_CUSTOM_EVENT_WITHOUT_TYPE = new UserAction(UserActionType.Custom, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), - event_value: 'Case Submit' + Math.random() + event_value: 'Case Submit' + Math.random(), }); const IRRELEVANT_ACTIONS = [ new UserAction(UserActionType.Search, new Date(TEST_DATE_STRING), { origin_level_1: 'not relevant' + Math.random(), query_expression: 'not relevant', - cause: 'interfaceLoad' + cause: 'interfaceLoad', }), new UserAction(UserActionType.PageView, new Date(TEST_DATE_STRING), { origin_level_1: 'not relevant' + Math.random(), content_id_key: '@sysurihash', - content_id_value: 'product1' + content_id_value: 'product1', }), new UserAction(UserActionType.Custom, new Date(TEST_DATE_STRING), { origin_level_1: 'not relevant' + Math.random(), c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' + event_value: 'headphones-gaming', }), new UserAction(UserActionType.Custom, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' - }) + event_value: 'headphones-gaming', + }), ]; const FAKE_USER_ACTIONS = [ new UserAction(UserActionType.Search, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), cause: 'searchboxSubmit', - query_expression: 'Best product' + query_expression: 'Best product', }), new UserAction(UserActionType.Click, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), uri_hash: 'product' + Math.random(), c_contentidkey: '@sysurihash', - c_contentidvalue: 'product1' - }) + c_contentidvalue: 'product1', + }), ]; const getMockComponent = (returnedActions: UserAction | UserAction[]) => { return Mock.advancedComponentSetup( UserActivity, - new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: 'testuserId' }, (env) => { fakeUserProfileModel(env.root, sandbox).getActions.returns(Promise.resolve(returnedActions)); return env; }) @@ -111,7 +111,7 @@ describe('UserActivity', () => { it('should show the starting date and time of the user action session', () => { const mock = getMockComponent(FAKE_USER_ACTIONS); - const timestamps = FAKE_USER_ACTIONS.map(action => action.timestamp).sort(); + const timestamps = FAKE_USER_ACTIONS.map((action) => action.timestamp).sort(); return delay(() => { const firstAction = timestamps[0]; @@ -123,7 +123,7 @@ describe('UserActivity', () => { it('should duration of the user action session', () => { const mock = getMockComponent(FAKE_USER_ACTIONS); - const timestamps = FAKE_USER_ACTIONS.map(action => action.timestamp).sort(); + const timestamps = FAKE_USER_ACTIONS.map((action) => action.timestamp).sort(); return delay(() => { expect(mock.cmp.element.innerHTML).toMatch(formatTimeInterval(timestamps[timestamps.length - 1].getTime() - timestamps[0].getTime())); @@ -134,7 +134,7 @@ describe('UserActivity', () => { const mock = getMockComponent([...FAKE_USER_ACTIONS, ...IRRELEVANT_ACTIONS]); return delay(() => { - IRRELEVANT_ACTIONS.forEach(action => { + IRRELEVANT_ACTIONS.forEach((action) => { expect(mock.cmp.element.querySelector(ACTIVITY_SELECTOR).innerHTML).not.toMatch(action.raw.origin_level_1); }); }); @@ -144,7 +144,7 @@ describe('UserActivity', () => { const mock = getMockComponent([...FAKE_USER_ACTIONS, ...IRRELEVANT_ACTIONS]); return delay(() => { - FAKE_USER_ACTIONS.forEach(action => { + FAKE_USER_ACTIONS.forEach((action) => { expect(mock.cmp.element.querySelector(ACTIVITY_SELECTOR).innerHTML).toMatch(action.raw.origin_level_1); }); }); @@ -154,7 +154,7 @@ describe('UserActivity', () => { const mock = getMockComponent(IRRELEVANT_ACTIONS); return delay(() => { - IRRELEVANT_ACTIONS.forEach(action => { + IRRELEVANT_ACTIONS.forEach((action) => { expect(mock.cmp.element.querySelector(ACTIVITY_SELECTOR).innerHTML).toMatch(action.raw.origin_level_1); }); }); @@ -169,7 +169,7 @@ describe('UserActivity', () => { expect(folded).not.toBeNull(); folded.click(); - IRRELEVANT_ACTIONS.forEach(action => { + IRRELEVANT_ACTIONS.forEach((action) => { expect(mock.cmp.element.querySelector(ACTIVITY_SELECTOR).innerHTML).toMatch(action.raw.origin_level_1); }); }); @@ -177,14 +177,14 @@ describe('UserActivity', () => { }); describe('search event', () => { - ['omniboxAnalytics', 'userActionsSubmit', 'omniboxFromLink', 'searchboxAsYouType', 'searchboxSubmit', 'searchFromLink'].map(cause => { + ['omniboxAnalytics', 'userActionsSubmit', 'omniboxFromLink', 'searchboxAsYouType', 'searchboxSubmit', 'searchFromLink'].map((cause) => { it(`should display the "User Query" as event title when there is a query expression and the cause is ${cause}`, () => { const mock = getMockComponent([ new UserAction(UserActionType.Search, new Date(TEST_DATE_STRING), { origin_level_1: 'relevant' + Math.random(), query_expression: 'someSearch' + Math.random(), - cause: cause - }) + cause: cause, + }), ]); return delay(async () => { @@ -466,7 +466,7 @@ describe('UserActivity', () => { let getActionStub: SinonStub<[HTMLElement, UserActivity], void>; const mock = Mock.advancedComponentSetup( UserActivity, - new Mock.AdvancedComponentSetupOptions(null, { userId: null }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: null }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) @@ -481,7 +481,7 @@ describe('UserActivity', () => { let getActionStub: SinonStub<[HTMLElement, UserActivity], void>; const mock = Mock.advancedComponentSetup( UserActivity, - new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, env => { + new Mock.AdvancedComponentSetupOptions(null, { userId: '' }, (env) => { getActionStub = fakeUserProfileModel(env.root, sandbox).getActions; return env; }) diff --git a/tests/components/ViewedByCustomer/ViewedByCustomer.spec.ts b/tests/components/ViewedByCustomer/ViewedByCustomer.spec.ts index 112f1d5f..045e79f1 100644 --- a/tests/components/ViewedByCustomer/ViewedByCustomer.spec.ts +++ b/tests/components/ViewedByCustomer/ViewedByCustomer.spec.ts @@ -56,7 +56,7 @@ describe('ViewedByCustomer', () => { }); }); - [false, undefined, null].forEach(falsyValue => { + [false, undefined, null].forEach((falsyValue) => { describe(`when the field isUserActionView of the result is ${falsyValue}`, () => { const fakeResult: IQueryResult = { ...Fake.createFakeResult(), isUserActionView: falsyValue }; diff --git a/tests/models/UserProfilingModel.spec.ts b/tests/models/UserProfilingModel.spec.ts index 0ed23f5e..2139bc54 100644 --- a/tests/models/UserProfilingModel.spec.ts +++ b/tests/models/UserProfilingModel.spec.ts @@ -20,13 +20,13 @@ describe('UserProfilingModel', () => { c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' - } + event_value: 'headphones-gaming', + }, }, { name: UserActionType.Search, time: 1550509200357, - value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' } + value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' }, }, { name: UserActionType.Click, @@ -35,22 +35,22 @@ describe('UserProfilingModel', () => { uri_hash: 'product1', c_contentidkey: '@sysurihash', c_contentidvalue: 'product1', - origin_level_1: 'originLevel1' - } + origin_level_1: 'originLevel1', + }, }, { name: UserActionType.PageView, time: 1547571617714, - value: { content_id_key: '@sysurihash', origin_level_1: 'originLevel1', content_id_value: 'product1' } - } + value: { content_id_key: '@sysurihash', origin_level_1: 'originLevel1', content_id_value: 'product1' }, + }, ]; const FAKE_SEARCH_ACTION = { name: UserActionType.Search, time: 1550509200357, - value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' } + value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' }, }; - const FAKE_USER_ACTIONS = FAKE_HISTORY_ACTIONS.map(action => new UserAction(action.name, new Date(action.time), action.value)); + const FAKE_USER_ACTIONS = FAKE_HISTORY_ACTIONS.map((action) => new UserAction(action.name, new Date(action.time), action.value)); const FAKE_ACTIONS_WITH_URI_HASH = [ { name: UserActionType.Click, @@ -59,8 +59,8 @@ describe('UserProfilingModel', () => { uri_hash: TEST_URI_HASH, c_contentidkey: '@sysurihash', c_contentidvalue: 'product1', - origin_level_1: 'originLevel1' - } + origin_level_1: 'originLevel1', + }, }, { name: UserActionType.Click, @@ -69,8 +69,8 @@ describe('UserProfilingModel', () => { uri_hash: 'nodoc', c_contentidkey: '@sysurihash', c_contentidvalue: 'product1', - origin_level_1: 'originLevel1' - } + origin_level_1: 'originLevel1', + }, }, { name: UserActionType.Click, @@ -79,9 +79,9 @@ describe('UserProfilingModel', () => { uri_hash: TEST_URI_HASH, c_contentidkey: '@sysurihash', c_contentidvalue: 'product1', - origin_level_1: 'originLevel1' - } - } + origin_level_1: 'originLevel1', + }, + }, ]; let sandbox: sinon.SinonSandbox; @@ -118,13 +118,13 @@ describe('UserProfilingModel', () => { get: () => { wasAccessed = true; return buildAccessToken('toto'); - } + }, }); new UserProfileModel(document.createElement('div'), { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); expect(wasAccessed).toBe(true); @@ -142,7 +142,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -153,13 +153,13 @@ describe('UserProfilingModel', () => { ); const actions = await actionsPromise; - const actionsWithDocument = actions.filter(action => action.document); - const uniqueUriHashes = FAKE_ACTIONS_WITH_URI_HASH.map(x => x.value.uri_hash).filter((x, i, l) => l.indexOf(x) === i); + const actionsWithDocument = actions.filter((action) => action.document); + const uniqueUriHashes = FAKE_ACTIONS_WITH_URI_HASH.map((x) => x.value.uri_hash).filter((x, i, l) => l.indexOf(x) === i); expect(((endpoint.search.args[0][0] as unknown) as QueryBuilder).numberOfResults).toEqual(uniqueUriHashes.length); expect(actionsWithDocument.length).toBeGreaterThanOrEqual(documentResults.results.length); actionsWithDocument.forEach((action, i) => { - const matchingDocument = documentResults.results.find(document => document.raw.urihash === action.document.raw.urihash); + const matchingDocument = documentResults.results.find((document) => document.raw.urihash === action.document.raw.urihash); expect(matchingDocument).toBeDefined(); expect(action.document.title).toEqual(matchingDocument.title); @@ -174,7 +174,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -186,7 +186,7 @@ describe('UserProfilingModel', () => { ); const actions = await actionsPromise; - expect(actions.filter(action => action.document).length).toEqual(0); + expect(actions.filter((action) => action.document).length).toEqual(0); }); it('should attach no documents on click actions when the search call for documents details fails', async () => { @@ -197,7 +197,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -209,7 +209,7 @@ describe('UserProfilingModel', () => { ); const actions = await actionsPromise; - expect(actions.filter(action => action.document).length).toEqual(0); + expect(actions.filter((action) => action.document).length).toEqual(0); }); it('should not fetch documents when there is no event with an urihash', async () => { @@ -220,7 +220,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -232,7 +232,7 @@ describe('UserProfilingModel', () => { ); const actions = await actionsPromise; - expect(actions.filter(action => action.document).length).toEqual(0); + expect(actions.filter((action) => action.document).length).toEqual(0); }); it('should fetch all actions from a user', async () => { @@ -243,7 +243,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); model.registerNewAttribute(TEST_USER, FAKE_USER_ACTIONS); @@ -272,7 +272,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -307,7 +307,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); // Do a first call, it should do a callout. @@ -345,7 +345,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actionsPromise = model.getActions(TEST_USER); @@ -382,14 +382,18 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); // Store some actions beforehand. - model.set(TEST_USER, FAKE_HISTORY_ACTIONS.map(x => new UserAction(x.name, new Date(x.time), x.value)), { - silent: true, - customAttribute: true - }); + model.set( + TEST_USER, + FAKE_HISTORY_ACTIONS.map((x) => new UserAction(x.name, new Date(x.time), x.value)), + { + silent: true, + customAttribute: true, + } + ); const actionsPromise = model.getActions(TEST_USER); @@ -418,7 +422,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); model.deleteActions(TEST_USER); @@ -434,7 +438,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); model.getActions(TEST_USER); @@ -453,13 +457,17 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); - model.set(TEST_USER, FAKE_HISTORY_ACTIONS.map(x => new UserAction(x.name, new Date(x.time), x.value)), { - silent: true, - customAttribute: true - }); + model.set( + TEST_USER, + FAKE_HISTORY_ACTIONS.map((x) => new UserAction(x.name, new Date(x.time), x.value)), + { + silent: true, + customAttribute: true, + } + ); model.deleteActions(TEST_USER); @@ -475,7 +483,7 @@ describe('UserProfilingModel', () => { organizationId: TEST_ORGANIZATION, restUri: TEST_REST_URI, accessToken: TEST_TOKEN, - searchEndpoint: endpoint + searchEndpoint: endpoint, }); const actions1 = model.getActions(TEST_USER); diff --git a/tests/rest/UserProfilingEndpoint.spec.ts b/tests/rest/UserProfilingEndpoint.spec.ts index c735e3a7..bf57c773 100644 --- a/tests/rest/UserProfilingEndpoint.spec.ts +++ b/tests/rest/UserProfilingEndpoint.spec.ts @@ -17,13 +17,13 @@ describe('UserProfilingEndpoint', () => { c_contentidkey: '@sysurihash', c_contentidvalue: 'headphones-gaming', event_type: 'addPurchase', - event_value: 'headphones-gaming' - } + event_value: 'headphones-gaming', + }, }, { name: UserActionType.Search, time: 1550509200357, - value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' } + value: { cause: 'searchboxSubmit', query_expression: 'Best product', origin_level_1: 'originLevel1' }, }, { name: UserActionType.Click, @@ -32,14 +32,14 @@ describe('UserProfilingEndpoint', () => { uri_hash: 'product1', c_contentidkey: '@sysurihash', c_contentidvalue: 'product1', - origin_level_1: 'originLevel1' - } + origin_level_1: 'originLevel1', + }, }, { name: UserActionType.PageView, time: 1547571617714, - value: { content_id_key: '@sysurihash', origin_level_1: 'originLevel1', content_id_value: 'product1' } - } + value: { content_id_key: '@sysurihash', origin_level_1: 'originLevel1', content_id_value: 'product1' }, + }, ]; let sandbox: sinon.SinonSandbox; @@ -55,7 +55,7 @@ describe('UserProfilingEndpoint', () => { xhr = sandbox.useFakeXMLHttpRequest(); request = []; - xhr.onCreate = req => { + xhr.onCreate = (req) => { request.push(req); }; }); @@ -72,7 +72,7 @@ describe('UserProfilingEndpoint', () => { it('should override the uri with the default uri when none is given as an option', () => { const endpoint = new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), - organization: TEST_ORGANIZATION + organization: TEST_ORGANIZATION, }); expect(endpoint.options.uri).toEqual(UserProfilingEndpoint.DEFAULT_URI); @@ -84,7 +84,7 @@ describe('UserProfilingEndpoint', () => { new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), organization: TEST_ORGANIZATION, - uri: TEST_URI + uri: TEST_URI, }).getActions(TEST_USER_ID); const LAST_REQUEST = request[request.length - 1]; @@ -100,7 +100,7 @@ describe('UserProfilingEndpoint', () => { const RESPONSE = new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), organization: TEST_ORGANIZATION, - uri: TEST_URI + uri: TEST_URI, }).getActions(TEST_USER_ID); request[request.length - 1].respond( @@ -124,7 +124,7 @@ describe('UserProfilingEndpoint', () => { const RESPONSE = new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), organization: TEST_ORGANIZATION, - uri: TEST_URI + uri: TEST_URI, }).getActions(TEST_USER_ID); request[request.length - 1].respond( @@ -145,7 +145,7 @@ describe('UserProfilingEndpoint', () => { const RESPONSE = new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), organization: TEST_ORGANIZATION, - uri: TEST_URI + uri: TEST_URI, }).getActions(TEST_USER_ID); request[request.length - 1].respond( @@ -168,7 +168,7 @@ describe('UserProfilingEndpoint', () => { const RESPONSE = new UserProfilingEndpoint({ accessToken: buildAccessToken(TEST_ACCESS_TOKEN), organization: TEST_ORGANIZATION, - uri: TEST_URI + uri: TEST_URI, }).getActions(TEST_USER_ID); request[request.length - 1].respond(400, {}, ''); diff --git a/tests/utils.ts b/tests/utils.ts index c0c3607d..0dc3ca39 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -11,7 +11,7 @@ export function buildAccessToken(token: string) { return new SearchEndpoint({ accessToken: token, renewAccessToken: () => Promise.resolve(token), - restUri: 'https://test.uri.test' + restUri: 'https://test.uri.test', }).accessToken; } @@ -23,16 +23,16 @@ export function buildActionHistoryResponse(actions: IActionHistory[]) { return { value: actions && - actions.map(action => { + actions.map((action) => { return { name: action.name, time: action.time.toString(), - value: JSON.stringify(action.value, null, 0) + value: JSON.stringify(action.value, null, 0), }; }), debug: false, internalExecutionLog: [''], - executionTime: 0.949252553 + executionTime: 0.949252553, }; } @@ -55,7 +55,7 @@ export function generate(time: number, generator: (i: number) => T): T[] { * @param timemout The timeout to wait. */ export function delay(callback: () => any, timemout = 0) { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve(callback()); }, timemout);