Skip to content

Commit 2021acc

Browse files
authored
refactor: begin renaming bookmark to saved searches (#1407)
* refactor: begin renaming bookmark to saved searches Previously, we used the phrases `bookmark` and `saved search` interchangeably. However, after creating the APIs, `saved searches` are the saved query objects and `bookmarks` describe a user's specific status related to a saved search. This commit starts to rename a lot of the references to `bookmark` to `saved search`. We still need to rename the appBookmarkInfo to appSavedSearchInfo (since it's all about reading from the saved searches API), but that can come later. Besides the renaming mentioned above, there is one new thing: `CurrentSavedSearch`. `CurrentSavedSearch` is a new interface that can hold either one of the new interfaces: `UserSavedSearch` and `GlobalSavedSearch` This is done through a discriminated [union](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#discriminated-unions). I used this type of union vs the regular union with `|` because GlobalSavedSearch and UserSavedSearch had different fields but previously I was just allowing them to use both one interface and mark all the fields optional. These two specific interfaces let consumers know that fields are actually expected for each interface. Additionally, the typescript compiler in vscode is smart enough to know what once you have checked for a certain type, it knows it is using that type. * change type->scope
1 parent c84f09a commit 2021acc

17 files changed

+652
-513
lines changed

frontend/src/static/js/components/test/webstatus-overview-content.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ describe('webstatus-overview-content', () => {
3434
const element: WebstatusOverviewContent = container.querySelector(
3535
'webstatus-overview-content',
3636
) as WebstatusOverviewContent;
37-
// Set location to one of the globalBookmarks.
37+
// Set location to one of the globalSavedSearches.
3838
element.location = {search: '?q=test_query_1'};
3939
element.appBookmarkInfo = {
40-
globalBookmarks: [
40+
globalSavedSearches: [
4141
{
4242
name: 'Test Bookmark 1',
4343
query: 'test_query_1',
@@ -49,7 +49,7 @@ describe('webstatus-overview-content', () => {
4949
description: 'test description2',
5050
},
5151
],
52-
currentGlobalBookmark: {
52+
currentGlobalSavedSearch: {
5353
name: 'Test Bookmark 1',
5454
query: 'test_query_1',
5555
description: 'test description1',
@@ -77,16 +77,16 @@ describe('webstatus-overview-content', () => {
7777
const element: WebstatusOverviewContent = container.querySelector(
7878
'webstatus-overview-content',
7979
) as WebstatusOverviewContent;
80-
// Set location to one of the globalBookmarks.
80+
// Set location to one of the globalSavedSearches.
8181
element.location = {search: '?q=test_query_1'};
8282
element.appBookmarkInfo = {
83-
globalBookmarks: [
83+
globalSavedSearches: [
8484
{
8585
name: 'Test Bookmark 1',
8686
query: 'test_query_1',
8787
},
8888
],
89-
currentGlobalBookmark: {
89+
currentGlobalSavedSearch: {
9090
name: 'Test Bookmark 1',
9191
query: 'test_query_1',
9292
},

frontend/src/static/js/components/test/webstatus-overview-filters.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import {WebstatusOverviewFilters} from '../webstatus-overview-filters.js';
3131
import {APIClient} from '../../api/client.js';
3232

3333
import {stub} from 'sinon'; // Make sure you have sinon installed
34-
import {bookmarkHelpers} from '../../contexts/app-bookmark-info-context.js';
34+
import {savedSearchHelpers} from '../../contexts/app-bookmark-info-context.js';
3535

3636
it('should correctly update _activeQuery based on getCurrentQuery return value', async () => {
3737
const apiClient = new APIClient('');
3838
const location = {search: ''};
3939

40-
const getCurrentQueryStub = stub(bookmarkHelpers, 'getCurrentQuery');
40+
const getCurrentQueryStub = stub(savedSearchHelpers, 'getCurrentQuery');
4141

4242
// Test case 1: Empty query
4343
getCurrentQueryStub.returns('');

frontend/src/static/js/components/test/webstatus-overview-table.test.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,29 @@ import {ApiError} from '../../api/errors.js';
2121
import {TaskStatus} from '@lit/task';
2222
import {WebstatusOverviewTable} from '../webstatus-overview-table.js';
2323
import '../webstatus-overview-table.js';
24+
import {
25+
CurrentSavedSearch,
26+
SavedSearchScope,
27+
} from '../../contexts/app-bookmark-info-context.js';
2428

2529
describe('webstatus-overview-table', () => {
26-
const orderedBookmark = {
27-
name: 'Ordered Bookmark 1',
28-
query: 'name:test3 OR id:test1 OR id:test2',
29-
description: 'test description1',
30-
is_ordered: true,
30+
const orderedSavedSearch: CurrentSavedSearch = {
31+
scope: SavedSearchScope.GlobalSavedSearch,
32+
value: {
33+
name: 'Ordered Bookmark 1',
34+
query: 'name:test3 OR id:test1 OR id:test2',
35+
description: 'test description1',
36+
is_ordered: true,
37+
},
3138
};
32-
const defaultOrderBookmark = {
33-
name: 'No order Bookmark 2',
34-
query: 'id:nothing',
35-
description: 'test description1',
36-
is_ordered: false,
39+
const defaultOrderSavedSearch: CurrentSavedSearch = {
40+
scope: SavedSearchScope.GlobalSavedSearch,
41+
value: {
42+
name: 'No order Bookmark 2',
43+
query: 'id:nothing',
44+
description: 'test description1',
45+
is_ordered: false,
46+
},
3747
};
3848
const page = {
3949
data: [
@@ -82,7 +92,7 @@ describe('webstatus-overview-table', () => {
8292
await fixture<WebstatusOverviewTable>(
8393
html`<webstatus-overview-table
8494
.location=${location}
85-
.bookmark=${orderedBookmark}
95+
.savedSearch=${orderedSavedSearch}
8696
.taskTracker=${taskTracker}
8797
></webstatus-overview-table>`,
8898
);
@@ -100,14 +110,17 @@ describe('webstatus-overview-table', () => {
100110
expect(sortedFeatures[3].feature_id).to.equal('test2');
101111
});
102112

103-
it('reorderByQueryTerms() sorts correctly with DEFAULT_BOOKMARKS', async () => {
113+
it('reorderByQueryTerms() sorts correctly with DEFAULT_GLOBAL_SAVED_SEARCHES', async () => {
104114
const cssQuery =
105115
'id:anchor-positioning OR id:container-queries OR id:has OR id:nesting OR id:view-transitions OR id:subgrid OR id:grid OR name:scrollbar OR id:scroll-driven-animations OR id:scope';
106-
const cssBookmark = {
107-
name: 'css',
108-
query: cssQuery,
109-
description: 'test description1',
110-
is_ordered: true,
116+
const cssSavedSearch: CurrentSavedSearch = {
117+
scope: SavedSearchScope.GlobalSavedSearch,
118+
value: {
119+
name: 'css',
120+
query: cssQuery,
121+
description: 'test description1',
122+
is_ordered: true,
123+
},
111124
};
112125
const cssPage = {
113126
data: [
@@ -177,7 +190,7 @@ describe('webstatus-overview-table', () => {
177190
await fixture<WebstatusOverviewTable>(
178191
html`<webstatus-overview-table
179192
.location=${location}
180-
.bookmark=${cssBookmark}
193+
.savedSearch=${cssSavedSearch}
181194
.taskTracker=${cssTaskTracker}
182195
></webstatus-overview-table>`,
183196
);
@@ -208,7 +221,7 @@ describe('webstatus-overview-table', () => {
208221
const component = await fixture<WebstatusOverviewTable>(
209222
html`<webstatus-overview-table
210223
.location=${location}
211-
.bookmark=${defaultOrderBookmark}
224+
.savedSearch=${defaultOrderSavedSearch}
212225
.taskTracker=${taskTracker}
213226
></webstatus-overview-table>`,
214227
);

0 commit comments

Comments
 (0)