Skip to content

Commit

Permalink
Merge pull request #4 from UCL/devel
Browse files Browse the repository at this point in the history
Remove searched for prefix from json queries. Add test for failed html
  • Loading branch information
david-guzman authored Aug 8, 2022
2 parents c129dc5 + fa85ef5 commit 75621e9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
6 changes: 5 additions & 1 deletion TakeoutFilter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
9C03B7B6286B1D8700788D53 /* CatalogueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C03B7B5286B1D8700788D53 /* CatalogueTests.swift */; };
9C03B7B8286B2F3B00788D53 /* CatalogueSample.csv in Resources */ = {isa = PBXBuildFile; fileRef = 9C03B7B7286B2F3B00788D53 /* CatalogueSample.csv */; };
9C13485C28A182F6001266DB /* MyActivityError.html in Resources */ = {isa = PBXBuildFile; fileRef = 9C13485B28A182F5001266DB /* MyActivityError.html */; };
9C2FA6D728758AB30095FDFD /* Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C2FA6D628758AB30095FDFD /* Query.swift */; };
9C2FA6D92875AFEC0095FDFD /* MyActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C2FA6D82875AFEC0095FDFD /* MyActivity.swift */; };
9C2FA6DB2875CB670095FDFD /* FilterOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C2FA6DA2875CB670095FDFD /* FilterOutput.swift */; };
Expand Down Expand Up @@ -64,14 +65,15 @@
/* Begin PBXFileReference section */
9C03B7B5286B1D8700788D53 /* CatalogueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatalogueTests.swift; sourceTree = "<group>"; };
9C03B7B7286B2F3B00788D53 /* CatalogueSample.csv */ = {isa = PBXFileReference; lastKnownFileType = text; path = CatalogueSample.csv; sourceTree = "<group>"; };
9C13485B28A182F5001266DB /* MyActivityError.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = MyActivityError.html; sourceTree = "<group>"; };
9C2FA6D628758AB30095FDFD /* Query.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Query.swift; path = Main/Query.swift; sourceTree = "<group>"; };
9C2FA6D82875AFEC0095FDFD /* MyActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MyActivity.swift; path = Main/MyActivity.swift; sourceTree = "<group>"; };
9C2FA6DA2875CB670095FDFD /* FilterOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FilterOutput.swift; path = Main/FilterOutput.swift; sourceTree = "<group>"; };
9C4C95F72869D2A000AE5371 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainView.swift; path = Main/MainView.swift; sourceTree = "<group>"; };
9C4C95F92869D38100AE5371 /* MainLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MainLogic.swift; path = Main/MainLogic.swift; sourceTree = "<group>"; };
9C4C95FB286A051500AE5371 /* Catalogue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Catalogue.swift; path = Main/Catalogue.swift; sourceTree = "<group>"; };
9C4EBC742885844000302F50 /* PorterStemmerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PorterStemmerTests.swift; sourceTree = "<group>"; };
9C5566262862114100CB77BB /* TakeoutFilter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = TakeoutFilter.app; path = ../Release/TakeoutFilter.app; sourceTree = BUILT_PRODUCTS_DIR; };
9C5566262862114100CB77BB /* TakeoutFilter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TakeoutFilter.app; sourceTree = BUILT_PRODUCTS_DIR; };
9C5566292862114100CB77BB /* TakeoutFilterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TakeoutFilterApp.swift; sourceTree = "<group>"; };
9C55662D2862114600CB77BB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
9C5566302862114600CB77BB /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -201,6 +203,7 @@
9CDFBD37288708EF005CD08A /* DataSourceTests.swift */,
9CAD801328883E4D00C2A814 /* MyActivity.html */,
9CAD801528886BC400C2A814 /* QueryDateFormatterTests.swift */,
9C13485B28A182F5001266DB /* MyActivityError.html */,
);
path = TakeoutFilterTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -344,6 +347,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9C13485C28A182F6001266DB /* MyActivityError.html in Resources */,
9C03B7B8286B2F3B00788D53 /* CatalogueSample.csv in Resources */,
9CDFBD302886CF25005CD08A /* PorterStemmerInput.txt in Resources */,
9CDFBD342886F0CF005CD08A /* MyActivity.json in Resources */,
Expand Down
1 change: 1 addition & 0 deletions TakeoutFilter/Main/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extension Filter {
for n in names {
queryTitle = myActivityItem.title.replacingOccurrences(of: n, with: "", options: .caseInsensitive, range: nil)
}
queryTitle = queryTitle.replacingOccurrences(of: "Searched for ", with: "")
let qDate = parseQueryDate(myActivityItem.time)
return Query(query: queryTitle, date: qDate)
}
Expand Down
15 changes: 14 additions & 1 deletion TakeoutFilterTests/FilterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FilterTests: XCTestCase {
XCTAssertEqual(result.totalNumberOfQueries, 4)
let expectedDate = ISODateFormatter().obtainFormatter().date(from: "2021-02-15")
XCTAssertEqual(result.firstQueryDate, expectedDate)
XCTAssertEqual(result.filteredQueries.count, 3)
XCTAssertEqual(result.filteredQueries.count, 4)
}

