@@ -3,6 +3,7 @@ module Test.Main where
3import Prelude
3import Prelude
5import Control.Monad.Aff (Aff, launchAff, forkAff, delay)
5import Control.Monad.Aff (Aff, launchAff, forkAff, delay)
6+import Control.Monad.Aff.Console (log)
6import Control.Monad.Aff.AVar (AVAR, makeVar', modifyVar, peekVar, killVar)
7import Control.Monad.Aff.AVar (AVAR, makeVar', modifyVar, peekVar, killVar)
7import Control.Monad.Eff (Eff)
8import Control.Monad.Eff (Eff)
8import Control.Monad.Eff.Class (liftEff)
9import Control.Monad.Eff.Class (liftEff)
@@ -520,3 +521,409 @@ main = runMocha do
521 tearDown dbName dbVersion db
522 tearDown dbName dbVersion db
524+ it "count(Nothing) " do
525+ let dbName = "db-count"
529+ autoIncrement = true
531+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
533+ _ <- IDBObjectStore.add store "patate" Nothing
534+ _ <- IDBObjectStore.add store 14 Nothing
535+ n <- IDBObjectStore.count store Nothing
539+ db <- IDBFactory.open dbName Nothing
540+ { onUpgradeNeeded : Just callback
541+ , onBlocked : Nothing
543+ tearDown dbName dbVersion db
546+ it "getKey() (fixed)" do
547+ let dbName = "db-getKey"
552+ autoIncrement = false
554+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
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)
562+ db <- IDBFactory.open dbName Nothing
563+ { onUpgradeNeeded : Just callback
564+ , onBlocked : Nothing
566+ tearDown dbName dbVersion db
568+ it "getKey() (given)" do
569+ let dbName = "db-getKey"
573+ autoIncrement = true
575+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
577+ key <- IDBObjectStore.add store "patate" Nothing
578+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only key)
579+ mkey `shouldEqual` Just key
582+ db <- IDBFactory.open dbName Nothing
583+ { onUpgradeNeeded : Just callback
584+ , onBlocked : Nothing
586+ tearDown dbName dbVersion db
588+ it "getKey() unknown" do
589+ let dbName = "db-getKey"
593+ autoIncrement = true
595+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
597+ key <- IDBObjectStore.add store "patate" Nothing
598+ mkey <- IDBObjectStore.getKey store (IDBKeyRange.only 14)
599+ mkey `shouldEqual` Nothing
602+ db <- IDBFactory.open dbName Nothing
603+ { onUpgradeNeeded : Just callback
604+ , onBlocked : Nothing
606+ tearDown dbName dbVersion db
608+ it "getAllKeys(nothing, nothing)" do
609+ let dbName = "db-getAllKeys"
613+ autoIncrement = true
615+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
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]
623+ db <- IDBFactory.open dbName Nothing
624+ { onUpgradeNeeded : Just callback
625+ , onBlocked : Nothing
627+ tearDown dbName dbVersion db
629+ it "getAllKeys(lowerBound(1, true), nothing)" do
630+ let dbName = "db-getAllKeys"
634+ autoIncrement = true
636+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
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]
645+ db <- IDBFactory.open dbName Nothing
646+ { onUpgradeNeeded : Just callback
647+ , onBlocked : Nothing
649+ tearDown dbName dbVersion db
651+ it "openCursor(Nothing, Next)" do
652+ let dbName = "db-openCursor"
656+ autoIncrement = true
658+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
660+ _ <- IDBObjectStore.openCursor store Nothing Next
664+ db <- IDBFactory.open dbName Nothing
665+ { onUpgradeNeeded : Just callback
666+ , onBlocked : Nothing
668+ tearDown dbName dbVersion db
670+ it "openCursor(Nothing, NextUnique)" do
671+ let dbName = "db-openCursor"
675+ autoIncrement = true
677+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
679+ _ <- IDBObjectStore.openCursor store Nothing NextUnique
683+ db <- IDBFactory.open dbName Nothing
684+ { onUpgradeNeeded : Just callback
685+ , onBlocked : Nothing
687+ tearDown dbName dbVersion db
689+ it "openCursor(Nothing, Prev)" do
690+ let dbName = "db-openCursor"
694+ autoIncrement = true
696+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
698+ _ <- IDBObjectStore.openCursor store Nothing Prev
702+ db <- IDBFactory.open dbName Nothing
703+ { onUpgradeNeeded : Just callback
704+ , onBlocked : Nothing
706+ tearDown dbName dbVersion db
708+ it "openCursor(Nothing, PrevUnique)" do
709+ let dbName = "db-openCursor"
713+ autoIncrement = true
715+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
717+ _ <- IDBObjectStore.openCursor store Nothing PrevUnique
721+ db <- IDBFactory.open dbName Nothing
722+ { onUpgradeNeeded : Just callback
723+ , onBlocked : Nothing
725+ tearDown dbName dbVersion db
727+ it "openCursor(Just upperBound, Next)" do
728+ let dbName = "db-openCursor"
732+ autoIncrement = true
734+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
736+ _ <- IDBObjectStore.openCursor store (Just $ IDBKeyRange.upperBound 10 true) Next
740+ db <- IDBFactory.open dbName Nothing
741+ { onUpgradeNeeded : Just callback
742+ , onBlocked : Nothing
744+ tearDown dbName dbVersion db
746+ it "openKeyCursor(Nothing, Next)" do
747+ let dbName = "db-openKeyCursor"
751+ autoIncrement = true
753+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
755+ _ <- IDBObjectStore.openKeyCursor store Nothing Next
759+ db <- IDBFactory.open dbName Nothing
760+ { onUpgradeNeeded : Just callback
761+ , onBlocked : Nothing
763+ tearDown dbName dbVersion db
765+ it "openKeyCursor(Nothing, NextUnique)" do
766+ let dbName = "db-openKeyCursor"
770+ autoIncrement = true
772+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
774+ _ <- IDBObjectStore.openKeyCursor store Nothing NextUnique
778+ db <- IDBFactory.open dbName Nothing
779+ { onUpgradeNeeded : Just callback
780+ , onBlocked : Nothing
782+ tearDown dbName dbVersion db
784+ it "openKeyCursor(Nothing, Prev)" do
785+ let dbName = "db-openKeyCursor"
789+ autoIncrement = true
791+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
793+ _ <- IDBObjectStore.openKeyCursor store Nothing Prev
797+ db <- IDBFactory.open dbName Nothing
798+ { onUpgradeNeeded : Just callback
799+ , onBlocked : Nothing
801+ tearDown dbName dbVersion db
803+ it "openKeyCursor(Nothing, PrevUnique)" do
804+ let dbName = "db-openKeyCursor"
808+ autoIncrement = true
810+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
812+ _ <- IDBObjectStore.openKeyCursor store Nothing PrevUnique
816+ db <- IDBFactory.open dbName Nothing
817+ { onUpgradeNeeded : Just callback
818+ , onBlocked : Nothing
820+ tearDown dbName dbVersion db
822+ it "openKeyCursor(Just upperBound, Next)" do
823+ let dbName = "db-openKeyCursor"
827+ autoIncrement = true
829+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
831+ _ <- IDBObjectStore.openKeyCursor store (Just $ IDBKeyRange.upperBound 10 true) Next
835+ db <- IDBFactory.open dbName Nothing
836+ { onUpgradeNeeded : Just callback
837+ , onBlocked : Nothing
839+ tearDown dbName dbVersion db
841+ it "store.autoIncrement[true]" do
842+ let dbName = "db-autoIncrement"
846+ autoIncrement = true
848+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
849+ let autoIncrement' = IDBObjectStore.autoIncrement store
850+ _ <- launchAff $ autoIncrement `shouldEqual` autoIncrement'
853+ db <- IDBFactory.open dbName Nothing
854+ { onUpgradeNeeded : Just callback
855+ , onBlocked : Nothing
857+ tearDown dbName dbVersion db
859+ it "store.autoIncrement[false]" do
860+ let dbName = "db-autoIncrement"
864+ autoIncrement = false
866+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
867+ let autoIncrement' = IDBObjectStore.autoIncrement store
868+ _ <- launchAff $ autoIncrement `shouldEqual` autoIncrement'
871+ db <- IDBFactory.open dbName Nothing
872+ { onUpgradeNeeded : Just callback
873+ , onBlocked : Nothing
875+ tearDown dbName dbVersion db
877+ it "store.keyPath[\"patate\"]" do
878+ let dbName = "db-keyPath"
881+ keyPath = ["patate"]
882+ autoIncrement = false
884+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
885+ let keyPath' = IDBObjectStore.keyPath store
886+ _ <- launchAff $ keyPath `shouldEqual` keyPath'
889+ db <- IDBFactory.open dbName Nothing
890+ { onUpgradeNeeded : Just callback
891+ , onBlocked : Nothing
893+ tearDown dbName dbVersion db
895+ it "store.indexNames[]" do
896+ let dbName = "db-indexNames"
900+ autoIncrement = false
902+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
903+ let indexNames = IDBObjectStore.indexNames store
904+ _ <- launchAff $ indexNames `shouldEqual` []
907+ db <- IDBFactory.open dbName Nothing
908+ { onUpgradeNeeded : Just callback
909+ , onBlocked : Nothing
911+ tearDown dbName dbVersion db
913+ it "store.name[\"store\"]" do
914+ let dbName = "db-indexNames"
918+ autoIncrement = false
920+ store <- IDBDatabase.createObjectStore db storeName { keyPath, autoIncrement }
921+ let storeName' = IDBObjectStore.name store
922+ _ <- launchAff $ storeName `shouldEqual` storeName'
925+ db <- IDBFactory.open dbName Nothing
926+ { onUpgradeNeeded : Just callback
927+ , onBlocked : Nothing
929+ tearDown dbName dbVersion db