Get the Number of items found by *AllBy* testing-library queries - react-testing-library

I'm familiar with the assertion of expect(element).toHaveLength(number),
I want to test for a new row addition in a table,
I could just assert some specific item's text to be in the document,
But the situation brought me to think it could be beneficial to be able to get the number of items found by testing-library's findAllby* queries.
I looked in the testing-library docs for an answer but it seems there is no easy way to check how many items were found by findAllby*...
Any ideas and suggestions will be appreciated

You can assert on the length of findAllBy* request results like so :
const rows = await findAllByText('my searched text');
expect(rows).toHaveLength(2);
React-testing-library's *All* queries return arrays : https://testing-library.com/docs/queries/about#types-of-queries

Related

How to clear Django's cached query after prefetch_related

I'm rendering a list of items with their related reviews. I used prefetch_related so it won't issue a new query for each item's reviews.
items = Item.objects.all().prefetch_related('reviews')
Later, I add a review and try to re-calculate the average:
item = items[0]
Review.objects.create(item=item, score=5)
# recalculate average
reviews = item.reviews.all()
...
Oh no! This list of reviews doesn't include the one I just created. How can I clear this cache so the query can be performed fresh? Or should I be creating the review differently?
prefetch_related(None)
Source: https://docs.djangoproject.com/en/2.0/ref/models/querysets/
This is not the correct answer as he want to do it after querying.
The correct way is using :
_remove_prefetched_objects
In this case :
item.reviews._remove_prefetched_objects()

Microsoft Cognitive Services - Bing News Search API V5. So many misunderstanding

I'm working on an app that use the Bing news API. We are currently using the V2 but we want to update it to V5.
We have a problem with the TotalEstimatedMatches attribute. This count is updated radomly when we try to iterate with the offset.
Sometimes the data are not relevant. or when we try to sort the results by date, the dates are not well sorted.
Is there someone who did it ? I really need help.
Thank's !
You should only integrate the very 1st TotalEstimatedMatches return value and use that as a constant maximum-bound while you use the 'count' & 'offset' params to iterate through pages of the same query. I use python primarily so I will here.
If:
TotalEstimatedMatches == 250,000
in the response returned from the first 50 results of your query. Then if you wanted to get a massive list of ALL 250,000 links you would do something like:
# Assuming count==50 & offset==0
max_bound = 250000
results = []
while offset <= max_bound-50:
results.append(your_search_function(your_query, count, offset, **stuff))
offset += count
If you were to keep doing offset calculations using the new TotalEstimatedMatches attribute generated after each query, you'll start skipping pages.
As far as the date-ranges go, I'm less sure. I think I read they're adding better functionality there soon.

How to query from ListColumn[String] in cassandra using phantom

I am new to cassandra (started learning on my own interest few days back) and looking for help for the below problem.
I have a Cassandra table "User" and a ListColumn "interests extends ListColumn[String]".
Now, I want to fetch all users with an interest, say "playing".
like: select from user where interests.contains("playing")!
I scanned through the ListColumn api but not able to find any. Also, searched in google but no such helpful posts.
Any help guys please... Thanks in Advance :)
So there is contains among operators and here is an example how to use it. It looks like that it should work as any other operator, so just go for database.userTable.select.where(_.interests contains "playing").fetch() - of course, depending on your conventions.
This is possible with a secondary index on a collection column, which only works with a Set column, and not with a List.
Bottom line:
object interests extends SetColumn[String](this) with Index[Set[String]]
And then you can execute the following:
select.where(_.interests contains "test").fetch()
You can also use multiple restrictions if you allow filtering.
select.where(_.interests contains "test")
.and(_.interests contains "test2")
.allowFiltering()
.fetch()
The above will only match if both interests are found in a record.

Django-Haystack autocomplete---get distinct results

I would like my autocomplete results with django-haystack to be distinct. However, if multiple objects in my database have a certain value for an attribute on which I am autocompleting, the result appears multiple times.
I am using Haystack with solr as my backend. My query, as in the tutorial, looks like:
SearchQuerySet().autocomplete(content_auto=request.GET.get('q', ''))[:5]
I'm new to Haystack, and the documentation seems limited.
Any help would be greatly appreciated.
Thanks!

Openedge SDO -> smart data browser - I want to filter the query results

I have an SDO supplying data to a read-only browser. The SDO query joins several tables and has calculated fields as well as natural data fields.
The users now want a search facility so the browser will only show rows where the search word appears in ANY of the text fields.
For example they want to see rows where
customer.name matches "*bob*" OR
customer.address1 matches "*bob*" OR
product.description matches "*bob*" OR
calc_field_1 matches "*bob*" OR
calc_field_2 matches "*bob*" OR ...
Ideally the answer will filter the SDO output as it is created - but I am also happy to filter the data on the way to the smartbrowser or in the smartbrowser.
The business problem you're trying to solve in fraught with performance issues if you implement it as written. I'd suggest
adding another character column to the table or db,
putting all the words from the other columns in it,
applying a word-index to the new column,
doing a search on that column, and then linking back to the source tables.
It'll be much faster and easier to use.
I used a very simple solution in the end. Users can enter a string they are looking for. If the string is in a cell in the browser then the cell is highlighted in yellow.
Before this the users had to scroll up and down trying to spot the cells of interest in hundreds of rows. We did not have the time or budget for anything fancier.
The important bit of code in the smartbrowser is like this...
on row-display of br_table in frame f-main
do:
if rowObject.field1 matches "*BOB*" then
rowObject.field1:BGCOLOR in browse br_table = 14.
if rowObject.field2 matches "*BOB*" then
rowObject.field2:BGCOLOR in browse br_table = 14.
if rowObject.field3 matches "*BOB*" then
rowObject.field3:BGCOLOR in browse br_table = 14.
... etc ...
it's not hard-coded to only look for Bob - but you should get the idea.