Skip to content

Commit

Permalink
Use hex value for snapshots and extend test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Aug 25, 2020
1 parent dadc804 commit 25bd5a2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 211 deletions.
2 changes: 1 addition & 1 deletion build/usernameToColor-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ const snapshot = require('./../src/functions/usernameToColor/__snapshots__/usern
const result = {}
Object.keys(snapshot).map((key) => {
const uid = key.replace('usernameToColor ', '').replace(' has the proper color 1', '')
result[uid] = JSON.parse(snapshot[key].replace('Color ', '').replace(",\n}\n", "}"))
result[uid] = JSON.parse(snapshot[key])
})
console.log(JSON.stringify(result))
278 changes: 71 additions & 207 deletions src/functions/usernameToColor/__snapshots__/usernameToColor.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,209 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`usernameToColor Akeel Robertson has the proper color 1`] = `
Color {
"b": 164,
"g": 80,
"r": 151,
}
`;

exports[`usernameToColor Alishia Ann Lowry has the proper color 1`] = `
Color {
"b": 109,
"g": 158,
"r": 208,
}
`;

exports[`usernameToColor Arham Johnson has the proper color 1`] = `
Color {
"b": 201,
"g": 130,
"r": 0,
}
`;

exports[`usernameToColor Brayden Truong has the proper color 1`] = `
Color {
"b": 109,
"g": 158,
"r": 208,
}
`;

exports[`usernameToColor Daphne Roy has the proper color 1`] = `
Color {
"b": 164,
"g": 80,
"r": 151,
}
`;

exports[`usernameToColor Ellena Wright Frederic Conway has the proper color 1`] = `
Color {
"b": 133,
"g": 114,
"r": 195,
}
`;

exports[`usernameToColor Gianluca Hills has the proper color 1`] = `
Color {
"b": 97,
"g": 180,
"r": 214,
}
`;

exports[`usernameToColor Haseeb Stephens has the proper color 1`] = `
Color {
"b": 97,
"g": 180,
"r": 214,
}
`;

exports[`usernameToColor Idris Mac has the proper color 1`] = `
Color {
"b": 164,
"g": 80,
"r": 151,
}
`;

exports[`usernameToColor Kristi Fisher has the proper color 1`] = `
Color {
"b": 201,
"g": 130,
"r": 0,
}
`;

exports[`usernameToColor Lillian Wall has the proper color 1`] = `
Color {
"b": 145,
"g": 92,
"r": 188,
}
`;

exports[`usernameToColor Lorelai Taylor has the proper color 1`] = `
Color {
"b": 85,
"g": 203,
"r": 221,
}
`;

exports[`usernameToColor Madina Knight has the proper color 1`] = `
Color {
"b": 164,
"g": 80,
"r": 151,
}
`;

exports[`usernameToColor Rae Hope has the proper color 1`] = `
Color {
"b": 171,
"g": 90,
"r": 121,
}
`;

exports[`usernameToColor Santiago Singleton has the proper color 1`] = `
Color {
"b": 145,
"g": 92,
"r": 188,
}
`;

exports[`usernameToColor Sid Combs has the proper color 1`] = `
Color {
"b": 109,
"g": 158,
"r": 208,
}
`;

exports[`usernameToColor Vivienne Jacobs has the proper color 1`] = `
Color {
"b": 193,
"g": 120,
"r": 30,
}
`;

exports[`usernameToColor Zaki Cortes has the proper color 1`] = `
Color {
"b": 143,
"g": 166,
"r": 110,
}
`;

exports[`usernameToColor a user has the proper color 1`] = `
Color {
"b": 179,
"g": 100,
"r": 91,
}
`;

exports[`usernameToColor admin has the proper color 1`] = `
Color {
"b": 109,
"g": 158,
"r": 208,
}
`;

exports[`usernameToColor admin@cloud.example.com has the proper color 1`] = `
Color {
"b": 164,
"g": 80,
"r": 151,
}
`;

exports[`usernameToColor another user has the proper color 1`] = `
Color {
"b": 85,
"g": 203,
"r": 221,
}
`;

exports[`usernameToColor asd has the proper color 1`] = `
Color {
"b": 181,
"g": 142,
"r": 36,
}
`;

exports[`usernameToColor bar has the proper color 1`] = `
Color {
"b": 201,
"g": 130,
"r": 0,
}
`;

exports[`usernameToColor foo has the proper color 1`] = `
Color {
"b": 109,
"g": 158,
"r": 208,
}
`;

exports[`usernameToColor wasd has the proper color 1`] = `
Color {
"b": 157,
"g": 70,
"r": 182,
}
`;
exports[`usernameToColor has the proper color 1`] = `"#0082c9"`;

