Live location share - set time limit (#8082)

* add mocking helpers for platform peg

Signed-off-by: Kerry Archibald <kerrya@element.io>

* basic working live duration dropdown

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add duration format utility

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add duration dropdown to live location picker

Signed-off-by: Kerry Archibald <kerrya@element.io>

* adjust style to allow overflow and variable height chin

Signed-off-by: Kerry Archibald <kerrya@element.io>

* tidy comments

Signed-off-by: Kerry Archibald <kerrya@element.io>

* arrow fn change

Signed-off-by: Kerry Archibald <kerrya@element.io>

* lint

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-03-21 12:42:58 +01:00 committed by GitHub
parent 8418b4fd71
commit 14653d1378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 366 additions and 37 deletions

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { formatSeconds, formatRelativeTime } from "../../src/DateUtils";
import { formatSeconds, formatRelativeTime, formatDuration } from "../../src/DateUtils";
describe("formatSeconds", () => {
it("correctly formats time with hours", () => {
@ -70,3 +70,25 @@ describe("formatRelativeTime", () => {
expect(formatRelativeTime(date, true)).toBe("Oct 31, 2020");
});
});
describe('formatDuration()', () => {
type TestCase = [string, string, number];
const MINUTE_MS = 60000;
const HOUR_MS = MINUTE_MS * 60;
it.each<TestCase>([
['rounds up to nearest day when more than 24h - 40 hours', '2d', 40 * HOUR_MS],
['rounds down to nearest day when more than 24h - 26 hours', '1d', 26 * HOUR_MS],
['24 hours', '1d', 24 * HOUR_MS],
['rounds to nearest hour when less than 24h - 23h', '23h', 23 * HOUR_MS],
['rounds to nearest hour when less than 24h - 6h and 10min', '6h', 6 * HOUR_MS + 10 * MINUTE_MS],
['rounds to nearest hours when less than 24h', '2h', 2 * HOUR_MS + 124234],
['rounds to nearest minute when less than 1h - 59 minutes', '59m', 59 * MINUTE_MS],
['rounds to nearest minute when less than 1h - 1 minute', '1m', MINUTE_MS],
['rounds to nearest second when less than 1min - 59 seconds', '59s', 59000],
['rounds to 0 seconds when less than a second - 123ms', '0s', 123],
])('%s formats to %s', (_description, expectedResult, input) => {
expect(formatDuration(input)).toEqual(expectedResult);
});
});