git.iko.soy/purescript-indexed-DB
on master help sign in
complete test suite for IDBObjectStore
commitf583308d73543077578e01fe6988e6db63e12a22 authorKtorZ <matthias.benkort@gmail.com> dateFri 30 Jun 2017, 11:31 (9 years ago) parentfc4915b
2 files changed+409−2
package.json+2−2 test/Main.purs+407
package.json+2−2
@@ -6,10 +6,10 @@
66 "scripts": {
77 "test:build": "pulp browserify -j 4 --main \"Test.Main\" -I test --to dist/karma/index.js",
88 "test:run": "karma start --single-run",
9− "test:watch": "find . -type f -regex '.*\\(src\\|test\\).*' ! -regex '.*bower_components.*\\|.*node_modules.*|.*\\.sw.*$' | entr -s 'npm run test'",
9+ "test:watch": "find . -type f -regex '.*\\(src\\|test\\).*' ! -regex '.*bower_components.*\\|.*node_modules.*|.*\\.sw.*' | entr -s 'npm run test'",
1010 "test": "npm run test:build && npm run test:run",
1111 "build": "pulp browserify -j 4 -O --to dist/bundle.js",
12− "start": "find . -type f -regex '.*\\(src\\|test\\).*' ! -regex '.*bower_components.*\\|.*node_modules.*|.*\\.sw.*$' | entr -s 'clear; pulp browserify -j 4 -t dist/bundle.js'",
12+ "start": "find . -type f -regex '.*\\(src\\|test\\).*' ! -regex '.*bower_components.*\\|.*node_modules.*|.*\\.sw.*' | entr -s 'clear; pulp browserify -j 4 -t dist/bundle.js'",
1313 "start:test": "karma start"
1414 },
1515 "dependencies": {
test/Main.purs+407
@@ -3,6 +3,7 @@ module Test.Main where
33import Prelude
44
55import Control.Monad.Aff (Aff, launchAff, forkAff, delay)
6+import Control.Monad.Aff.Console (log)
67import Control.Monad.Aff.AVar (AVAR, makeVar', modifyVar, peekVar, killVar)
78import Control.Monad.Eff (Eff)
89import Control.Monad.Eff.Class (liftEff)
@@ -520,3 +521,409 @@ main = runMocha do
520521 }
521522 tearDown dbName dbVersion db
522523
524+ it "count(Nothing) " do
525+ let dbName = "db-count"
526+ dbVersion = 1
527+ storeName = "store"
528+ keyPath = []
529+ autoIncrement = true
530+ callback db = do
531+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
532+ _ <- launchAff $ do
533+ _ <- IDBObjectStore.add store "patate" Nothing
534+ _ <- IDBObjectStore.add store 14 Nothing
535+ n <- IDBObjectStore.count store Nothing
536+ n `shouldEqual` 2
537+ pure unit
538+
539+ db <- IDBFactory.open dbName Nothing
540+ { onUpgradeNeeded : Just callback
541+ , onBlocked : Nothing
542+ }
543+ tearDown dbName dbVersion db
544+
545+
546+ it "getKey() (fixed)" do
547+ let dbName = "db-getKey"
548+ dbVersion = 1
549+ storeName = "store"
550+ keyPath = ["id"]
551+ key = "patate"
552+ autoIncrement = false
553+ callback db = do
554+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
555+ _ <- launchAff $ do
556+ key' <- IDBObjectStore.add store { id: key, value: 14 } Nothing
557+ (unsafeFromKey key') `shouldEqual` key
558+ key' <- IDBObjectStore.getKey store (IDBKeyRange.only key)
559+ (unsafeFromKey <$> key') `shouldEqual` (Just key)
560+ pure unit
561+
562+ db <- IDBFactory.open dbName Nothing
563+ { onUpgradeNeeded : Just callback
564+ , onBlocked : Nothing
565+ }
566+ tearDown dbName dbVersion db
567+
568+ it "getKey() (given)" do
569+ let dbName = "db-getKey"
570+ dbVersion = 1
571+ storeName = "store"
572+ keyPath = []
573+ autoIncrement = true
574+ callback db = do
575+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
576+ _ <- launchAff $ do
577+ key <- IDBObjectStore.add store "patate" Nothing
578+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only key)
579+ mkey `shouldEqual` Just key
580+ pure unit
581+
582+ db <- IDBFactory.open dbName Nothing
583+ { onUpgradeNeeded : Just callback
584+ , onBlocked : Nothing
585+ }
586+ tearDown dbName dbVersion db
587+
588+ it "getKey() unknown" do
589+ let dbName = "db-getKey"
590+ dbVersion = 1
591+ storeName = "store"
592+ keyPath = []
593+ autoIncrement = true
594+ callback db = do
595+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
596+ _ <- launchAff $ do
597+ key <- IDBObjectStore.add store "patate" Nothing
598+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
599+ mkey `shouldEqual` Nothing
600+ pure unit
601+
602+ db <- IDBFactory.open dbName Nothing
603+ { onUpgradeNeeded : Just callback
604+ , onBlocked : Nothing
605+ }
606+ tearDown dbName dbVersion db
607+
608+ it "getAllKeys(nothing, nothing)" do
609+ let dbName = "db-getAllKeys"
610+ dbVersion = 1
611+ storeName = "store"
612+ keyPath = []
613+ autoIncrement = true
614+ callback db = do
615+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
616+ _ <- launchAff $ do
617+ k1 <- IDBObjectStore.add store "patate" Nothing
618+ k2 <- IDBObjectStore.add store "autruche" Nothing
619+ keys <- IDBObjectStore.getAllKeys store Nothing Nothing
620+ keys `shouldEqual` [k1,k2]
621+ pure unit
622+
623+ db <- IDBFactory.open dbName Nothing
624+ { onUpgradeNeeded : Just callback
625+ , onBlocked : Nothing
626+ }
627+ tearDown dbName dbVersion db
628+
629+ it "getAllKeys(lowerBound(1, true), nothing)" do
630+ let dbName = "db-getAllKeys"
631+ dbVersion = 1
632+ storeName = "store"
633+ keyPath = []
634+ autoIncrement = true
635+ callback db = do
636+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
637+ _ <- launchAff $ do
638+ k1 <- IDBObjectStore.add store "patate" Nothing
639+ k2 <- IDBObjectStore.add store "autruche" Nothing
640+ k3 <- IDBObjectStore.add store 14 Nothing
641+ keys <- IDBObjectStore.getAllKeys store (Just $ IDBKeyRange.lowerBound 1 true) Nothing
642+ keys `shouldEqual` [k2, k3]
643+ pure unit
644+
645+ db <- IDBFactory.open dbName Nothing
646+ { onUpgradeNeeded : Just callback
647+ , onBlocked : Nothing
648+ }
649+ tearDown dbName dbVersion db
650+
651+ it "openCursor(Nothing, Next)" do
652+ let dbName = "db-openCursor"
653+ dbVersion = 1
654+ storeName = "store"
655+ keyPath = []
656+ autoIncrement = true
657+ callback db = do
658+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
659+ _ <- launchAff $ do
660+ _ <- IDBObjectStore.openCursor store Nothing Next
661+ pure unit
662+ pure unit
663+
664+ db <- IDBFactory.open dbName Nothing
665+ { onUpgradeNeeded : Just callback
666+ , onBlocked : Nothing
667+ }
668+ tearDown dbName dbVersion db
669+
670+ it "openCursor(Nothing, NextUnique)" do
671+ let dbName = "db-openCursor"
672+ dbVersion = 1
673+ storeName = "store"
674+ keyPath = []
675+ autoIncrement = true
676+ callback db = do
677+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
678+ _ <- launchAff $ do
679+ _ <- IDBObjectStore.openCursor store Nothing NextUnique
680+ pure unit
681+ pure unit
682+
683+ db <- IDBFactory.open dbName Nothing
684+ { onUpgradeNeeded : Just callback
685+ , onBlocked : Nothing
686+ }
687+ tearDown dbName dbVersion db
688+
689+ it "openCursor(Nothing, Prev)" do
690+ let dbName = "db-openCursor"
691+ dbVersion = 1
692+ storeName = "store"
693+ keyPath = []
694+ autoIncrement = true
695+ callback db = do
696+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
697+ _ <- launchAff $ do
698+ _ <- IDBObjectStore.openCursor store Nothing Prev
699+ pure unit
700+ pure unit
701+
702+ db <- IDBFactory.open dbName Nothing
703+ { onUpgradeNeeded : Just callback
704+ , onBlocked : Nothing
705+ }
706+ tearDown dbName dbVersion db
707+
708+ it "openCursor(Nothing, PrevUnique)" do
709+ let dbName = "db-openCursor"
710+ dbVersion = 1
711+ storeName = "store"
712+ keyPath = []
713+ autoIncrement = true
714+ callback db = do
715+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
716+ _ <- launchAff $ do
717+ _ <- IDBObjectStore.openCursor store Nothing PrevUnique
718+ pure unit
719+ pure unit
720+
721+ db <- IDBFactory.open dbName Nothing
722+ { onUpgradeNeeded : Just callback
723+ , onBlocked : Nothing
724+ }
725+ tearDown dbName dbVersion db
726+
727+ it "openCursor(Just upperBound, Next)" do
728+ let dbName = "db-openCursor"
729+ dbVersion = 1
730+ storeName = "store"
731+ keyPath = []
732+ autoIncrement = true
733+ callback db = do
734+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
735+ _ <- launchAff $ do
736+ _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 10 true) Next
737+ pure unit
738+ pure unit
739+
740+ db <- IDBFactory.open dbName Nothing
741+ { onUpgradeNeeded : Just callback
742+ , onBlocked : Nothing
743+ }
744+ tearDown dbName dbVersion db
745+
746+ it "openKeyCursor(Nothing, Next)" do
747+ let dbName = "db-openKeyCursor"
748+ dbVersion = 1
749+ storeName = "store"
750+ keyPath = []
751+ autoIncrement = true
752+ callback db = do
753+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
754+ _ <- launchAff $ do
755+ _ <- IDBObjectStore.openKeyCursor store Nothing Next
756+ pure unit
757+ pure unit
758+
759+ db <- IDBFactory.open dbName Nothing
760+ { onUpgradeNeeded : Just callback
761+ , onBlocked : Nothing
762+ }
763+ tearDown dbName dbVersion db
764+
765+ it "openKeyCursor(Nothing, NextUnique)" do
766+ let dbName = "db-openKeyCursor"
767+ dbVersion = 1
768+ storeName = "store"
769+ keyPath = []
770+ autoIncrement = true
771+ callback db = do
772+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
773+ _ <- launchAff $ do
774+ _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique
775+ pure unit
776+ pure unit
777+
778+ db <- IDBFactory.open dbName Nothing
779+ { onUpgradeNeeded : Just callback
780+ , onBlocked : Nothing
781+ }
782+ tearDown dbName dbVersion db
783+
784+ it "openKeyCursor(Nothing, Prev)" do
785+ let dbName = "db-openKeyCursor"
786+ dbVersion = 1
787+ storeName = "store"
788+ keyPath = []
789+ autoIncrement = true
790+ callback db = do
791+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
792+ _ <- launchAff $ do
793+ _ <- IDBObjectStore.openKeyCursor store Nothing Prev
794+ pure unit
795+ pure unit
796+
797+ db <- IDBFactory.open dbName Nothing
798+ { onUpgradeNeeded : Just callback
799+ , onBlocked : Nothing
800+ }
801+ tearDown dbName dbVersion db
802+
803+ it "openKeyCursor(Nothing, PrevUnique)" do
804+ let dbName = "db-openKeyCursor"
805+ dbVersion = 1
806+ storeName = "store"
807+ keyPath = []
808+ autoIncrement = true
809+ callback db = do
810+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
811+ _ <- launchAff $ do
812+ _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique
813+ pure unit
814+ pure unit
815+
816+ db <- IDBFactory.open dbName Nothing
817+ { onUpgradeNeeded : Just callback
818+ , onBlocked : Nothing
819+ }
820+ tearDown dbName dbVersion db
821+
822+ it "openKeyCursor(Just upperBound, Next)" do
823+ let dbName = "db-openKeyCursor"
824+ dbVersion = 1
825+ storeName = "store"
826+ keyPath = []
827+ autoIncrement = true
828+ callback db = do
829+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
830+ _ <- launchAff $ do
831+ _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.upperBound 10 true) Next
832+ pure unit
833+ pure unit
834+
835+ db <- IDBFactory.open dbName Nothing
836+ { onUpgradeNeeded : Just callback
837+ , onBlocked : Nothing
838+ }
839+ tearDown dbName dbVersion db
840+
841+ it "store.autoIncrement[true]" do
842+ let dbName = "db-autoIncrement"
843+ dbVersion = 1
844+ storeName = "store"
845+ keyPath = []
846+ autoIncrement = true
847+ callback db = do
848+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
849+ let autoIncrement' = IDBObjectStore.autoIncrement store
850+ _ <- launchAff $ autoIncrement `shouldEqual` autoIncrement'
851+ pure unit
852+
853+ db <- IDBFactory.open dbName Nothing
854+ { onUpgradeNeeded : Just callback
855+ , onBlocked : Nothing
856+ }
857+ tearDown dbName dbVersion db
858+
859+ it "store.autoIncrement[false]" do
860+ let dbName = "db-autoIncrement"
861+ dbVersion = 1
862+ storeName = "store"
863+ keyPath = []
864+ autoIncrement = false
865+ callback db = do
866+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
867+ let autoIncrement' = IDBObjectStore.autoIncrement store
868+ _ <- launchAff $ autoIncrement `shouldEqual` autoIncrement'
869+ pure unit
870+
871+ db <- IDBFactory.open dbName Nothing
872+ { onUpgradeNeeded : Just callback
873+ , onBlocked : Nothing
874+ }
875+ tearDown dbName dbVersion db
876+
877+ it "store.keyPath[\"patate\"]" do
878+ let dbName = "db-keyPath"
879+ dbVersion = 1
880+ storeName = "store"
881+ keyPath = ["patate"]
882+ autoIncrement = false
883+ callback db = do
884+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
885+ let keyPath' = IDBObjectStore.keyPath store
886+ _ <- launchAff $ keyPath `shouldEqual` keyPath'
887+ pure unit
888+
889+ db <- IDBFactory.open dbName Nothing
890+ { onUpgradeNeeded : Just callback
891+ , onBlocked : Nothing
892+ }
893+ tearDown dbName dbVersion db
894+
895+ it "store.indexNames[]" do
896+ let dbName = "db-indexNames"
897+ dbVersion = 1
898+ storeName = "store"
899+ keyPath = []
900+ autoIncrement = false
901+ callback db = do
902+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
903+ let indexNames = IDBObjectStore.indexNames store
904+ _ <- launchAff $ indexNames `shouldEqual` []
905+ pure unit
906+
907+ db <- IDBFactory.open dbName Nothing
908+ { onUpgradeNeeded : Just callback
909+ , onBlocked : Nothing
910+ }
911+ tearDown dbName dbVersion db
912+
913+ it "store.name[\"store\"]" do
914+ let dbName = "db-indexNames"
915+ dbVersion = 1
916+ storeName = "store"
917+ keyPath = []
918+ autoIncrement = false
919+ callback db = do
920+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
921+ let storeName' = IDBObjectStore.name store
922+ _ <- launchAff $ storeName `shouldEqual` storeName'
923+ pure unit
924+
925+ db <- IDBFactory.open dbName Nothing
926+ { onUpgradeNeeded : Just callback
927+ , onBlocked : Nothing
928+ }
929+ tearDown dbName dbVersion db