How to use Narrow method in storybook-root

Best JavaScript code snippet using storybook-root

narrow_state.js

Source:narrow_state.js Github

copy

Full Screen

1zrequire("people");2zrequire("Filter", "js/filter");3zrequire("stream_data");4zrequire("narrow_state");5set_global("page_params", {});6function set_filter(operators) {7 operators = operators.map((op) => ({8 operator: op[0],9 operand: op[1],10 }));11 narrow_state.set_current_filter(new Filter(operators));12}13run_test("stream", () => {14 assert.equal(narrow_state.public_operators(), undefined);15 assert(!narrow_state.active());16 const test_stream = {name: "Test", stream_id: 15};17 stream_data.add_sub(test_stream);18 assert(!narrow_state.is_for_stream_id(test_stream.stream_id));19 set_filter([20 ["stream", "Test"],21 ["topic", "Bar"],22 ["search", "yo"],23 ]);24 assert(narrow_state.active());25 assert.equal(narrow_state.stream(), "Test");26 assert.equal(narrow_state.stream_id(), test_stream.stream_id);27 assert.equal(narrow_state.topic(), "Bar");28 assert(narrow_state.is_for_stream_id(test_stream.stream_id));29 const expected_operators = [30 {negated: false, operator: "stream", operand: "Test"},31 {negated: false, operator: "topic", operand: "Bar"},32 {negated: false, operator: "search", operand: "yo"},33 ];34 const public_operators = narrow_state.public_operators();35 assert.deepEqual(public_operators, expected_operators);36 assert.equal(narrow_state.search_string(), "stream:Test topic:Bar yo");37});38run_test("narrowed", () => {39 narrow_state.reset_current_filter(); // not narrowed, basically40 assert(!narrow_state.narrowed_to_pms());41 assert(!narrow_state.narrowed_by_reply());42 assert(!narrow_state.narrowed_by_pm_reply());43 assert(!narrow_state.narrowed_by_topic_reply());44 assert(!narrow_state.narrowed_to_search());45 assert(!narrow_state.narrowed_to_topic());46 assert(!narrow_state.narrowed_by_stream_reply());47 assert.equal(narrow_state.stream_id(), undefined);48 assert(!narrow_state.narrowed_to_starred());49 set_filter([["stream", "Foo"]]);50 assert(!narrow_state.narrowed_to_pms());51 assert(!narrow_state.narrowed_by_reply());52 assert(!narrow_state.narrowed_by_pm_reply());53 assert(!narrow_state.narrowed_by_topic_reply());54 assert(!narrow_state.narrowed_to_search());55 assert(!narrow_state.narrowed_to_topic());56 assert(narrow_state.narrowed_by_stream_reply());57 assert(!narrow_state.narrowed_to_starred());58 set_filter([["pm-with", "steve@zulip.com"]]);59 assert(narrow_state.narrowed_to_pms());60 assert(narrow_state.narrowed_by_reply());61 assert(narrow_state.narrowed_by_pm_reply());62 assert(!narrow_state.narrowed_by_topic_reply());63 assert(!narrow_state.narrowed_to_search());64 assert(!narrow_state.narrowed_to_topic());65 assert(!narrow_state.narrowed_by_stream_reply());66 assert(!narrow_state.narrowed_to_starred());67 set_filter([68 ["stream", "Foo"],69 ["topic", "bar"],70 ]);71 assert(!narrow_state.narrowed_to_pms());72 assert(narrow_state.narrowed_by_reply());73 assert(!narrow_state.narrowed_by_pm_reply());74 assert(narrow_state.narrowed_by_topic_reply());75 assert(!narrow_state.narrowed_to_search());76 assert(narrow_state.narrowed_to_topic());77 assert(!narrow_state.narrowed_by_stream_reply());78 assert(!narrow_state.narrowed_to_starred());79 set_filter([["search", "grail"]]);80 assert(!narrow_state.narrowed_to_pms());81 assert(!narrow_state.narrowed_by_reply());82 assert(!narrow_state.narrowed_by_pm_reply());83 assert(!narrow_state.narrowed_by_topic_reply());84 assert(narrow_state.narrowed_to_search());85 assert(!narrow_state.narrowed_to_topic());86 assert(!narrow_state.narrowed_by_stream_reply());87 assert(!narrow_state.narrowed_to_starred());88 set_filter([["is", "starred"]]);89 assert(!narrow_state.narrowed_to_pms());90 assert(!narrow_state.narrowed_by_reply());91 assert(!narrow_state.narrowed_by_pm_reply());92 assert(!narrow_state.narrowed_by_topic_reply());93 assert(!narrow_state.narrowed_to_search());94 assert(!narrow_state.narrowed_to_topic());95 assert(!narrow_state.narrowed_by_stream_reply());96 assert(narrow_state.narrowed_to_starred());97});98run_test("operators", () => {99 set_filter([100 ["stream", "Foo"],101 ["topic", "Bar"],102 ["search", "Yo"],103 ]);104 let result = narrow_state.operators();105 assert.equal(result.length, 3);106 assert.equal(result[0].operator, "stream");107 assert.equal(result[0].operand, "Foo");108 assert.equal(result[1].operator, "topic");109 assert.equal(result[1].operand, "Bar");110 assert.equal(result[2].operator, "search");111 assert.equal(result[2].operand, "yo");112 narrow_state.reset_current_filter();113 result = narrow_state.operators();114 assert.equal(result.length, 0);115});116run_test("muting_enabled", () => {117 set_filter([["stream", "devel"]]);118 assert(narrow_state.muting_enabled());119 narrow_state.reset_current_filter(); // not narrowed, basically120 assert(narrow_state.muting_enabled());121 set_filter([122 ["stream", "devel"],123 ["topic", "mac"],124 ]);125 assert(!narrow_state.muting_enabled());126 set_filter([["search", "whatever"]]);127 assert(!narrow_state.muting_enabled());128 set_filter([["is", "private"]]);129 assert(!narrow_state.muting_enabled());130 set_filter([["is", "starred"]]);131 assert(!narrow_state.muting_enabled());132});133run_test("set_compose_defaults", () => {134 set_filter([135 ["stream", "Foo"],136 ["topic", "Bar"],137 ]);138 const stream_and_subject = narrow_state.set_compose_defaults();139 assert.equal(stream_and_subject.stream, "Foo");140 assert.equal(stream_and_subject.topic, "Bar");141 set_filter([["pm-with", "foo@bar.com"]]);142 let pm_test = narrow_state.set_compose_defaults();143 assert.equal(pm_test.private_message_recipient, undefined);144 const john = {145 email: "john@doe.com",146 user_id: 57,147 full_name: "John Doe",148 };149 people.add_active_user(john);150 people.add_active_user(john);151 set_filter([["pm-with", "john@doe.com"]]);152 pm_test = narrow_state.set_compose_defaults();153 assert.equal(pm_test.private_message_recipient, "john@doe.com");154 set_filter([155 ["topic", "duplicate"],156 ["topic", "duplicate"],157 ]);158 assert.deepEqual(narrow_state.set_compose_defaults(), {});159 stream_data.add_sub({name: "ROME", stream_id: 99});160 set_filter([["stream", "rome"]]);161 const stream_test = narrow_state.set_compose_defaults();162 assert.equal(stream_test.stream, "ROME");163});164run_test("update_email", () => {165 const steve = {166 email: "steve@foo.com",167 user_id: 43,168 full_name: "Steve",169 };170 people.add_active_user(steve);171 set_filter([172 ["pm-with", "steve@foo.com"],173 ["sender", "steve@foo.com"],174 ["stream", "steve@foo.com"], // try to be tricky175 ]);176 narrow_state.update_email(steve.user_id, "showell@foo.com");177 const filter = narrow_state.filter();178 assert.deepEqual(filter.operands("pm-with"), ["showell@foo.com"]);179 assert.deepEqual(filter.operands("sender"), ["showell@foo.com"]);180 assert.deepEqual(filter.operands("stream"), ["steve@foo.com"]);181});182run_test("topic", () => {183 set_filter([184 ["stream", "Foo"],185 ["topic", "Bar"],186 ]);187 assert.equal(narrow_state.topic(), "Bar");188 set_filter([189 ["stream", "release"],190 ["topic", "@#$$^test"],191 ]);192 assert.equal(narrow_state.topic(), "@#$$^test");193 set_filter([]);194 assert.equal(narrow_state.topic(), undefined);195 set_filter([196 ["sender", "test@foo.com"],197 ["pm-with", "test@foo.com"],198 ]);199 assert.equal(narrow_state.topic(), undefined);200 narrow_state.set_current_filter(undefined);201 assert.equal(narrow_state.topic(), undefined);202});203run_test("stream", () => {204 set_filter([]);205 assert.equal(narrow_state.stream(), undefined);206 assert.equal(narrow_state.stream_id(), undefined);207 set_filter([208 ["stream", "Foo"],209 ["topic", "Bar"],210 ]);211 assert.equal(narrow_state.stream(), "Foo");212 assert.equal(narrow_state.stream_sub(), undefined);213 assert.equal(narrow_state.stream_id(), undefined);214 const sub = {name: "Foo", stream_id: 55};215 stream_data.add_sub(sub);216 assert.equal(narrow_state.stream_id(), 55);217 assert.deepEqual(narrow_state.stream_sub(), sub);218 set_filter([219 ["sender", "someone"],220 ["topic", "random"],221 ]);222 assert.equal(narrow_state.stream(), undefined);223});224run_test("pm_string", () => {225 // This function will return undefined unless we're clearly226 // narrowed to a specific PM (including huddles) with real227 // users.228 narrow_state.set_current_filter(undefined);229 assert.equal(narrow_state.pm_string(), undefined);230 set_filter([231 ["stream", "Foo"],232 ["topic", "Bar"],233 ]);234 assert.equal(narrow_state.pm_string(), undefined);235 set_filter([["pm-with", ""]]);236 assert.equal(narrow_state.pm_string(), undefined);237 set_filter([["pm-with", "bogus@foo.com"]]);238 assert.equal(narrow_state.pm_string(), undefined);239 const alice = {240 email: "alice@foo.com",241 user_id: 444,242 full_name: "Alice",243 };244 const bob = {245 email: "bob@foo.com",246 user_id: 555,247 full_name: "Bob",248 };249 people.add_active_user(alice);250 people.add_active_user(bob);251 set_filter([["pm-with", "bob@foo.com,alice@foo.com"]]);252 assert.equal(narrow_state.pm_string(), "444,555");...

Full Screen

Full Screen

dayPeriod-narrow-en.js

Source:dayPeriod-narrow-en.js Github

copy

Full Screen

1// |reftest| skip-if(release_or_beta) -- Intl.DateTimeFormat-dayPeriod is not released yet2// Copyright 2019 Leo Balter. All rights reserved.3// This code is governed by the BSD license found in the LICENSE file.4/*---5esid: sec-initializedatetimeformat6description: Checks basic handling of dayPeriod, narrow format.7features: [Intl.DateTimeFormat-dayPeriod]8locale: [en-US]9---*/10const d0000 = new Date(2017, 11, 12, 0, 0, 0, 0);11const d0100 = new Date(2017, 11, 12, 1, 0, 0, 0);12const d0200 = new Date(2017, 11, 12, 2, 0, 0, 0);13const d0300 = new Date(2017, 11, 12, 3, 0, 0, 0);14const d0400 = new Date(2017, 11, 12, 4, 0, 0, 0);15const d0500 = new Date(2017, 11, 12, 5, 0, 0, 0);16const d0600 = new Date(2017, 11, 12, 6, 0, 0, 0);17const d0700 = new Date(2017, 11, 12, 7, 0, 0, 0);18const d0800 = new Date(2017, 11, 12, 8, 0, 0, 0);19const d0900 = new Date(2017, 11, 12, 9, 0, 0, 0);20const d1000 = new Date(2017, 11, 12, 10, 0, 0, 0);21const d1100 = new Date(2017, 11, 12, 11, 0, 0, 0);22const d1200 = new Date(2017, 11, 12, 12, 0, 0, 0);23const d1300 = new Date(2017, 11, 12, 13, 0, 0, 0);24const d1400 = new Date(2017, 11, 12, 14, 0, 0, 0);25const d1500 = new Date(2017, 11, 12, 15, 0, 0, 0);26const d1600 = new Date(2017, 11, 12, 16, 0, 0, 0);27const d1700 = new Date(2017, 11, 12, 17, 0, 0, 0);28const d1800 = new Date(2017, 11, 12, 18, 0, 0, 0);29const d1900 = new Date(2017, 11, 12, 19, 0, 0, 0);30const d2000 = new Date(2017, 11, 12, 20, 0, 0, 0);31const d2100 = new Date(2017, 11, 12, 21, 0, 0, 0);32const d2200 = new Date(2017, 11, 12, 22, 0, 0, 0);33const d2300 = new Date(2017, 11, 12, 23, 0, 0, 0);34const narrow = new Intl.DateTimeFormat('en', {35 dayPeriod: 'narrow'36});37assert.sameValue(narrow.format(d0000), 'at night', '00:00, narrow format');38assert.sameValue(narrow.format(d0100), 'at night', '01:00, narrow format');39assert.sameValue(narrow.format(d0200), 'at night', '02:00, narrow format');40assert.sameValue(narrow.format(d0300), 'at night', '03:00, narrow format');41assert.sameValue(narrow.format(d0400), 'at night', '04:00, narrow format');42assert.sameValue(narrow.format(d0500), 'at night', '05:00, narrow format');43assert.sameValue(narrow.format(d0600), 'in the morning', '06:00, narrow format');44assert.sameValue(narrow.format(d0700), 'in the morning', '07:00, narrow format');45assert.sameValue(narrow.format(d0800), 'in the morning', '08:00, narrow format');46assert.sameValue(narrow.format(d0900), 'in the morning', '09:00, narrow format');47assert.sameValue(narrow.format(d1000), 'in the morning', '10:00, narrow format');48assert.sameValue(narrow.format(d1100), 'in the morning', '11:00, narrow format');49assert.sameValue(narrow.format(d1200), 'n', '12:00, narrow format');50assert.sameValue(narrow.format(d1300), 'in the afternoon', '13:00, narrow format');51assert.sameValue(narrow.format(d1400), 'in the afternoon', '14:00, narrow format');52assert.sameValue(narrow.format(d1500), 'in the afternoon', '15:00, narrow format');53assert.sameValue(narrow.format(d1600), 'in the afternoon', '16:00, narrow format');54assert.sameValue(narrow.format(d1700), 'in the afternoon', '17:00, narrow format');55assert.sameValue(narrow.format(d1800), 'in the evening', '18:00, narrow format');56assert.sameValue(narrow.format(d1900), 'in the evening', '19:00, narrow format');57assert.sameValue(narrow.format(d2000), 'in the evening', '20:00, narrow format');58assert.sameValue(narrow.format(d2100), 'at night', '21:00, narrow format');59assert.sameValue(narrow.format(d2200), 'at night', '22:00, narrow format');60assert.sameValue(narrow.format(d2300), 'at night', '23:00, narrow format');61const narrowNumeric = new Intl.DateTimeFormat('en', {62 dayPeriod: 'narrow',63 hour: 'numeric'64});65assert.sameValue(narrowNumeric.format(d0000), '12 at night', '00:00, narrow-numeric');66assert.sameValue(narrowNumeric.format(d0100), '1 at night', '01:00, narrow-numeric');67assert.sameValue(narrowNumeric.format(d0200), '2 at night', '02:00, narrow-numeric');68assert.sameValue(narrowNumeric.format(d0300), '3 at night', '03:00, narrow-numeric');69assert.sameValue(narrowNumeric.format(d0400), '4 at night', '04:00, narrow-numeric');70assert.sameValue(narrowNumeric.format(d0500), '5 at night', '05:00, narrow-numeric');71assert.sameValue(narrowNumeric.format(d0600), '6 in the morning', '06:00, narrow-numeric');72assert.sameValue(narrowNumeric.format(d0700), '7 in the morning', '07:00, narrow-numeric');73assert.sameValue(narrowNumeric.format(d0800), '8 in the morning', '08:00, narrow-numeric');74assert.sameValue(narrowNumeric.format(d0900), '9 in the morning', '09:00, narrow-numeric');75assert.sameValue(narrowNumeric.format(d1000), '10 in the morning', '10:00, narrow-numeric');76assert.sameValue(narrowNumeric.format(d1100), '11 in the morning', '11:00, narrow-numeric');77assert.sameValue(narrowNumeric.format(d1200), '12 n', '12:00, narrow-numeric');78assert.sameValue(narrowNumeric.format(d1300), '1 in the afternoon', '13:00, narrow-numeric');79assert.sameValue(narrowNumeric.format(d1400), '2 in the afternoon', '14:00, narrow-numeric');80assert.sameValue(narrowNumeric.format(d1500), '3 in the afternoon', '15:00, narrow-numeric');81assert.sameValue(narrowNumeric.format(d1600), '4 in the afternoon', '16:00, narrow-numeric');82assert.sameValue(narrowNumeric.format(d1700), '5 in the afternoon', '17:00, narrow-numeric');83assert.sameValue(narrowNumeric.format(d1800), '6 in the evening', '18:00, narrow-numeric');84assert.sameValue(narrowNumeric.format(d1900), '7 in the evening', '19:00, narrow-numeric');85assert.sameValue(narrowNumeric.format(d2000), '8 in the evening', '20:00, narrow-numeric');86assert.sameValue(narrowNumeric.format(d2100), '9 at night', '21:00, narrow-numeric');87assert.sameValue(narrowNumeric.format(d2200), '10 at night', '22:00, narrow-numeric');88assert.sameValue(narrowNumeric.format(d2300), '11 at night', '23:00, narrow-numeric');...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful