<commit_before>{-
Copyright 2015 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module Test.SlamData.Feature.Test.Search where

import Prelude
import Control.Apply ((*>))
import Test.Feature.Log (successMsg)
import Test.SlamData.Feature.Expectations as Expect
import Test.SlamData.Feature.Monad (SlamFeature)
import Test.SlamData.Feature.Interactions as Interact
import Test.Feature.Scenario (scenario)

searchScenario :: String -> Array String -> SlamFeature Unit -> SlamFeature Unit
searchScenario =
  scenario
    "Search"
    (Interact.createWorkspaceInTestFolder "Search")
    (Interact.deleteFileInTestFolder "Untitled Workspace.slam"
       *> Interact.browseRootFolder)

test :: SlamFeature Unit
test = do
  searchScenario "Search for a city" [] do
    --Test.SlamData.Feature.Monad.waitTime 30000
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "springfield"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 10 "city" "SPRINGFIELD"
    successMsg "Successfully searched for a city"

  searchScenario "Search within results" [] do
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "springfield"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "OR"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 2 "city" "SPRINGFIELD"
    Expect.cardsInTableColumnInLastCardToContain 2 "state" "OR"
    successMsg "Successfully searched within results"

  searchScenario "Search with field names" [] do
    --Given.aDocument "/test-mount/testDb/zips"
    --  [ Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30001"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30000"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "DELAWARE"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30001"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "CO"
    --      , Tuple "pop" "30001"
    --      ]
    --  ]
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard
      "city:springfield state:or pop:>30000"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 1 "city" "SPRINGFIELD"
    Expect.cardsInTableColumnInLastCardToContain 1 "state" "OR"
    Expect.cardsInTableColumnInLastCardToBeGT 1 "pop" "30000"
    successMsg "Successfully searched with field names"

  searchScenario "Suppress search results" [] do
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "city:portland -state:OR"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 10 "city" "PORTLAND"
    Expect.cardsInTableColumnInLastCardToNotEq 10 "state" "OR"
    successMsg "Successfully suppressed search results"
<commit_msg>add issue 1841 to search results<commit_after>{-
Copyright 2015 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module Test.SlamData.Feature.Test.Search where

import Prelude
import Control.Apply ((*>))
import Test.Feature.Log (successMsg)
import Test.SlamData.Feature.Expectations as Expect
import Test.SlamData.Feature.Monad (SlamFeature)
import Test.SlamData.Feature.Interactions as Interact
import Test.Feature.Scenario (scenario)

searchScenario :: String -> Array String -> SlamFeature Unit -> SlamFeature Unit
searchScenario =
  scenario
    "Search"
    (Interact.createWorkspaceInTestFolder "Search")
    (Interact.deleteFileInTestFolder "Untitled Workspace.slam"
       *> Interact.browseRootFolder)

test :: SlamFeature Unit
test = do
  searchScenario "Search for a city" [] do
    --Test.SlamData.Feature.Monad.waitTime 30000
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "springfield"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 10 "city" "SPRINGFIELD"
    successMsg "Successfully searched for a city"

  searchScenario "Search within results" ["https://slamdata.atlassian.net/browse/SD-1841"] do
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "springfield"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "OR"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 2 "city" "SPRINGFIELD"
    Expect.cardsInTableColumnInLastCardToContain 2 "state" "OR"
    successMsg "Successfully searched within results"

  searchScenario "Search with field names" [] do
    --Given.aDocument "/test-mount/testDb/zips"
    --  [ Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30001"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30000"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "DELAWARE"
    --      , Tuple "state" "OR"
    --      , Tuple "pop" "30001"
    --      ]
    --  , Map.fromFoldable
    --      [ Tuple "city" "WEST SPRINGFIELD"
    --      , Tuple "state" "CO"
    --      , Tuple "pop" "30001"
    --      ]
    --  ]
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard
      "city:springfield state:or pop:>30000"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 1 "city" "SPRINGFIELD"
    Expect.cardsInTableColumnInLastCardToContain 1 "state" "OR"
    Expect.cardsInTableColumnInLastCardToBeGT 1 "pop" "30000"
    successMsg "Successfully searched with field names"

  searchScenario "Suppress search results" [] do
    Interact.insertOpenCardInLastDeck
    Interact.selectFileForLastOpenCard "/test-mount/testDb/zips"
    Interact.accessNextCardInLastDeck
    Interact.insertSearchCardInLastDeck
    Interact.provideSearchStringInLastSearchCard "city:portland -state:OR"
    Interact.accessNextCardInLastDeck
    Interact.insertTableCardInLastDeck
    Expect.cardsInTableColumnInLastCardToContain 10 "city" "PORTLAND"
    Expect.cardsInTableColumnInLastCardToNotEq 10 "state" "OR"
    successMsg "Successfully suppressed search results"

{'fraction_non_alphanumeric': 0.08270504912040211, 'fraction_numerical': 0.013251085218185972, 'mean_word_length': 3.8077979132344866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643721', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2702, 'n_words': 596}