summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-19 16:41:52 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-19 16:41:52 -0400
commit82bbb7b09ccf3451033f17b2de9f6f17c030b974 (patch)
tree6c322819c6ebb3aa8141443c92d86e65761be4d2
parentff4095d8e4728ddfca51fd01cd138c09d0df4964 (diff)
downloadcatalyst-view-spreadsheet-template-82bbb7b09ccf3451033f17b2de9f6f17c030b974.tar.gz
catalyst-view-spreadsheet-template-82bbb7b09ccf3451033f17b2de9f6f17c030b974.zip
add a basic test
-rw-r--r--t/basic.t327
-rw-r--r--t/lib/MyApp.pm13
-rw-r--r--t/lib/MyApp/Controller/Root.pm15
-rw-r--r--t/lib/MyApp/View/Spreadsheet/Template.pm9
-rw-r--r--t/lib/MyApp/root/index.json151
5 files changed, 515 insertions, 0 deletions
diff --git a/t/basic.t b/t/basic.t
new file mode 100644
index 0000000..1cf1851
--- /dev/null
+++ b/t/basic.t
@@ -0,0 +1,327 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use lib 't/lib';
+
+use Catalyst::Test 'MyApp';
+use Spreadsheet::ParseXLSX;
+
+my $res = request('basic.xlsx');
+is($res->code, 200);
+
+my $data = $res->content;
+open my $fh, '<', \$data;
+my $wb = Spreadsheet::ParseXLSX->new->parse($fh);
+
+is($wb->worksheet_count, 1);
+
+my $ws = $wb->worksheet(0);
+is($ws->get_name, 'Sheet1');
+is_deeply([$ws->row_range], [0, 5]);
+is_deeply([$ws->col_range], [0, 4]);
+
+{
+ my $cell = $ws->get_cell(0, 0);
+ is($cell->unformatted, "Colored Cell");
+ is($cell->value, "Colored Cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [1, '#9BBB59', '#FFFFFF']);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#FFFF00');
+}
+
+{
+ my $cell = $ws->get_cell(0, 1);
+ is($cell->unformatted, "Wide Cell (25.00)");
+ is($cell->value, "Wide Cell (25.00)");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 2);
+ is($cell->unformatted, "Bordered Cell w/ Text Wrap");
+ is($cell->value, "Bordered Cell w/ Text Wrap");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok($format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(1) x 4]);
+ is_deeply($format->{BdrColor}, [('#000000') x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 3);
+ is($cell->unformatted, "Middle Valigned");
+ is($cell->value, "Middle Valigned");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 1);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(0, 4);
+ is($cell->unformatted, "Right Aligned and text wrapped");
+ is($cell->value, "Right Aligned and text wrapped");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 3);
+ is($format->{AlignV}, 2);
+ ok($format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (0..4) {
+ is($ws->get_cell(1, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(2, 0);
+ is($cell->unformatted, 10);
+ is($cell->value, 10);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..4) {
+ is($ws->get_cell(2, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(3, 0);
+ is($cell->unformatted, 20);
+ is($cell->value, 20);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..2) {
+ is($ws->get_cell(3, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(3, 3);
+ is($cell->unformatted, 2.5);
+ is($cell->value, "\$2.50");
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(3, 4);
+ is($cell->unformatted, "<< currency cell");
+ is($cell->value, "<< currency cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 2);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#4BACC6');
+}
+
+{
+ my $cell = $ws->get_cell(4, 0);
+ is($cell->unformatted, 30);
+ is($cell->value, 30);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+for my $i (1..4) {
+ is($ws->get_cell(4, $i), undef);
+}
+
+{
+ my $cell = $ws->get_cell(5, 0);
+ is($cell->unformatted, 60);
+ is($cell->value, 60);
+ is($cell->type, 'Numeric');
+ is($cell->{Formula}, 'SUM(A3:A5)');
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 0);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [0, undef, undef]);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ { local $TODO = "defaults don't work properly yet";
+ is($font->{Height}, 12);
+ }
+ is($font->{Color}, '#000000');
+}
+
+{
+ my $cell = $ws->get_cell(5, 1);
+ is($cell->unformatted, "<< formula cell");
+ is($cell->value, "<< formula cell");
+ is($cell->type, 'Text');
+ is($cell->{Formula}, undef);
+
+ my $format = $cell->get_format;
+ is($format->{AlignH}, 3);
+ is($format->{AlignV}, 2);
+ ok(!$format->{Wrap});
+ is_deeply($format->{Fill}, [1, '#EEECE1', '#FFFFFF']);
+ is_deeply($format->{BdrStyle}, [(0) x 4]);
+ is_deeply($format->{BdrColor}, [(undef) x 4]);
+ is_deeply($format->{BdrDiag}, [0, 0, undef]);
+
+ my $font = $format->{Font};
+ is($font->{Name}, 'Calibri');
+ is($font->{Height}, 12);
+ is($font->{Color}, '#F79646');
+}
+
+for my $i (2..4) {
+ is($ws->get_cell(5, $i), undef);
+}
+
+
+done_testing;
diff --git a/t/lib/MyApp.pm b/t/lib/MyApp.pm
new file mode 100644
index 0000000..279ab6a
--- /dev/null
+++ b/t/lib/MyApp.pm
@@ -0,0 +1,13 @@
+package MyApp;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst';
+
+__PACKAGE__->config(
+ name => 'MyApp',
+);
+
+__PACKAGE__->setup;
+
+1;
diff --git a/t/lib/MyApp/Controller/Root.pm b/t/lib/MyApp/Controller/Root.pm
new file mode 100644
index 0000000..8d02d2b
--- /dev/null
+++ b/t/lib/MyApp/Controller/Root.pm
@@ -0,0 +1,15 @@
+package MyApp::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => '');
+
+sub index :Path :Args(0) {}
+
+sub end : ActionClass('RenderView') {}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/lib/MyApp/View/Spreadsheet/Template.pm b/t/lib/MyApp/View/Spreadsheet/Template.pm
new file mode 100644
index 0000000..34760bf
--- /dev/null
+++ b/t/lib/MyApp/View/Spreadsheet/Template.pm
@@ -0,0 +1,9 @@
+package MyApp::View::Spreadsheet::Template;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::View::Spreadsheet::Template';
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/t/lib/MyApp/root/index.json b/t/lib/MyApp/root/index.json
new file mode 100644
index 0000000..64fc6e1
--- /dev/null
+++ b/t/lib/MyApp/root/index.json
@@ -0,0 +1,151 @@
+{
+ "selection" : 0,
+ "worksheets" : [
+ {
+ "cells" : [
+ [
+ {
+ "contents" : "Colored Cell",
+ "format" : {
+ "bg_color" : "#9BBB59",
+ "color" : "#FFFF00",
+ "pattern" : "solid",
+ "size" : 12
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Wide Cell (25.00)",
+ "type" : "string"
+ },
+ {
+ "contents" : "Bordered Cell w/ Text Wrap",
+ "format" : {
+ "border" : [
+ "thin",
+ "thin",
+ "thin",
+ "thin"
+ ],
+ "border_color" : [
+ "#000000",
+ "#000000",
+ "#000000",
+ "#000000"
+ ],
+ "text_wrap" : true
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Middle Valigned",
+ "format" : {
+ "valign" : "vcenter"
+ },
+ "type" : "string"
+ },
+ {
+ "contents" : "Right Aligned and text wrapped",
+ "format" : {
+ "align" : "right",
+ "text_wrap" : true
+ },
+ "type" : "string"
+ }
+ ],
+ [
+ {},
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 10,
+ "type" : "number"
+ },
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 20,
+ "type" : "number"
+ },
+ {},
+ {},
+ {
+ "contents" : 2.5,
+ "format" : {
+ "num_format" : "\"$\"#,##0.00"
+ },
+ "type" : "number"
+ },
+ {
+ "contents" : "<< currency cell",
+ "format" : {
+ "align" : "center",
+ "color" : "#4BACC6",
+ "size" : 12
+ },
+ "type" : "string"
+ }
+ ],
+ [
+ {
+ "contents" : 30,
+ "type" : "number"
+ },
+ {},
+ {},
+ {},
+ {}
+ ],
+ [
+ {
+ "contents" : 60,
+ "formula" : "SUM(A3:A5)",
+ "type" : "number"
+ },
+ {
+ "contents" : "<< formula cell",
+ "format" : {
+ "align" : "right",
+ "bg_color" : "#EEECE1",
+ "color" : "#F79646",
+ "pattern" : "solid",
+ "size" : 12
+ },
+ "type" : "string"
+ },
+ {},
+ {},
+ {}
+ ]
+ ],
+ "column_widths" : [
+ 10.83203125,
+ 25.83203125,
+ 10,
+ 15,
+ 18.1640625
+ ],
+ "name" : "Sheet1",
+ "row_heights" : [
+ 45,
+ 15,
+ 15,
+ 15,
+ 15,
+ 15
+ ],
+ "selection" : [
+ 3,
+ 4
+ ]
+ }
+ ]
+}