1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2// See the LICENCE file in the repository root for full licence text.
3
4import GroupJson from 'interfaces/group-json';
5import { groupColour, urlPresence } from 'utils/css';
6
7describe('utils/css', () => {
8 describe('.groupColour', () => {
9 const group: GroupJson = {
10 colour: '#abcdef',
11 has_listing: true,
12 has_playmodes: true,
13 id: 1,
14 identifier: 'abc',
15 is_probationary: false,
16 name: 'ABC',
17 short_name: 'abc',
18 };
19
20 it('get CSS object with correct colour', () => {
21 expect(groupColour(group)).toEqual({
22 '--group-colour': '#abcdef',
23 });
24 });
25
26 it('get CSS object with initial value when null', () => {
27 expect(groupColour({ ...group, colour: null })).toEqual({
28 '--group-colour': 'initial',
29 });
30 });
31
32 it('get CSS object with initial value when undefined', () => {
33 expect(groupColour()).toEqual({
34 '--group-colour': 'initial',
35 });
36 });
37 });
38
39 describe('.urlPresence', () => {
40 describe('when url is empty', () => {
41 const cases = [
42 {
43 description: 'empty string should be undefined',
44 url: '',
45 },
46 {
47 description: 'null should be undefined',
48 url: null,
49 },
50 {
51 description: 'undefined should be undefined',
52 url: undefined,
53 },
54 ];
55
56 cases.forEach((test) => {
57 it(test.description, () => {
58 expect(urlPresence(test.url)).toBe(undefined);
59 });
60 });
61 });
62
63 describe('when url is not empty', () => {
64 const cases = [
65 {
66 description: 'should wrap with url',
67 expected: 'url("//some-path?a=1")',
68 url: '//some-path?a=1',
69 },
70 {
71 description: 'should escape double quotes',
72 expected: 'url("https://localhost/why%22double%22quotes?a=%22%22")',
73 url: 'https://localhost/why"double"quotes?a=""',
74 },
75 ];
76
77 cases.forEach((test) => {
78 it(test.description, () => {
79 expect(urlPresence(test.url)).toBe(test.expected);
80 });
81 });
82 });
83 });
84});