func testHtmlFilter() {
Expand All @@ -35,6 +35,19 @@ class FilterTests: XCTestCase {
XCTAssertEqual(result.totalNumberOfQueries, 3)
let expectedDate = UsDateFormatter().obtainFormatter().date(from: "Feb 15, 2021, 4:45:11 PM BST")
XCTAssertEqual(result.firstQueryDate, expectedDate)
XCTAssertEqual(result.filteredQueries.count, 3)
}

func testHtmlErrorFilter() {
let bundle = Bundle(for: CatalogueTests.self)
let htmlUrl = URL(fileURLWithPath: "MyActivityError.html", relativeTo: bundle.resourceURL)
let htmlContent = try! String(contentsOf: htmlUrl)
let instance: Filter = HtmlFilter()
let result = instance.filterQueries(content: htmlContent, presentationDate: Date(), namesToFilter: "Forename Surname")
XCTAssertEqual(result.outcome, .success)
XCTAssertEqual(result.totalNumberOfQueries, 3)
let expectedDate = UsDateFormatter().obtainFormatter().date(from: "Feb 15, 2021, 4:45:11 PM BST")
XCTAssertEqual(result.firstQueryDate, expectedDate)
XCTAssertEqual(result.filteredQueries.count, 2)
}

Expand Down
33 changes: 33 additions & 0 deletions TakeoutFilterTests/MyActivityError.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My Activity History</title>
</head>
<body>
<div class="mdl-grid">

<div class="outer-cell mdl-cell mdl-cell--12-col mdl-shadow--2dp">
<div class="mdl-grid">
<div class="header-cell mdl-cell mdl-cell--12-col">
<p class="mdl-typography--title">Search<br></p>
</div>

<div class="content-cell mdl-cell mdl-cell--6-col mdl-typography--body-1">
Visited <a href="https://www.google.com/url?q=http://www.danword.com/crossword/Like_a_badly_behaved_child&amp;usg=AOvVaw1LTnVAG7vGRYA8WkFNuVI1">Like a badly-behaved child - crossword puzzle clues &amp; answers ...</a><br>4 May 2021, 18:01:34 GMT
</div>

<div class="content-cell mdl-cell mdl-cell--6-col mdl-typography--body-1 mdl-typography--text-right"></div>

<div class="content-cell mdl-cell mdl-cell--12-col mdl-typography--caption"><b>Products:</b><br>&emsp;Search<br>
<b>Locations:</b><br>
 At <a href="https://www.google.com/maps/@?api=1&amp;map_action=map&amp;center=51.525450,-0.129252&amp;zoom=9">this general area</a> - Based on your
past activity<br>
<b>Why is this here?</b><br>
 This activity was saved to your Google Account because the following settings were on:&nbsp;Web &amp; App Activity.&nbsp;You can control these
settings &nbsp;<a href="https://myaccount.google.com/activitycontrols">here</a>.
</div>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 75621e9

Please sign in to comment.