Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1079349 - Some integration tests for search.
Browse files Browse the repository at this point in the history
  • Loading branch information
hfiguiere committed Oct 15, 2014
1 parent 4a65d29 commit 086f446
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/music/test/marionette/lib/music.js
Expand Up @@ -20,6 +20,16 @@ Music.Selector = Object.freeze({
songsTab: '#tabs-songs',
albumsTab: '#tabs-albums',

// search fields
searchTiles: '#views-tiles-search',
searchTilesField: '#views-tiles-search-input',
searchList: '#views-list-search',
searchListField: '#views-list-search-input',
// search results
searchArtists: '#views-search-artists',
searchAlbums: '#views-search-albums',
searchTitles: '#views-search-titles',

viewsList: '#views-list-anchor',
viewsSublist: '#views-sublist-anchor',
firstSong: '.list-item',
Expand Down Expand Up @@ -165,6 +175,18 @@ Music.prototype = {
assert.equal(shouldBeShown, result);
},

searchTiles: function(searchTerm) {
this.client.helper.waitForElement(Music.Selector.searchTiles);

var input = this.client.helper.waitForElement(
Music.Selector.searchTilesField);
assert.ok(input);

input.clear();
this.client.waitFor(input.displayed.bind(input));
input.sendKeys(searchTerm);
},

switchToSongsView: function() {
this.songsTab.tap();
},
Expand Down
135 changes: 135 additions & 0 deletions apps/music/test/marionette/search_test.js
@@ -0,0 +1,135 @@
/* global require, marionette, setup, suite, test, __dirname */
'use strict';

var assert = require('assert');
var Music = require('./lib/music.js');
var FakeRingtones = require('./lib/fakeringtones.js');
var FakeControls = require('./lib/fakecontrols.js');
/*var Statusbar = require('./lib/statusbar.js');*/

marionette('Music player search', function() {
var apps = {};
apps[FakeRingtones.DEFAULT_ORIGIN] = __dirname + '/fakeringtones';
apps[FakeControls.DEFAULT_ORIGIN] = __dirname + '/fakecontrols';

var client = marionette.client({
prefs: {
'device.storage.enabled': true,
'device.storage.testing': true,
'device.storage.prompt.testing': true
},

settings: {
'lockscreen.enabled': false,
'ftu.manifestURL': null
},

apps: apps
});

var music;

setup(function() {
music = new Music(client);

client.fileManager.removeAllFiles();
client.fileManager.add([
{
type: 'music',
filePath: 'apps/music/test-data/playlists/01.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/02.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/03.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/a.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/b.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/c.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/w.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/x.ogg'
},
{
type: 'music',
filePath: 'apps/music/test-data/playlists/y.ogg'
}
]);
});

suite('Search tests', function () {

setup(function() {
music.launch();
music.waitForFirstTile();

music.searchTiles('the');
});



function testSearchResults(viewSelector, expectedCount) {
var view = client.helper.waitForElement(viewSelector);
assert.ok(view);

// wait for the results to be displayed.
// XXX this mostly assume we populate before showing the div.
client.waitFor(function() {
return view.displayed();
});

// since we display the count, just get it.
var count = view.findElement('.search-result-count').text();
var results = view.findElement('.search-results');
assert.ok(results);

var resultsList = results.findElements('li.list-item', 'css selector');
assert.ok(resultsList);

// detect inconsistency.
assert.equal(resultsList.length, count);
// check what we expect.
assert.equal(count, expectedCount);

return resultsList;
}

test('Check simple search results in artists.', function() {
// check for the results in "artists"
var resultsList = testSearchResults(Music.Selector.searchArtists, 2);

assert.equal(resultsList[1].findElement('.list-single-title').text(),
'The NSA');
assert.equal(resultsList[1].findElement('.search-highlight').text(),
'The');
});

test('Check simple search results in tracks.', function() {
// check for the results in "artists"
var resultsList = testSearchResults(Music.Selector.searchTitles, 1);

assert.equal(resultsList[0].findElement('.list-main-title').text(),
'The Ecuadorian Embassy');
assert.equal(resultsList[0].findElement('.search-highlight').text(),
'The');
});

});

});

0 comments on commit 086f446

Please sign in to comment.