Seasons have a color to show on the calendar. I need them in HTML format (e.g., #123abc) in order to set as value to `<input type="color">`, but i did not want to save them as text in the database, as integers are better representations of colors—in fact, that’s what the HTML syntax also is: an integer. I think the best would be to create an extension that adds an HTML color type, with functions to convert from many representations (e.g., CSS’ rgb or even color names) to integer and back. However, that’s a lot of work and i can satisfy Camper’s needs with just a couple of functions and a domain. To show the color on the index, at first tried to use a read-only `<input type="color">`, but seems that this type of input can not be read-only and must be disabled instead. However, i do not know whether it makes sense to have a disabled input outside a form “just” to show a color; i suspect it does not. Thus, at the end i use SVG with a single circle, which is better that a 50%-rounded div with a background color, even if the result is the same—SVG **is** intended for showing pictures, which is this case.
59 lines
2.4 KiB
PL/PgSQL
59 lines
2.4 KiB
PL/PgSQL
-- Test edit_season
|
|
set client_min_messages to warning;
|
|
create extension if not exists pgtap;
|
|
reset client_min_messages;
|
|
|
|
begin;
|
|
|
|
set search_path to camper, public;
|
|
|
|
select plan(12);
|
|
|
|
select has_function('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean']);
|
|
select function_lang_is('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'sql');
|
|
select function_returns('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'uuid');
|
|
select isnt_definer('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean']);
|
|
select volatility_is('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'volatile');
|
|
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'guest', array[]::text[]);
|
|
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'employee', array[]::text[]);
|
|
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'admin', array['EXECUTE']);
|
|
select function_privs_are('camper', 'edit_season', array ['uuid', 'text', 'color', 'boolean'], 'authenticator', array[]::text[]);
|
|
|
|
set client_min_messages to warning;
|
|
truncate season cascade;
|
|
truncate company cascade;
|
|
reset client_min_messages;
|
|
|
|
|
|
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_lang_tag)
|
|
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 'ca')
|
|
;
|
|
|
|
insert into season (company_id, slug, name, color, active)
|
|
values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 'Low', to_integer('#232323'), true)
|
|
, (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 'High', to_integer('#323232'), false)
|
|
;
|
|
|
|
select lives_ok(
|
|
$$ select edit_season('87452b88-b48f-48d3-bb6c-0296de64164e', 'Very Low', '#1e1e1e', false) $$,
|
|
'Should be able to edit the first season'
|
|
);
|
|
|
|
select lives_ok(
|
|
$$ select edit_season('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'Very High', '#9f9f9f', true) $$,
|
|
'Should be able to edit the second season'
|
|
);
|
|
|
|
select bag_eq(
|
|
$$ select slug::text, name, to_color(color)::text, active from season $$,
|
|
$$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 'Very Low', '#1e1e1e', false)
|
|
, ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 'Very High', '#9f9f9f', true)
|
|
$$,
|
|
'Should have updated all seasons.'
|
|
);
|
|
|
|
select *
|
|
from finish();
|
|
|
|
rollback;
|