1
1
import { defaultRenderContainer } from './renderContainer'
2
2
import { describe , expect , test } from 'vitest'
3
- import { type TemplateId , type Ord , type Template , type Note } from 'shared'
3
+ import {
4
+ type TemplateId ,
5
+ type Ord ,
6
+ type Template ,
7
+ type Note ,
8
+ type Card ,
9
+ } from 'shared'
4
10
import { throwExp } from 'shared'
5
- import { noteOrds , strip , toSampleCard , toSampleNote } from './cardHtml'
11
+ import {
12
+ type HtmlResult ,
13
+ noteOrds ,
14
+ strip ,
15
+ toSampleCard ,
16
+ toSampleNote ,
17
+ getOk as getOkSafe ,
18
+ } from './cardHtml'
6
19
7
20
function buildTemplate (
8
21
fieldValues : Array < readonly [ string , string ] > ,
@@ -45,6 +58,10 @@ function buildTemplate(
45
58
} satisfies Template
46
59
}
47
60
61
+ export function getOk ( result : HtmlResult ) {
62
+ return getOkSafe ( result ) ?? throwExp ( 'ya goofed' )
63
+ }
64
+
48
65
function testBody (
49
66
fieldValues : Array < readonly [ string , string ] > ,
50
67
frontTemplate : string ,
@@ -55,12 +72,12 @@ function testBody(
55
72
expectedBack : string ,
56
73
) : void {
57
74
const template = buildTemplate ( fieldValues , frontTemplate , backTemplate , type )
58
- const [ front , back ] =
59
- defaultRenderContainer . body (
60
- toSampleCard ( ord as Ord ) ,
61
- toSampleNote ( new Map ( fieldValues ) ) ,
62
- template ,
63
- ) ?? throwExp ( 'should never happen' )
75
+ const r = defaultRenderContainer . body (
76
+ toSampleCard ( ord as Ord ) ,
77
+ toSampleNote ( new Map ( fieldValues ) ) ,
78
+ template ,
79
+ )
80
+ const [ front , back ] = getOk ( r )
64
81
expect ( front ) . toBe ( expectedFront )
65
82
expect ( back ) . toBe ( expectedBack )
66
83
}
@@ -75,12 +92,13 @@ function testStrippedBody(
75
92
expectedBack : string ,
76
93
) : void {
77
94
const template = buildTemplate ( fieldValues , frontTemplate , backTemplate , type )
78
- const [ front , back ] =
95
+ const [ front , back ] = getOk (
79
96
defaultRenderContainer . body (
80
97
toSampleCard ( ord as Ord ) ,
81
98
toSampleNote ( new Map ( fieldValues ) ) ,
82
99
template ,
83
- ) ?? throwExp ( 'should never happen' )
100
+ ) ,
101
+ )
84
102
expectStrippedToBe ( front , expectedFront )
85
103
expectStrippedToBe ( back , expectedBack )
86
104
}
@@ -583,12 +601,12 @@ test('CardHtml renders multiple cloze templates properly 4 with hint', () => {
583
601
} )
584
602
585
603
function expectTemplate (
586
- template : readonly [ string , string ] | null ,
604
+ template : HtmlResult ,
587
605
expectedFront : string ,
588
606
expectedBack : string ,
589
607
) : void {
590
608
expect ( template ) . not . toBeNull ( )
591
- const [ front , back ] = template !
609
+ const [ front , back ] = getOk ( template )
592
610
expectStrippedToBe ( front , expectedFront )
593
611
expectStrippedToBe ( back , expectedBack )
594
612
}
@@ -728,6 +746,15 @@ function toTestNote(
728
746
}
729
747
}
730
748
749
+ function toBody (
750
+ card : Card ,
751
+ note : Note ,
752
+ template : Template ,
753
+ short : boolean = false ,
754
+ ) {
755
+ return getOk ( defaultRenderContainer . body ( card , note , template , short ) )
756
+ }
757
+
731
758
describe ( 'standardTemplate tags' , ( ) => {
732
759
const fieldValues = [
733
760
[ 'Back' , 'Ottawa' ] ,
@@ -736,7 +763,7 @@ describe('standardTemplate tags', () => {
736
763
737
764
test ( 'CardHtml generates proper basic card template with no tags' , ( ) => {
738
765
const [ front , back ] =
739
- defaultRenderContainer . body (
766
+ toBody (
740
767
toSampleCard ( 0 as Ord ) ,
741
768
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( ) } ) ,
742
769
buildTemplate (
@@ -756,7 +783,7 @@ describe('standardTemplate tags', () => {
756
783
757
784
test ( 'CardHtml generates proper basic card template with 1 tag' , ( ) => {
758
785
const [ front , back ] =
759
- defaultRenderContainer . body (
786
+ toBody (
760
787
toSampleCard ( 0 as Ord ) ,
761
788
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( [ 'Geography' ] ) } ) ,
762
789
buildTemplate (
@@ -776,7 +803,7 @@ describe('standardTemplate tags', () => {
776
803
777
804
test ( 'CardHtml generates proper basic card template with 2 tags' , ( ) => {
778
805
const [ front , back ] =
779
- defaultRenderContainer . body (
806
+ toBody (
780
807
toSampleCard ( 0 as Ord ) ,
781
808
toTestNote ( new Map ( fieldValues ) , {
782
809
tags : new Set ( [ 'Geography' , 'Capital' ] ) ,
@@ -798,7 +825,7 @@ describe('standardTemplate tags', () => {
798
825
799
826
test ( 'CardHtml generates proper basic card template with no conditional tags' , ( ) => {
800
827
const [ front , back ] =
801
- defaultRenderContainer . body (
828
+ toBody (
802
829
toSampleCard ( 0 as Ord ) ,
803
830
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( ) } ) ,
804
831
buildTemplate (
@@ -818,7 +845,7 @@ describe('standardTemplate tags', () => {
818
845
819
846
test ( 'CardHtml generates proper basic card template with 1 conditional tag' , ( ) => {
820
847
const [ front , back ] =
821
- defaultRenderContainer . body (
848
+ toBody (
822
849
toSampleCard ( 0 as Ord ) ,
823
850
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( [ 'Geography' ] ) } ) ,
824
851
buildTemplate (
@@ -838,7 +865,7 @@ describe('standardTemplate tags', () => {
838
865
839
866
test ( 'CardHtml generates proper basic card template with 2 conditional tags' , ( ) => {
840
867
const [ front , back ] =
841
- defaultRenderContainer . body (
868
+ toBody (
842
869
toSampleCard ( 0 as Ord ) ,
843
870
toTestNote ( new Map ( fieldValues ) , {
844
871
tags : new Set ( [ 'Geography' , 'Capital' ] ) ,
@@ -860,7 +887,7 @@ describe('standardTemplate tags', () => {
860
887
861
888
test ( 'CardHtml generates proper basic card template with no antiConditional tags' , ( ) => {
862
889
const [ front , back ] =
863
- defaultRenderContainer . body (
890
+ toBody (
864
891
toSampleCard ( 0 as Ord ) ,
865
892
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( ) } ) ,
866
893
buildTemplate (
@@ -880,7 +907,7 @@ describe('standardTemplate tags', () => {
880
907
881
908
test ( 'CardHtml generates proper basic card template with 1 antiConditional tag' , ( ) => {
882
909
const [ front , back ] =
883
- defaultRenderContainer . body (
910
+ toBody (
884
911
toSampleCard ( 0 as Ord ) ,
885
912
toTestNote ( new Map ( fieldValues ) , { tags : new Set ( [ 'Geography' ] ) } ) ,
886
913
buildTemplate (
@@ -900,7 +927,7 @@ describe('standardTemplate tags', () => {
900
927
901
928
test ( 'CardHtml generates proper basic card template with 2 antiConditional tags' , ( ) => {
902
929
const [ front , back ] =
903
- defaultRenderContainer . body (
930
+ toBody (
904
931
toSampleCard ( 0 as Ord ) ,
905
932
toTestNote ( new Map ( fieldValues ) , {
906
933
tags : new Set ( [ 'Geography' , 'Capital' ] ) ,
0 commit comments