From cbb3d08e13feddbd80f6f2f9f5680402f7d3e6ad Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Fri, 11 Feb 2022 19:51:52 +0700 Subject: [PATCH 1/7] feat(jest): 100% code coverage for Commands.test.ts --- libraries/ui/Commands.test.ts | 33 +++++++++++++++++++ libraries/ui/Commands.ts | 8 +++++ .../ui/__snapshots__/Commands.test.ts.snap | 2 ++ 3 files changed, 43 insertions(+) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index 38f36bbf8d..b7c7607401 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -173,4 +173,37 @@ describe('Commands.isArgsValid', () => { ) expect(result).toMatchSnapshot() }) + + test('6', () => { + const object: any = [ + { + name: '1.0.0', + options: + 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22undefined%22%20height%3D%22undefined%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22NaN%22%20y%3D%22NaN%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3Eundefinedxundefined%3C%2Ftext%3E%3C%2Fsvg%3E', + }, + ] + const result: any = Commands.isArgsValid( + { name: 'Edmond', description: 'Print Base', args: object }, + ['1.0.0', '^5.0.0', '^5.0.0', 'v4.0.0-rc.4', '4.0.0-beta1\t'], + ) + expect(result).toMatchSnapshot() + }) + + describe('Commands.hasCommandPreview', () => { + test('0', () => { + const object: string = '/a' + // Regex is [a-z0-9], hence everything that is in these is valid. + // Other condition that we need to consider so that it passes the test is that: + // it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) + // AND + // the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). + const result: any = Commands.hasCommandPreview(object) + expect(result).toBeTruthy() + }) + test('1', () => { + const object: string = 'ABC' // ABC is not in [a-z0-9], it would be in it if it was rather [a-zA-Z0-9]. + const result: any = Commands.hasCommandPreview(object) + expect(result).toBeFalsy() + }) + }) }) diff --git a/libraries/ui/Commands.ts b/libraries/ui/Commands.ts index 869c850148..09ef438d18 100644 --- a/libraries/ui/Commands.ts +++ b/libraries/ui/Commands.ts @@ -11,6 +11,14 @@ export const commandPrefix = '/' */ export function containsCommand(text: string) { const cmd = text.split(' ')[0].replace(commandPrefix, '') + console.log(1, cmd, text) + console.log( + 2, + text.charAt(0) === commandPrefix, + text.charAt(0), + commandPrefix, + ) + console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1) return ( text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) // the || part is needed for showing all the available commands after writing the commandPrefix diff --git a/libraries/ui/__snapshots__/Commands.test.ts.snap b/libraries/ui/__snapshots__/Commands.test.ts.snap index 53fec42204..d610587f26 100644 --- a/libraries/ui/__snapshots__/Commands.test.ts.snap +++ b/libraries/ui/__snapshots__/Commands.test.ts.snap @@ -24,6 +24,8 @@ exports[`Commands.isArgsValid 4 1`] = `false`; exports[`Commands.isArgsValid 5 1`] = `true`; +exports[`Commands.isArgsValid 6 1`] = `true`; + exports[`Commands.parseCommand 0 1`] = ` Object { "args": Array [ From 9aea1728d1587e17b3e311242025d92fb2c0f3e1 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Fri, 11 Feb 2022 19:54:56 +0700 Subject: [PATCH 2/7] update(jest): more valid comments for the object passed into the function --- libraries/ui/Commands.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index b7c7607401..591317b116 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -201,7 +201,11 @@ describe('Commands.isArgsValid', () => { expect(result).toBeTruthy() }) test('1', () => { - const object: string = 'ABC' // ABC is not in [a-z0-9], it would be in it if it was rather [a-zA-Z0-9]. + const object: string = 'ABC' // A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) + // Though what makes this string above invalid is because it does not adhere to both the condition of + // text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) + // It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. + // And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` const result: any = Commands.hasCommandPreview(object) expect(result).toBeFalsy() }) From c153c7a68e1ff00511f5d4485a028f09094da2b1 Mon Sep 17 00:00:00 2001 From: Sara Tavares <29093946+stavares843@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:43:27 +0000 Subject: [PATCH 3/7] chore(update): multi line comment, remove log --- libraries/ui/Commands.test.ts | 21 +++++++++++---------- libraries/ui/Commands.ts | 8 +------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index 591317b116..75183c150e 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -192,20 +192,21 @@ describe('Commands.isArgsValid', () => { describe('Commands.hasCommandPreview', () => { test('0', () => { const object: string = '/a' - // Regex is [a-z0-9], hence everything that is in these is valid. - // Other condition that we need to consider so that it passes the test is that: - // it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) - // AND - // the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). + /* Regex is [a-z0-9], hence everything that is in these is valid. + Other condition that we need to consider so that it passes the test is that: + it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) + AND + the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). */ const result: any = Commands.hasCommandPreview(object) expect(result).toBeTruthy() }) test('1', () => { - const object: string = 'ABC' // A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) - // Though what makes this string above invalid is because it does not adhere to both the condition of - // text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) - // It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. - // And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` + const object: string = + 'ABC' /* A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) + Though what makes this string above invalid is because it does not adhere to both the condition of + text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) + It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. + And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` */ const result: any = Commands.hasCommandPreview(object) expect(result).toBeFalsy() }) diff --git a/libraries/ui/Commands.ts b/libraries/ui/Commands.ts index 09ef438d18..b8cdf47d4c 100644 --- a/libraries/ui/Commands.ts +++ b/libraries/ui/Commands.ts @@ -11,13 +11,7 @@ export const commandPrefix = '/' */ export function containsCommand(text: string) { const cmd = text.split(' ')[0].replace(commandPrefix, '') - console.log(1, cmd, text) - console.log( - 2, - text.charAt(0) === commandPrefix, - text.charAt(0), - commandPrefix, - ) + console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1) return ( text.charAt(0) === commandPrefix && From ec510c582f700fd327472da8ac441098ac4bb09e Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Fri, 11 Feb 2022 19:51:52 +0700 Subject: [PATCH 4/7] feat(jest): 100% code coverage for Commands.test.ts --- libraries/ui/Commands.test.ts | 33 +++++++++++++++++++ libraries/ui/Commands.ts | 8 +++++ .../ui/__snapshots__/Commands.test.ts.snap | 2 ++ 3 files changed, 43 insertions(+) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index a9af8659ba..35db162e4d 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -172,4 +172,37 @@ describe('Commands.isArgsValid', () => { ) expect(result).toMatchSnapshot() }) + + test('6', () => { + const object: any = [ + { + name: '1.0.0', + options: + 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22undefined%22%20height%3D%22undefined%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%3Ctext%20x%3D%22NaN%22%20y%3D%22NaN%22%20font-size%3D%2220%22%20alignment-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20fill%3D%22white%22%3Eundefinedxundefined%3C%2Ftext%3E%3C%2Fsvg%3E', + }, + ] + const result: any = Commands.isArgsValid( + { name: 'Edmond', description: 'Print Base', args: object }, + ['1.0.0', '^5.0.0', '^5.0.0', 'v4.0.0-rc.4', '4.0.0-beta1\t'], + ) + expect(result).toMatchSnapshot() + }) + + describe('Commands.hasCommandPreview', () => { + test('0', () => { + const object: string = '/a' + // Regex is [a-z0-9], hence everything that is in these is valid. + // Other condition that we need to consider so that it passes the test is that: + // it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) + // AND + // the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). + const result: any = Commands.hasCommandPreview(object) + expect(result).toBeTruthy() + }) + test('1', () => { + const object: string = 'ABC' // ABC is not in [a-z0-9], it would be in it if it was rather [a-zA-Z0-9]. + const result: any = Commands.hasCommandPreview(object) + expect(result).toBeFalsy() + }) + }) }) diff --git a/libraries/ui/Commands.ts b/libraries/ui/Commands.ts index 869c850148..09ef438d18 100644 --- a/libraries/ui/Commands.ts +++ b/libraries/ui/Commands.ts @@ -11,6 +11,14 @@ export const commandPrefix = '/' */ export function containsCommand(text: string) { const cmd = text.split(' ')[0].replace(commandPrefix, '') + console.log(1, cmd, text) + console.log( + 2, + text.charAt(0) === commandPrefix, + text.charAt(0), + commandPrefix, + ) + console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1) return ( text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) // the || part is needed for showing all the available commands after writing the commandPrefix diff --git a/libraries/ui/__snapshots__/Commands.test.ts.snap b/libraries/ui/__snapshots__/Commands.test.ts.snap index 53fec42204..d610587f26 100644 --- a/libraries/ui/__snapshots__/Commands.test.ts.snap +++ b/libraries/ui/__snapshots__/Commands.test.ts.snap @@ -24,6 +24,8 @@ exports[`Commands.isArgsValid 4 1`] = `false`; exports[`Commands.isArgsValid 5 1`] = `true`; +exports[`Commands.isArgsValid 6 1`] = `true`; + exports[`Commands.parseCommand 0 1`] = ` Object { "args": Array [ From d5db36c99d44289d5494d71d9f04533cb484a1e9 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Fri, 11 Feb 2022 19:54:56 +0700 Subject: [PATCH 5/7] update(jest): more valid comments for the object passed into the function --- libraries/ui/Commands.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index 35db162e4d..e8468aacb5 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -200,7 +200,11 @@ describe('Commands.isArgsValid', () => { expect(result).toBeTruthy() }) test('1', () => { - const object: string = 'ABC' // ABC is not in [a-z0-9], it would be in it if it was rather [a-zA-Z0-9]. + const object: string = 'ABC' // A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) + // Though what makes this string above invalid is because it does not adhere to both the condition of + // text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) + // It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. + // And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` const result: any = Commands.hasCommandPreview(object) expect(result).toBeFalsy() }) From 1c9a3e06af4ba236c2d8b3527c43a856f9fff873 Mon Sep 17 00:00:00 2001 From: Sara Tavares <29093946+stavares843@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:43:27 +0000 Subject: [PATCH 6/7] chore(update): multi line comment, remove log --- libraries/ui/Commands.test.ts | 21 +++++++++++---------- libraries/ui/Commands.ts | 8 +------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libraries/ui/Commands.test.ts b/libraries/ui/Commands.test.ts index e8468aacb5..717133e113 100644 --- a/libraries/ui/Commands.test.ts +++ b/libraries/ui/Commands.test.ts @@ -191,20 +191,21 @@ describe('Commands.isArgsValid', () => { describe('Commands.hasCommandPreview', () => { test('0', () => { const object: string = '/a' - // Regex is [a-z0-9], hence everything that is in these is valid. - // Other condition that we need to consider so that it passes the test is that: - // it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) - // AND - // the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). + /* Regex is [a-z0-9], hence everything that is in these is valid. + Other condition that we need to consider so that it passes the test is that: + it will return true if either the string has / at the start (text.charAt(0) === commandPrefix) + AND + the text is valid for the regex (/^[a-z0-9]+$/i) and has a length of 1 (/ab has a length of 2). */ const result: any = Commands.hasCommandPreview(object) expect(result).toBeTruthy() }) test('1', () => { - const object: string = 'ABC' // A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) - // Though what makes this string above invalid is because it does not adhere to both the condition of - // text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) - // It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. - // And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` + const object: string = + 'ABC' /* A-Z is in [a-z0-9] because of the `i` flag at the end of the regex (/^[a-z0-9]+$/i) + Though what makes this string above invalid is because it does not adhere to both the condition of + text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) + It does not have `/` at the start, hence not adhering to text.charAt(0) === commandPrefix. + And though it adheres to `(cmd.match(/^[a-z0-9]+$/i)`, it does not adhere to `text.length === 1` */ const result: any = Commands.hasCommandPreview(object) expect(result).toBeFalsy() }) diff --git a/libraries/ui/Commands.ts b/libraries/ui/Commands.ts index 09ef438d18..b8cdf47d4c 100644 --- a/libraries/ui/Commands.ts +++ b/libraries/ui/Commands.ts @@ -11,13 +11,7 @@ export const commandPrefix = '/' */ export function containsCommand(text: string) { const cmd = text.split(' ')[0].replace(commandPrefix, '') - console.log(1, cmd, text) - console.log( - 2, - text.charAt(0) === commandPrefix, - text.charAt(0), - commandPrefix, - ) + console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1) return ( text.charAt(0) === commandPrefix && From a6a0de0868f3f31e4526b278484a27a39d2bd959 Mon Sep 17 00:00:00 2001 From: Sara Tavares <29093946+stavares843@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:45:18 +0000 Subject: [PATCH 7/7] chore(update): remove log --- libraries/ui/Commands.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/ui/Commands.ts b/libraries/ui/Commands.ts index b8cdf47d4c..b74a845f33 100644 --- a/libraries/ui/Commands.ts +++ b/libraries/ui/Commands.ts @@ -12,7 +12,6 @@ export const commandPrefix = '/' export function containsCommand(text: string) { const cmd = text.split(' ')[0].replace(commandPrefix, '') - console.log(3, cmd, text, cmd.match(/^[a-z0-9]+$/i), text.length === 1) return ( text.charAt(0) === commandPrefix && (cmd.match(/^[a-z0-9]+$/i) || text.length === 1) // the || part is needed for showing all the available commands after writing the commandPrefix