Commit e4f1d9ed authored by Netrom's avatar Netrom
Browse files

Add check all notes in page test, Json parsing, Adjust tests

parent 0dd91ee6
Pipeline #1732 canceled with stages
in 1 minute and 19 seconds
Showing with 4346 additions and 13 deletions
+4346 -13
using System;
using System.Collections.Generic;
using Memri.Tests.JsonModels;
namespace Memri.Tests.Constants
{
class NodeTypes
{
public string NodeTypeName { get; set; }
public Type NodeType { get; set; }
}
class NodeRules
{
// property names
public static string Type = "_type";
//property values
public static string NoteType = "Note";
public static string PersonType = "Person";
public static string EmailType = "EmailMessage";
public static List<NodeTypes> NodeTypes = new List<NodeTypes>
{
new NodeTypes
{
NodeTypeName = NoteType,
NodeType = typeof(NoteNode)
},
new NodeTypes
{
NodeTypeName = PersonType,
NodeType = typeof(PersonNode)
},
new NodeTypes
{
NodeTypeName = EmailType,
NodeType = typeof(EmailMessageNode)
}
};
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Memri.Tests.Constants;
using Newtonsoft.Json.Linq;
namespace Memri.Tests.Database
{
class JsonDbContext
{
private static JArray _db;
static JArray Db
{
get
{
if (_db == null)
{
var json = File.ReadAllText("./TestData/demo_database.json");
_db = JArray.Parse(json);
}
return _db;
}
}
public static List<T> GetNodes<T>()
where T : class
{
var nodeTypeName = NodeRules.NodeTypes.First(x => x.NodeType == typeof(T)).NodeTypeName;
return Db.Where(x => x[NodeRules.Type].Value<string>() == nodeTypeName).Select(x => x.ToObject<T>())
.ToList();
}
}
}
Feature: CheckAllNotes
In order to check that all the notes are loaded
As a regular human
I want to be able to see all my notes
Scenario: Check that the user can see all notes
Given The user is on the all notes screen
Then All his notes are displayed
\ No newline at end of file
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class EmailMessageEdgeNode
{
[DataMember(Name = "targetType")]
public string TargetType { get; set; }
[DataMember(Name = "uid")]
public long Uid { get; set; }
[DataMember(Name = "_type")]
public string Type { get; set; }
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class EmailMessageNode
{
[DataMember(Name = "uid")]
public long Uid { get; set; }
[DataMember(Name = "externalId")]
public string ExternalId { get; set; }
[DataMember(Name = "subject")]
public string Subject { get; set; }
[DataMember(Name = "content")]
public string Content { get; set; }
[DataMember(Name = "dateSent")]
public long DateSent { get; set; }
[DataMember(Name = "allEdges")]
public List<EmailMessageEdgeNode> AllEdges { get; set; }
}
}
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class NoteEdgeNode
{
[DataMember(Name = "_type")]
public string Type { get; set; }
[DataMember(Name = "targetType")]
public string TargetType { get; set; }
[DataMember(Name = "uid")]
public long Uid { get; set; }
}
}
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class NoteNode
{
[DataMember(Name = "title")]
public string Title { get; set; }
[DataMember(Name = "content")]
public string Content { get; set; }
[DataMember(Name = "starred")]
public bool Starred { get; set; }
[DataMember(Name = "dateModified")]
public long DateModified { get; set; }
[DataMember(Name = "allEdges")]
public List<NoteEdgeNode> AllEdges { get; set; }
[DataMember(Name = "_partial")]
public bool Partial { get; set; }
[DataMember(Name = "version")]
public int Version { get; set; }
}
}
\ No newline at end of file
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class PersonEdgeNode
{
[DataMember(Name = "_type")]
public string Type { get; set; }
[DataMember(Name = "targetType")]
public string TargetType { get; set; }
[DataMember(Name = "uid")]
public long Uid { get; set; }
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Memri.Tests.JsonModels
{
[DataContract]
public class PersonNode
{
[DataMember(Name = "uid")]
public long Uid { get; set; }
[DataMember(Name = "firstName")]
public string FirstName { get; set; }
[DataMember(Name = "lastName")]
public string LastName { get; set; }
[DataMember(Name = "birthDate")]
public long BirthDate { get; set; }
[DataMember(Name = "height")]
public int Height { get; set; }
[DataMember(Name = "allEdges")]
public List<PersonEdgeNode> AllEdges { get; set; }
[DataMember(Name = "version")]
public int Version { get; set; }
}
}
......@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Unity" Version="5.11.7" />
<PackageReference Include="xunit" Version="2.4.1" />
......@@ -31,6 +32,9 @@
<None Update="Features\CheckAddNote.feature">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Features\CheckAllNotes.feature">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Features\CheckDeleteNote.feature">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......@@ -58,6 +62,9 @@
<None Update="Features\CheckStarFilter.feature">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\demo_database.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
This diff is collapsed.
using System.Collections.ObjectModel;
using System.Threading;
using Memri.Tests.DI;
using Memri.Tests.iOSUiFramework;
using OpenQA.Selenium;
using System.Threading;
using Unity;
using Xunit;
using Xunit.Gherkin.Quick;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckAddNote.feature"), Collection("Sequential")]
public class CheckAddNote : Feature
......
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Memri.Tests.Database;
using Memri.Tests.DI;
using Memri.Tests.iOSUiFramework;
using Memri.Tests.JsonModels;
using OpenQA.Selenium;
using Unity;
using Xunit;
using Xunit.Gherkin.Quick;
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckAllNotes.feature"), Collection("Sequential")]
public class CheckAllNotes : Feature
{
protected iOSBrowser iOSBrowser { get; }
private readonly IUnityContainer _container = IoC.Container.CreateChildContainer();
public CheckAllNotes()
{
iOSBrowser = Resolve<iOSBrowser>("DefaultBrowser");
Thread.Sleep(1000);
}
protected T Resolve<T>(string name = null)
{
return name == null ? _container.Resolve<T>() : _container.Resolve<T>(name);
}
[Given("The user is on the all notes screen")]
public void GivenTheUserIsOnTheAllNotesScreen()
{
var allNotes = iOSBrowser.FindElement(By.XPath("//XCUIElementTypeButton[@name='All Notes']"));
Assert.Equal("All Notes", allNotes.Text);
}
[Then("All his notes are displayed")]
public void ThenAllHisNotesAreDisplayed()
{
var notesInPage = iOSBrowser.FindElements(By.XPath("//XCUIElementTypeApplication[@name='memri']/XCUIElementTypeWindow[1]" +
"//XCUIElementTypeOther" +
"/XCUIElementTypeTable/XCUIElementTypeCell"));
var notesInJson = JsonDbContext.GetNodes<NoteNode>();
Assert.Equal(notesInJson.Count, notesInPage.Count);
var titlesInApp = new List<string>();
foreach (var note in notesInPage)
{
var noteTitle = note.FindElement(By.XPath("//XCUIElementTypeStaticText"));
titlesInApp.Add(noteTitle.Text);
}
var titlesInJson = new List<string>();
foreach (var note in notesInJson)
{
titlesInJson.Add(note.Title);
}
Assert.True(titlesInJson.OrderBy(x => x).SequenceEqual(titlesInApp.OrderBy(x => x)));
}
}
}
......@@ -8,7 +8,7 @@ using Unity;
using Xunit;
using Xunit.Gherkin.Quick;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckDeleteNote.feature"), Collection("Sequential")]
public class CheckDeleteNote : Feature
......
......@@ -6,7 +6,7 @@ using Unity;
using Xunit;
using Xunit.Gherkin.Quick;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckEditNote.feature"), Collection("Sequential")]
public class CheckEditNote : Feature
......
......@@ -6,7 +6,7 @@ using Memri.Tests.iOSUiFramework;
using Unity;
using Memri.Tests.DI;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckNavigationToPerson.feature"), Collection("Sequential")]
public class CheckNavigationToPerson : Feature
......
......@@ -6,7 +6,7 @@ using Memri.Tests.iOSUiFramework;
using Unity;
using Memri.Tests.DI;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckNewNoteTitle.feature"), Collection("Sequential")]
public class CheckNewNoteTitle : Feature
......
......@@ -8,7 +8,7 @@ using Memri.Tests.DI;
using System.Collections.Generic;
using System.Linq;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckNoteSortingByContent.feature"), Collection("Sequential")]
public class CheckNoteSortingByContent : Feature
......
......@@ -8,7 +8,7 @@ using Memri.Tests.DI;
using System.Collections.Generic;
using System.Linq;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckNoteSortingByTitle.feature"), Collection("Sequential")]
public class CheckNoteSortingByTitle : Feature
......
......@@ -7,8 +7,10 @@ using Unity;
using Memri.Tests.DI;
using System.Collections.Generic;
using System.Linq;
using Memri.Tests.Database;
using Memri.Tests.JsonModels;
namespace Memri.Tests
namespace Memri.Tests.Tests
{
[FeatureFile("./Features/CheckSearchNote.feature"), Collection("Sequential")]
public class CheckSearchNote : Feature
......@@ -42,9 +44,12 @@ namespace Memri.Tests
{
iOSBrowser.FindElement(By.XPath("//XCUIElementTypeButton[@name='magnifyingglass']")).Click();
iOSBrowser.FindElement(By.XPath("//XCUIElementTypeApplication[@name='memri']/XCUIElementTypeWindow[1]" +
"//XCUIElementTypeOther" +
"/XCUIElementTypeTextField")).SendKeys(noteTitle);
foreach (char c in noteTitle)
{
iOSBrowser.FindElement(By.XPath("//XCUIElementTypeApplication[@name='memri']/XCUIElementTypeWindow[1]" +
"//XCUIElementTypeOther" +
"/XCUIElementTypeTextField")).SendKeys(c.ToString());
}
}
[Then("Only the searched note should be displayed in the page")]
......@@ -53,7 +58,18 @@ namespace Memri.Tests
var notesInPage = iOSBrowser.FindElements(By.XPath("//XCUIElementTypeApplication[@name='memri']/XCUIElementTypeWindow[1]" +
"//XCUIElementTypeOther" +
"/XCUIElementTypeTable/XCUIElementTypeCell"));
Assert.Equal(1, notesInPage.Count);
var notesInJson = JsonDbContext.GetNodes<NoteNode>();
var titlesInJson = new List<string>();
foreach (var note in notesInJson)
{
titlesInJson.Add(note.Title);
}
var searchedTitle = titlesInJson.Where(x => x.Contains(noteTitle));
Assert.Equal(searchedTitle.Count(), notesInPage.Count);
var titles = new List<string>();
foreach (var note in notesInPage)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment