Skip to content

Commit

Permalink
Add tests for process_css()
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-josef-spacek committed Mar 8, 2024
1 parent 8e91c54 commit bd9c134
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.05
- Add tests for process_css().
- Fix minimal dependency for Tags::HTML to 0.08 (thanks Andreas J. König,
GH#1).

Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ t/Tags-HTML-ChangePassword/04-cleanup.t
t/Tags-HTML-ChangePassword/05-init.t
t/Tags-HTML-ChangePassword/06-prepare.t
t/Tags-HTML-ChangePassword/07-process.t
t/Tags-HTML-ChangePassword/08-process_css.t
xt/Tags-HTML-ChangePassword/01-pod_coverage.t
xt/Tags-HTML-ChangePassword/02-pod.t
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TODO
====
1. Finish tests.
Missing test for translation and error (_text) in CSS.
2. Rewrite to Tags::HTML::Element.
3. Add check for messages in init()
Use Tags::HTML::Messages check. Prevent double check.
Expand Down
239 changes: 239 additions & 0 deletions t/Tags-HTML-ChangePassword/08-process_css.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
use strict;
use warnings;

use CSS::Struct::Output::Structure;
use English;
use Error::Pure::Utils qw(clean);
use Tags::HTML::ChangePassword;
use Test::More 'tests' => 5;
use Test::NoWarnings;

# Test.
my $css = CSS::Struct::Output::Structure->new;
my $obj = Tags::HTML::ChangePassword->new(
'css' => $css,
);
$obj->process_css;
my $ret_ar = $css->flush(1);
is_deeply(
$ret_ar,
[
['s', '.form-change-password'],
['d', 'width', '300px'],
['d', 'background-color', '#f2f2f2'],
['d', 'padding', '20px'],
['d', 'border-radius', '5px'],
['d', 'box-shadow', '0 0 10px rgba(0, 0, 0, 0.2)'],
['e'],

['s', '.form-change-password fieldset'],
['d', 'border', 'none'],
['d', 'padding', 0],
['d', 'margin-bottom', '20px'],
['e'],

['s', '.form-change-password legend'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '10px'],
['e'],

['s', '.form-change-password p'],
['d', 'margin', 0],
['d', 'padding', '10px 0'],
['e'],

['s', '.form-change-password label'],
['d', 'display', 'block'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '5px'],
['e'],

['s', '.form-change-password input[type="text"]'],
['s', '.form-change-password input[type="password"]'],
['d', 'width', '100%'],
['d', 'padding', '8px'],
['d', 'border', '1px solid #ccc'],
['d', 'border-radius', '3px'],
['e'],

['s', '.form-change-password button[type="submit"]'],
['d', 'width', '100%'],
['d', 'padding', '10px'],
['d', 'background-color', '#4CAF50'],
['d', 'color', '#fff'],
['d', 'border', 'none'],
['d', 'border-radius', '3px'],
['d', 'cursor', 'pointer'],
['e'],

['s', '.form-change-password button[type="submit"]:hover'],
['d', 'background-color', '#45a049'],
['e'],

['s', '.form-change-password .messages'],
['d', 'text-align', 'center'],
['e'],
],
'ChangePassword CSS code (default class name).',
);

# Test.
$css = CSS::Struct::Output::Structure->new;
$obj = Tags::HTML::ChangePassword->new(
'css' => $css,
);
$obj->prepare({
'error' => 'red',
'info' => 'blue',
});
$obj->process_css;
$ret_ar = $css->flush(1);
is_deeply(
$ret_ar,
[
['s', '.form-change-password'],
['d', 'width', '300px'],
['d', 'background-color', '#f2f2f2'],
['d', 'padding', '20px'],
['d', 'border-radius', '5px'],
['d', 'box-shadow', '0 0 10px rgba(0, 0, 0, 0.2)'],
['e'],

['s', '.form-change-password fieldset'],
['d', 'border', 'none'],
['d', 'padding', 0],
['d', 'margin-bottom', '20px'],
['e'],

['s', '.form-change-password legend'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '10px'],
['e'],

['s', '.form-change-password p'],
['d', 'margin', 0],
['d', 'padding', '10px 0'],
['e'],

['s', '.form-change-password label'],
['d', 'display', 'block'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '5px'],
['e'],

['s', '.form-change-password input[type="text"]'],
['s', '.form-change-password input[type="password"]'],
['d', 'width', '100%'],
['d', 'padding', '8px'],
['d', 'border', '1px solid #ccc'],
['d', 'border-radius', '3px'],
['e'],

['s', '.form-change-password button[type="submit"]'],
['d', 'width', '100%'],
['d', 'padding', '10px'],
['d', 'background-color', '#4CAF50'],
['d', 'color', '#fff'],
['d', 'border', 'none'],
['d', 'border-radius', '3px'],
['d', 'cursor', 'pointer'],
['e'],

['s', '.form-change-password button[type="submit"]:hover'],
['d', 'background-color', '#45a049'],
['e'],

['s', '.form-change-password .messages'],
['d', 'text-align', 'center'],
['e'],

['s', '.error'],
['d', 'color', 'red'],
['e'],

['s', '.info'],
['d', 'color', 'blue'],
['e'],
],
'ChangePassword CSS code (default class name + messages).',
);

# Test.
$css = CSS::Struct::Output::Structure->new;
$obj = Tags::HTML::ChangePassword->new(
'css' => $css,
'css_change_password' => 'my-class',
'width' => '50em',
);
$obj->process_css;
$ret_ar = $css->flush(1);
is_deeply(
$ret_ar,
[
['s', '.my-class'],
['d', 'width', '50em'],
['d', 'background-color', '#f2f2f2'],
['d', 'padding', '20px'],
['d', 'border-radius', '5px'],
['d', 'box-shadow', '0 0 10px rgba(0, 0, 0, 0.2)'],
['e'],

['s', '.my-class fieldset'],
['d', 'border', 'none'],
['d', 'padding', 0],
['d', 'margin-bottom', '20px'],
['e'],

['s', '.my-class legend'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '10px'],
['e'],

['s', '.my-class p'],
['d', 'margin', 0],
['d', 'padding', '10px 0'],
['e'],

['s', '.my-class label'],
['d', 'display', 'block'],
['d', 'font-weight', 'bold'],
['d', 'margin-bottom', '5px'],
['e'],

['s', '.my-class input[type="text"]'],
['s', '.my-class input[type="password"]'],
['d', 'width', '100%'],
['d', 'padding', '8px'],
['d', 'border', '1px solid #ccc'],
['d', 'border-radius', '3px'],
['e'],

['s', '.my-class button[type="submit"]'],
['d', 'width', '100%'],
['d', 'padding', '10px'],
['d', 'background-color', '#4CAF50'],
['d', 'color', '#fff'],
['d', 'border', 'none'],
['d', 'border-radius', '3px'],
['d', 'cursor', 'pointer'],
['e'],

['s', '.my-class button[type="submit"]:hover'],
['d', 'background-color', '#45a049'],
['e'],

['s', '.my-class .messages'],
['d', 'text-align', 'center'],
['e'],
],
'ChangePassword CSS code (explicit class name and width).',
);

# Test.
$obj = Tags::HTML::ChangePassword->new;
eval {
$obj->process_css;
};
is($EVAL_ERROR, "Parameter 'css' isn't defined.\n",
"Parameter 'css' isn't defined.");
clean();

0 comments on commit bd9c134

Please sign in to comment.