A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
9.2 KiB

3 years ago
import 'package:nextcloud/nextcloud.dart';
import 'package:test/test.dart';
import 'helper.dart';
3 years ago
const wikipediaFeedURL = 'https://en.wikipedia.org/w/api.php?action=featuredfeed&feed=featured&feedformat=atom';
const nasaFeedURL = 'https://www.nasa.gov/rss/dyn/breaking_news.rss';
Future main() async {
await run(await getDockerImage());
}
3 years ago
Future run(final DockerImage image) async {
3 years ago
group('news', () {
late DockerContainer container;
3 years ago
late TestNextcloudClient client;
setUp(() async {
container = await getDockerContainer(image);
client = await getTestClient(container);
});
tearDown(() => container.destroy());
3 years ago
Future<NextcloudNewsListFeeds> addWikipediaFeed([final int? folderID]) => client.news.addFeed(
url: wikipediaFeedURL,
folderId: folderID,
);
Future<NextcloudNewsListFeeds> addNasaFeed() => client.news.addFeed(
url: nasaFeedURL,
);
3 years ago
test('Is supported', () async {
final response = await client.news.isSupported();
expect(response, isTrue);
});
3 years ago
test('Add feed', () async {
var response = await client.news.listFeeds();
3 years ago
expect(response.starredCount, 0);
expect(response.newestItemId, null);
expect(response.feeds, hasLength(0));
response = await addWikipediaFeed();
expect(response.starredCount, null);
expect(response.newestItemId, isNotNull);
expect(response.feeds, hasLength(1));
expect(response.feeds[0].url, wikipediaFeedURL);
3 years ago
response = await client.news.listFeeds();
3 years ago
expect(response.starredCount, 0);
expect(response.newestItemId, isNotNull);
expect(response.feeds, hasLength(1));
expect(response.feeds[0].url, wikipediaFeedURL);
3 years ago
});
test('Rename feed', () async {
var response = await addWikipediaFeed();
expect(response.feeds[0].title, 'Wikipedia featured articles feed');
await client.news.renameFeed(
feedId: 1,
feedTitle: 'test1',
);
response = await client.news.listFeeds();
expect(response.feeds[0].title, 'test1');
});
test('Move feed to folder', () async {
await client.news.createFolder(name: 'test1');
await addWikipediaFeed();
await client.news.moveFeed(
feedId: 1,
folderId: 1,
);
final response = await client.news.listFolders();
expect(response.folders, hasLength(1));
expect(response.folders[0].id, 1);
expect(response.folders[0].name, 'test1');
expect(response.folders[0].opened, true);
expect(response.folders[0].feeds, hasLength(0));
});
3 years ago
test('Mark feed as read', () async {
final feedsResponse = await addWikipediaFeed();
var articlesResponse = await client.news.listArticles(type: NewsListType.unread.code);
expect(articlesResponse.items.length, greaterThan(0));
3 years ago
await client.news.markFeedAsRead(
feedId: feedsResponse.feeds[0].id,
newestItemId: feedsResponse.newestItemId!,
3 years ago
);
articlesResponse = await client.news.listArticles(type: NewsListType.unread.code);
3 years ago
expect(articlesResponse.items, hasLength(0));
});
test('List articles', () async {
var response = await client.news.listArticles();
3 years ago
expect(response.items, hasLength(0));
await addWikipediaFeed();
response = await client.news.listArticles();
expect(response.items.length, greaterThan(0));
expect(response.items[0].body, isNotNull);
expect(response.items[0].feedId, 1);
expect(response.items[0].unread, true);
expect(response.items[0].starred, false);
3 years ago
});
test('List updated articles', () async {
// Testing this is not easy, because we can't depend on an external source to update the feed
// Therefore we just add a second feed and check that the articles returned after a certain modified timestamp
// are exactly those of the new feed.
// Now that I think of it, maybe we could host our own feed and update that way, but this works for now.
await addWikipediaFeed();
var response = await client.news.listArticles();
final wikipediaArticles = response.items.length;
3 years ago
expect(wikipediaArticles, greaterThan(0));
await addNasaFeed();
response = await client.news.listArticles();
final nasaArticles = response.items.length - wikipediaArticles;
3 years ago
expect(nasaArticles, greaterThan(0));
response = await client.news.listUpdatedArticles(
lastModified: response.items[response.items.length - 1 - nasaArticles].lastModified,
);
3 years ago
expect(response.items, hasLength(nasaArticles));
});
test('Mark article as read', () async {
await addWikipediaFeed();
var response = await client.news.listArticles(type: NewsListType.unread.code);
final unreadArticles = response.items.length;
3 years ago
expect(unreadArticles, greaterThan(0));
await client.news.markArticleAsRead(
itemId: response.items[0].id,
);
response = await client.news.listArticles(type: NewsListType.unread.code);
3 years ago
expect(response.items, hasLength(unreadArticles - 1));
});
test('Mark article as unread', () async {
await addWikipediaFeed();
var response = await client.news.listArticles(type: NewsListType.unread.code);
final readArticle = response.items[0];
await client.news.markArticleAsRead(itemId: readArticle.id);
response = await client.news.listArticles(type: NewsListType.unread.code);
final unreadArticles = response.items.length;
3 years ago
expect(unreadArticles, greaterThan(0));
await client.news.markArticleAsUnread(itemId: readArticle.id);
response = await client.news.listArticles(type: NewsListType.unread.code);
3 years ago
expect(response.items, hasLength(unreadArticles + 1));
});
test('Star article', () async {
await addWikipediaFeed();
var response = await client.news.listArticles(type: NewsListType.starred.code);
final starredArticles = response.items.length;
3 years ago
expect(starredArticles, 0);
response = await client.news.listArticles();
await client.news.starArticle(
itemId: response.items[0].id,
);
response = await client.news.listArticles(type: NewsListType.starred.code);
3 years ago
expect(response.items, hasLength(1));
});
test('Unstar article', () async {
await addWikipediaFeed();
var response = await client.news.listArticles();
final item = response.items[0];
await client.news.starArticle(
itemId: item.id,
);
response = await client.news.listArticles(type: NewsListType.starred.code);
3 years ago
expect(response.items, hasLength(1));
await client.news.unstarArticle(
itemId: item.id,
);
response = await client.news.listArticles(type: NewsListType.starred.code);
3 years ago
expect(response.items, hasLength(0));
});
test('Create folder', () async {
var response = await client.news.listFolders();
3 years ago
expect(response.folders, hasLength(0));
response = await client.news.createFolder(name: 'test1');
3 years ago
expect(response.folders, hasLength(1));
expect(response.folders[0].id, 1);
expect(response.folders[0].name, 'test1');
expect(response.folders[0].opened, true);
expect(response.folders[0].feeds, hasLength(0));
response = await client.news.listFolders();
3 years ago
expect(response.folders, hasLength(1));
expect(response.folders[0].id, 1);
expect(response.folders[0].name, 'test1');
expect(response.folders[0].opened, true);
expect(response.folders[0].feeds, hasLength(0));
3 years ago
});
test('List folders', () async {
var response = await client.news.listFolders();
3 years ago
expect(response.folders, hasLength(0));
await client.news.createFolder(name: 'test1');
await client.news.createFolder(name: 'test2');
3 years ago
response = response = await client.news.listFolders();
3 years ago
expect(response.folders, hasLength(2));
expect(response.folders[0].id, 1);
expect(response.folders[0].name, 'test1');
expect(response.folders[0].opened, true);
expect(response.folders[0].feeds, hasLength(0));
expect(response.folders[1].id, 2);
expect(response.folders[1].name, 'test2');
expect(response.folders[1].opened, true);
expect(response.folders[1].feeds, hasLength(0));
3 years ago
});
test('Add feed to folder', () async {
await client.news.createFolder(name: 'test1');
3 years ago
final response = await addWikipediaFeed(1);
expect(response.starredCount, null);
expect(response.newestItemId, isNotNull);
expect(response.feeds, hasLength(1));
expect(response.feeds[0].folderId, 1);
expect(response.feeds[0].url, wikipediaFeedURL);
3 years ago
});
test('Mark folder as read', () async {
final foldersResponse = await client.news.createFolder(name: 'test1');
3 years ago
final feedsResponse = await addWikipediaFeed(1);
var articlesResponse = await client.news.listArticles(type: NewsListType.unread.code);
expect(articlesResponse.items.length, greaterThan(0));
3 years ago
await client.news.markFolderAsRead(
folderId: foldersResponse.folders[0].id,
newestItemId: feedsResponse.newestItemId!,
3 years ago
);
articlesResponse = await client.news.listArticles(type: NewsListType.unread.code);
3 years ago
expect(articlesResponse.items, hasLength(0));
});
});
}