File: 001_update_warning_text.t

package info (click to toggle)
shutter 0.99.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,880 kB
  • sloc: perl: 19,514; sh: 204; makefile: 52; xml: 40
file content (66 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

use 5.010;
use strict;
use warnings;

use Gtk3;    # to escape warnings "Too late to run INIT block"
use Locale::gettext;
use Test::More;
use Test::MockModule;

use POSIX qw(locale_h);
use locale;
setlocale(LC_MESSAGES, 'C'); # Allow non-English developers to match error messages

require_ok('Shutter::Draw::DrawingTool');

my $mock = Test::MockModule->new("Shutter::Draw::DrawingTool");
$mock->mock(
    "new",
    sub {
        my $cls = shift;

        return bless {
            _start_time => time(),
            _d          => Locale::gettext->domain("shutter") }, $cls;
    } );

subtest "Singular minute" => sub {
    my $draw        = Shutter::Draw::DrawingTool->new();
    my $warn_dialog = CustomWarnDialog->new();

    $draw->update_warning_text($warn_dialog);

    ok( $warn_dialog->{type} eq "secondary-text" );
    like( $warn_dialog->{txt}, qr/from the last minute/ );
};

subtest "Plural minutes" => sub {
    my $draw        = Shutter::Draw::DrawingTool->new();
    my $warn_dialog = CustomWarnDialog->new();

    $draw->{_start_time} = $draw->{_start_time} - 120;

    $draw->update_warning_text($warn_dialog);

    ok( $warn_dialog->{type} eq "secondary-text" );
    like( $warn_dialog->{txt}, qr/from the last 2 minutes/ );
};

done_testing();

package CustomWarnDialog {

    sub new {
        my $cls = shift;

        return bless { type => undef, txt => undef }, $cls;
    }

    sub set {
        my ( $self, $type, $txt ) = @_;

        $self->{type} = $type;
        $self->{txt}  = $txt;
    }
};