exports[`usernameToColor , has the proper color 1`] = `"#1e78c1"`;

exports[`usernameToColor . has the proper color 1`] = `"#c98879"`;

exports[`usernameToColor 123e4567-e89b-12d3-a456-426614174000 has the proper color 1`] = `"#bc5c91"`;

exports[`usernameToColor Akeel Robertson has the proper color 1`] = `"#9750a4"`;

exports[`usernameToColor Alishia Ann Lowry has the proper color 1`] = `"#d09e6d"`;

exports[`usernameToColor Arham Johnson has the proper color 1`] = `"#0082c9"`;

exports[`usernameToColor Brayden Truong has the proper color 1`] = `"#d09e6d"`;

exports[`usernameToColor Daphne Roy has the proper color 1`] = `"#9750a4"`;

exports[`usernameToColor Ellena Wright Frederic Conway has the proper color 1`] = `"#c37285"`;

exports[`usernameToColor Gianluca Hills has the proper color 1`] = `"#d6b461"`;

exports[`usernameToColor Haseeb Stephens has the proper color 1`] = `"#d6b461"`;

exports[`usernameToColor Idris Mac has the proper color 1`] = `"#9750a4"`;

exports[`usernameToColor Kristi Fisher has the proper color 1`] = `"#0082c9"`;

exports[`usernameToColor Lillian Wall has the proper color 1`] = `"#bc5c91"`;

exports[`usernameToColor Lorelai Taylor has the proper color 1`] = `"#ddcb55"`;

exports[`usernameToColor Madina Knight has the proper color 1`] = `"#9750a4"`;

exports[`usernameToColor Meeting has the proper color 1`] = `"#c98879"`;

exports[`usernameToColor Private Circle has the proper color 1`] = `"#c37285"`;

exports[`usernameToColor Rae Hope has the proper color 1`] = `"#795aab"`;

exports[`usernameToColor Santiago Singleton has the proper color 1`] = `"#bc5c91"`;

exports[`usernameToColor Sid Combs has the proper color 1`] = `"#d09e6d"`;

exports[`usernameToColor TestCircle has the proper color 1`] = `"#499aa2"`;

exports[`usernameToColor Tom Mörtel has the proper color 1`] = `"#248eb5"`;

exports[`usernameToColor Vivienne Jacobs has the proper color 1`] = `"#1e78c1"`;

exports[`usernameToColor Zaki Cortes has the proper color 1`] = `"#6ea68f"`;

exports[`usernameToColor a user has the proper color 1`] = `"#5b64b3"`;

exports[`usernameToColor admin has the proper color 1`] = `"#d09e6d"`;

exports[`usernameToColor admin@cloud.example.com has the proper color 1`] = `"#9750a4"`;

exports[`usernameToColor another user has the proper color 1`] = `"#ddcb55"`;

exports[`usernameToColor asd has the proper color 1`] = `"#248eb5"`;

exports[`usernameToColor bar has the proper color 1`] = `"#0082c9"`;

exports[`usernameToColor foo has the proper color 1`] = `"#d09e6d"`;

exports[`usernameToColor wasd has the proper color 1`] = `"#b6469d"`;

exports[`usernameToColor مرحبا بالعالم has the proper color 1`] = `"#c98879"`;

exports[`usernameToColor 🙈 has the proper color 1`] = `"#b6469d"`;
17 changes: 14 additions & 3 deletions src/functions/usernameToColor/usernameToColor.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import usernameToColor from './index'

const rgbToHex = (color) => {
return '#' + ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1)
}

describe('usernameToColor', () => {
'use strict'

const usernames = ['admin', 'foo', 'bar', 'asd', 'wasd', 'a user', 'another user', 'admin@cloud.example.com',
const usernames = [
'', ',', '.', 'admin', 'foo', 'bar', 'asd', 'wasd', 'a user', 'another user', 'admin@cloud.example.com',
'Lorelai Taylor',
'Lillian Wall',
'Haseeb Stephens',
Expand All @@ -21,11 +26,17 @@ describe('usernameToColor', () => {
'Gianluca Hills',
'Vivienne Jacobs',
'Brayden Truong',
'Akeel Robertson']
'Akeel Robertson',
'Tom Mörtel',
'🙈',
'مرحبا بالعالم',
'123e4567-e89b-12d3-a456-426614174000',
'Meeting', 'TestCircle', 'Private Circle',
]

usernames.forEach((key) => {
it(key + ' has the proper color', () => {
expect(usernameToColor(key)).toMatchSnapshot()
expect(rgbToHex(usernameToColor(key))).toMatchSnapshot()
})
})

Expand Down

0 comments on commit 25bd5a2

Please sign in to comment.