From 6afe89335998bebb0e124799167e15e17f406088 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 4 Dec 2020 18:02:55 +1100 Subject: [PATCH] fix up a few test --- styleguide.config.js | 4 - stylesheets/manifest.scss | 4 + ts/styleguide/ConversationContext.md | 7 - ts/styleguide/ConversationContext.tsx | 33 ----- ts/styleguide/StyleGuideUtil.ts | 121 ------------------ ts/styleguide/tslint.json | 11 -- .../linkPreviews/linkPreviewFetch_test.ts | 2 +- ts/test/types/Attachment_test.ts | 19 ++- ts/types/Attachment.ts | 4 - ts/util/lint/exceptions.json | 35 +---- ts/util/lint/linter.ts | 1 - yarn.lock | 62 ++++++--- 12 files changed, 67 insertions(+), 236 deletions(-) delete mode 100644 ts/styleguide/ConversationContext.md delete mode 100644 ts/styleguide/ConversationContext.tsx delete mode 100644 ts/styleguide/StyleGuideUtil.ts delete mode 100644 ts/styleguide/tslint.json diff --git a/styleguide.config.js b/styleguide.config.js index c58cf7d82..95e700262 100644 --- a/styleguide.config.js +++ b/styleguide.config.js @@ -32,10 +32,6 @@ module.exports = { components: 'ts/styleguide/**/*.tsx', }, ], - context: { - // Exposes necessary utilities in the global scope for all readme code snippets - util: 'ts/styleguide/StyleGuideUtil', - }, contextDependencies: [path.join(__dirname, 'ts/styleguide')], // We don't want one long, single page pagePerSection: true, diff --git a/stylesheets/manifest.scss b/stylesheets/manifest.scss index e9d03b0a7..9691f822c 100644 --- a/stylesheets/manifest.scss +++ b/stylesheets/manifest.scss @@ -4,6 +4,10 @@ @import 'node_modules/react-contexify/dist/ReactContexify.min.css'; @import 'node_modules/react-toastify/dist/ReactToastify.css'; +@import 'node_modules/sanitize.css/sanitize.css'; +@import 'node_modules/sanitize.css/forms.css'; +@import 'node_modules/sanitize.css/typography.css'; + // Global Settings, Variables, and Mixins @import 'themes.scss'; @import 'session_constants'; diff --git a/ts/styleguide/ConversationContext.md b/ts/styleguide/ConversationContext.md deleted file mode 100644 index c83b35951..000000000 --- a/ts/styleguide/ConversationContext.md +++ /dev/null @@ -1,7 +0,0 @@ -The simplest example of using the `` component: - -```jsx - -
Just a plain bit of text
-
-``` diff --git a/ts/styleguide/ConversationContext.tsx b/ts/styleguide/ConversationContext.tsx deleted file mode 100644 index c59b2fb0b..000000000 --- a/ts/styleguide/ConversationContext.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react'; -import classNames from 'classnames'; - -interface Props { - /** - * Corresponds to the theme setting in the app, and the class added to the root element. - */ - ios: boolean; - theme: 'light-theme' | 'dark-theme'; - type: 'private' | 'group'; -} - -/** - * Provides the parent elements necessary to allow the main Signal Desktop stylesheet to - * apply (with no changes) to messages in the Style Guide. - */ -export class ConversationContext extends React.Component { - public render() { - const { ios, theme, type } = this.props; - - return ( -
-
-
-
    {this.props.children}
-
-
-
- ); - } -} diff --git a/ts/styleguide/StyleGuideUtil.ts b/ts/styleguide/StyleGuideUtil.ts deleted file mode 100644 index 99bd2db4b..000000000 --- a/ts/styleguide/StyleGuideUtil.ts +++ /dev/null @@ -1,121 +0,0 @@ -import QueryString from 'qs'; -import classNames from 'classnames'; - -// This file provides helpers for the Style Guide, exposed at 'util' in the global scope -// via the 'context' option in react-styleguidist. - -import { default as _ } from 'lodash'; -export { ConversationContext } from './ConversationContext'; - -export { _, classNames }; - -// TypeScript wants two things when you import: -// 1) a normal typescript file -// 2) a javascript file with type definitions -// Anything else will raise an error, that it can't find the module. And so, we ignore... - -// @ts-ignore -import gif from '../../fixtures/giphy-GVNvOUpeYmI7e.gif'; -// 320x240 -const gifObjectUrl = makeObjectUrl(gif, 'image/gif'); -// @ts-ignore -import mp3 from '../../fixtures/incompetech-com-Agnus-Dei-X.mp3'; -const mp3ObjectUrl = makeObjectUrl(mp3, 'audio/mp3'); -// @ts-ignore -import txt from '../../fixtures/lorem-ipsum.txt'; -const txtObjectUrl = makeObjectUrl(txt, 'text/plain'); -// @ts-ignore -import mp4 from '../../fixtures/pixabay-Soap-Bubble-7141.mp4'; -const mp4ObjectUrl = makeObjectUrl(mp4, 'video/mp4'); -// @ts-ignore -import mp4v2 from '../../fixtures/ghost-kitty.mp4'; -const mp4ObjectUrlV2 = makeObjectUrl(mp4v2, 'video/mp4'); -// @ts-ignore -import png from '../../fixtures/freepngs-2cd43b_bed7d1327e88454487397574d87b64dc_mv2.png'; -// 800×1200 -const pngObjectUrl = makeObjectUrl(png, 'image/png'); - -// @ts-ignore -import landscape from '../../fixtures/koushik-chowdavarapu-105425-unsplash.jpg'; -// 800×1200 -const landscapeObjectUrl = makeObjectUrl(landscape, 'image/png'); - -// @ts-ignore -import landscapeGreen from '../../fixtures/1000x50-green.jpeg'; -const landscapeGreenObjectUrl = makeObjectUrl(landscapeGreen, 'image/jpeg'); -// @ts-ignore -import landscapePurple from '../../fixtures/200x50-purple.png'; -const landscapePurpleObjectUrl = makeObjectUrl(landscapePurple, 'image/png'); -// @ts-ignore -import portraitYellow from '../../fixtures/20x200-yellow.png'; -const portraitYellowObjectUrl = makeObjectUrl(portraitYellow, 'image/png'); -// @ts-ignore -import landscapeRed from '../../fixtures/300x1-red.jpeg'; -const landscapeRedObjectUrl = makeObjectUrl(landscapeRed, 'image/png'); -// @ts-ignore -import portraitTeal from '../../fixtures/50x1000-teal.jpeg'; -const portraitTealObjectUrl = makeObjectUrl(portraitTeal, 'image/png'); - -function makeObjectUrl(data: ArrayBuffer, contentType: string): string { - const blob = new Blob([data], { - type: contentType, - }); - - return URL.createObjectURL(blob); -} - -export { - mp3, - mp3ObjectUrl, - gif, - gifObjectUrl, - mp4, - mp4ObjectUrl, - mp4v2, - mp4ObjectUrlV2, - png, - pngObjectUrl, - txt, - txtObjectUrl, - landscape, - landscapeObjectUrl, - landscapeGreen, - landscapeGreenObjectUrl, - landscapePurple, - landscapePurpleObjectUrl, - portraitYellow, - portraitYellowObjectUrl, - landscapeRed, - landscapeRedObjectUrl, - portraitTeal, - portraitTealObjectUrl, -}; - -const query = window.location.search.replace(/^\?/, ''); -const urlOptions = QueryString.parse(query); -const theme = urlOptions.theme || 'light-theme'; -const ios = urlOptions.ios || false; -const locale = urlOptions.locale || 'en'; - -// @ts-ignore -import localeMessages from '../../_locales/en/messages.json'; - -// @ts-ignore -import { setup } from '../../js/modules/i18n'; -const i18n = setup(locale, localeMessages); - -export { theme, ios, locale, i18n }; - -// Telling Lodash to relinquish _ for use by underscore -// @ts-ignore -_.noConflict(); - -// @ts-ignore -window.log = { - // tslint:disable-next-line no-console - info: console.log, - // tslint:disable-next-line no-console - error: console.error, - // tslint:disable-next-line no-console - warn: console.warn, -}; diff --git a/ts/styleguide/tslint.json b/ts/styleguide/tslint.json deleted file mode 100644 index 4645335d0..000000000 --- a/ts/styleguide/tslint.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "defaultSeverity": "error", - "extends": ["../../tslint.json"], - "rules": { - // To allow the use of devDependencies here - "no-implicit-dependencies": false, - - // All tests use arrow functions, and they can be long - "max-func-body-length": false - } -} diff --git a/ts/test/test-electron/linkPreviews/linkPreviewFetch_test.ts b/ts/test/test-electron/linkPreviews/linkPreviewFetch_test.ts index 0e3e431e8..37f4dc04d 100644 --- a/ts/test/test-electron/linkPreviews/linkPreviewFetch_test.ts +++ b/ts/test/test-electron/linkPreviews/linkPreviewFetch_test.ts @@ -26,7 +26,7 @@ describe('link preview fetching', () => { beforeEach(() => { sandbox = sinon.createSandbox(); - warn = sandbox.stub(window.log, 'warn'); + // warn = sandbox.stub(window.log, 'warn'); }); afterEach(() => { diff --git a/ts/test/types/Attachment_test.ts b/ts/test/types/Attachment_test.ts index 6d2c15ff3..3e3d188f0 100644 --- a/ts/test/types/Attachment_test.ts +++ b/ts/test/types/Attachment_test.ts @@ -14,7 +14,7 @@ describe('Attachment', () => { const input: Attachment.AttachmentType = { fileName: 'funny-cat.mov', url: 'funny-cat.mov', - contentType: MIME.VIDEO_QUICKTIME, + contentType: MIME.IMAGE_GIF, }; assert.strictEqual(Attachment.getFileExtension(input), 'gif'); }); @@ -31,14 +31,27 @@ describe('Attachment', () => { describe('getSuggestedFilename', () => { context('for attachment with filename', () => { - it('should return existing filename if present', () => { + it('should generate a filename without timestamp', () => { const attachment: Attachment.AttachmentType = { fileName: 'funny-cat.mov', url: 'funny-cat.mov', contentType: MIME.VIDEO_QUICKTIME, }; const actual = Attachment.getSuggestedFilename({ attachment }); - const expected = 'funny-cat.mov'; + const expected = 'session-attachment.mov'; + assert.strictEqual(actual, expected); + }); + it('should generate a filename without timestamp but with an index', () => { + const attachment: Attachment.AttachmentType = { + fileName: 'funny-cat.mov', + url: 'funny-cat.mov', + contentType: MIME.VIDEO_QUICKTIME, + }; + const actual = Attachment.getSuggestedFilename({ + attachment, + index: 3, + }); + const expected = 'session-attachment_003.mov'; assert.strictEqual(actual, expected); }); }); diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index bda7d3f94..76b99c5a2 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -364,10 +364,6 @@ export const getSuggestedFilename = ({ timestamp?: number | Date; index?: number; }): string => { - if (attachment.fileName) { - return attachment.fileName; - } - const prefix = 'session-attachment'; const suffix = timestamp ? moment(timestamp).format('-YYYY-MM-DD-HHmmss') diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index df731cdb0..def57ebc2 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -372,7 +372,6 @@ "updated": "2018-09-19T18:13:29.628Z", "reasonDetail": "Interacting with already-existing DOM nodes" }, - { "rule": "jQuery-$(", "path": "js/views/debug_log_view.js", @@ -4508,38 +4507,6 @@ "reasonCategory": "falseMatch", "updated": "2018-09-19T21:59:32.770Z" }, - { - "rule": "jQuery-$(", - "path": "node_modules/node-gyp/lib/configure.js", - "line": " !gyp.opts.nodedir ? '<(target_arch)' : '$(Configuration)',", - "lineNumber": 296, - "reasonCategory": "falseMatch", - "updated": "2018-09-19T21:59:32.770Z" - }, - { - "rule": "jQuery-append(", - "path": "node_modules/node-gyp/node_modules/request/lib/multipart.js", - "line": " return chunked ? body.append(part) : body.push(Buffer.from(part))", - "lineNumber": 74, - "reasonCategory": "falseMatch", - "updated": "2018-09-19T18:13:29.628Z" - }, - { - "rule": "jQuery-append(", - "path": "node_modules/node-gyp/node_modules/request/request.js", - "line": " requestForm.append(key, value.value, value.options)", - "lineNumber": 324, - "reasonCategory": "falseMatch", - "updated": "2018-09-19T18:13:29.628Z" - }, - { - "rule": "jQuery-append(", - "path": "node_modules/node-gyp/node_modules/request/request.js", - "line": " requestForm.append(key, value)", - "lineNumber": 326, - "reasonCategory": "falseMatch", - "updated": "2018-09-19T18:13:29.628Z" - }, { "rule": "jQuery-wrap(", "path": "node_modules/optionator/lib/help.js", @@ -5907,4 +5874,4 @@ "updated": "2019-03-09T00:08:44.242Z", "reasonDetail": "Used only to trigger menu display" } -] +] \ No newline at end of file diff --git a/ts/util/lint/linter.ts b/ts/util/lint/linter.ts index 36c8462ab..dc24c379e 100644 --- a/ts/util/lint/linter.ts +++ b/ts/util/lint/linter.ts @@ -110,7 +110,6 @@ const excludedFiles = [ '^node_modules/eslint*', '^node_modules/esprima/*', '^node_modules/express/*', - '^node_modules/extract-zip/*', '^node_modules/finalhandler/*', '^node_modules/fsevents/*', '^node_modules/globule/*', diff --git a/yarn.lock b/yarn.lock index ca182ac06..3c33724fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -856,7 +856,12 @@ address@^1.0.1: resolved "https://registry.yarnpkg.com/address/-/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6" integrity sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA== -ajv-keywords@^3.0.0, ajv-keywords@^3.1.0: +ajv-keywords@^3.0.0: + version "3.5.2" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" + integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== + +ajv-keywords@^3.1.0: version "3.4.1" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.4.1.tgz#ef916e271c64ac12171fd8384eaae6b2345854da" integrity sha512-RO1ibKvd27e6FEShVFfPALuHI3WjSVNeK5FIsmme/LYRNxjKuNj+Dt7bucLa6NdSv3JcVTyMlm9kGR84z1XpaQ== @@ -876,7 +881,17 @@ ajv@^5.1.0, ajv@^5.3.0: fast-json-stable-stringify "^2.0.0" json-schema-traverse "^0.3.0" -ajv@^6.0.1, ajv@^6.1.0, ajv@^6.5.5: +ajv@^6.0.1: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + +ajv@^6.1.0, ajv@^6.5.5: version "6.12.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.0.tgz#06d60b96d87b8454a5adaba86e7854da629db4b7" integrity sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw== @@ -3686,17 +3701,17 @@ eslint-config-prettier@2.9.0: get-stdin "^5.0.1" eslint-import-resolver-node@^0.3.1: - version "0.3.3" - resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.3.tgz#dbaa52b6b2816b50bc6711af75422de808e98404" - integrity sha512-b8crLDo0M5RSe5YG8Pu2DYBj71tSB6OvXkfzwbJU2w7y8P4/yo0MyF8jU26IEuEuHF2K5/gcAJE3LhQGqBBbVg== + version "0.3.4" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz#85ffa81942c25012d8231096ddf679c03042c717" + integrity sha512-ogtf+5AB/O+nM6DIeBUNr2fuT7ot9Qg/1harBfBtaP13ekEWFQEEMP94BCB7zaNW3gyY+8SHYF00rnqYwXKWOA== dependencies: debug "^2.6.9" resolve "^1.13.1" eslint-module-utils@^2.1.1: - version "2.5.2" - resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.5.2.tgz#7878f7504824e1b857dd2505b59a8e5eda26a708" - integrity sha512-LGScZ/JSlqGKiT8OC+cYRxseMjyqt6QO54nl281CK93unD89ijSeRV6An8Ci/2nvWVKe8K/Tqdm75RQoIOCr+Q== + version "2.6.0" + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz#579ebd094f56af7797d19c9866c9c9486629bfa6" + integrity sha512-6j9xxegbqe8/kZY8cYpcp0xhbK0EgJlg3g9mib3/miLaExuuwc3n5UEfSnU6hWMbT0FAYVvDbL9RrRgpUeQIvA== dependencies: debug "^2.6.9" pkg-dir "^2.0.0" @@ -3743,9 +3758,9 @@ eslint-scope@^3.7.1: estraverse "^4.1.1" eslint-visitor-keys@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" - integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== + version "1.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" + integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== eslint@4.14.0: version "4.14.0" @@ -3809,11 +3824,11 @@ esprima@^4.0.0, esprima@^4.0.1, esprima@~4.0.0: integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== esquery@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.1.0.tgz#c5c0b66f383e7656404f86b31334d72524eddb48" - integrity sha512-MxYW9xKmROWF672KqjO75sszsA8Mxhw06YFeS5VHlB98KDHbOSurm3ArsjO60Eaf3QmGMCP1yn+0JQkNLo/97Q== + version "1.3.1" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.3.1.tgz#b78b5828aa8e214e29fb74c4d5b752e1c033da57" + integrity sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ== dependencies: - estraverse "^4.0.0" + estraverse "^5.1.0" esrecurse@^4.1.0: version "4.2.1" @@ -3822,11 +3837,16 @@ esrecurse@^4.1.0: dependencies: estraverse "^4.1.0" -estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0: +estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0: version "4.3.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== +estraverse@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.2.0.tgz#307df42547e6cc7324d3cf03c155d5cdb8c53880" + integrity sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ== + esutils@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" @@ -5970,7 +5990,7 @@ js-tokens@^3.0.2: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= -js-yaml@^3.13.1, js-yaml@^3.2.7, js-yaml@^3.9.1: +js-yaml@^3.13.1, js-yaml@^3.2.7: version "3.13.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== @@ -5978,6 +5998,14 @@ js-yaml@^3.13.1, js-yaml@^3.2.7, js-yaml@^3.9.1: argparse "^1.0.7" esprima "^4.0.0" +js-yaml@^3.9.1: + version "3.14.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482" + integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + js-yaml@~3.5.2: version "3.5.5" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.5.5.tgz#0377c38017cabc7322b0d1fbcd25a491641f2fbe"